Script functions for summons

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Script functions for summons

Post by Blue Dragon »

Someone could make a small introduction of how to do what I say below? If someone is enable to make the script also has no problems, hehehehe.

Processes:

1- The npc be invoked (such as elemental of fire, Earth and other), they arise/appear with their animations.(in all of them is the same animation, the number 12)


2- If you say/talk "follow me" near him, the npc will follow the owner of it, in the case who invoked it (same for all numbers below).

3- If you say/talk "attack", appear a target, and on the character or player that you select, it will start an attack.

4- If you say/talk "protect me", he will attack the first target that start an attack against you.

5- If you say/talk "stopped", he will stop following you or attack the target that you ordered attack.

I'm interested more in numbers 2, 3, 4, 5, the number 1 would not be so important, but would be cool, hehehe.

Is this, if possible, and someone animate to do this... :o
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Xuri or Dragon Slayer could help me? I do not understand how to do these things I mentioned above. =/

I can not do:
As the NPC obey only the owner / landlord;
How to make him attack the target I select, all kill (kill all)
As he guard his owner / owner to say "watch over all" (all guard)

todos sigame = all follow
todos mate = all kill
todos pare = all stop
todos vigiem = all guard

If anyone has the patience for this...
function onSpeech( strSaid, myPlayer, myNPC )
{
    if( strSaid == "todos sigame" )
    {
    myNPC.frozen = 0;
    myNPC.TurnToward( myPlayer );
    myNPC.Follow( myPlayer );
    myNPC.TextMessage( "*Seguindo*" );
    myPlayer.SysMessage( ""+myNPC.name+" ira segui-lo e defende-lo de qualquer inimigo que lhe ataque!" );
    }
    if( strSaid == "todos vigiem" )
    {
???????????????????????????
?????????????????????????????????
    ?????????????????????????????????
    }
    if( strSaid == "todos mate" )
    {
    myPlayer.CustomTarget( 0, "Selecione o alvo que deseja que sua criatura ataque" );
    ?????????????????????????????????
    ?????????????????????????????????
    }
    if( strSaid == "todos pare" )
    {
    myNPC.TurnToward( myPlayer );
    myNPC.frozen = 1;
    myNPC.TextMessage( "*Parado*" );
    myPlayer.SysMessage( ""+myNPC.name+" aguadara ate que voce diga novos comandos a ele!" );
    }
}
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

hmm i don't see why not working looks right.
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

I managed to improve the script as I think it should be.

But anyone can do for me the part of the "kill all", to the NPC to attack the target I selected? only remains for him to be so nearly complete, but that part I do not have a clue how.

Put phrases in English as well, I do not know if they have the meaning it should be, but stay here the script on english.

So that's it for me to say that the script is complete, missing only do what I said above and a few more things.


1-As stated above, perform the npc attack the selected target on the part of the "kill all".

2 - When you say "all stop" in addition to the npc stop moving, I think he would have to cancel all his actions, as the target it is attacking, following, among others. That I can not do as well :(

3 - Make the body of the NPC disappears at your death. I made an attempt keeping from your death sound and initiation of start the animation when he falls.

4 - Make the NPCs appear with your animations entry number 12.

NOTE: For the script works well, "npcai" the NPC must be = 0.
var DispelSom = 0x201; // Sound disappears when the NPC.
var FumaçaEfeitoID = 0x3728; // Effect of smoke when the NPC disappears


function onSpeech( strSaid, myPlayer, myNPC )
{
    if( strSaid == "all follow" )
    {
        if( myNPC.owner == myPlayer )
        {
        myNPC.frozen = 0;
        myNPC.TurnToward( myPlayer );
        myNPC.Follow( myPlayer );
        myNPC.TextMessage( "*Following*" );
        myPlayer.SysMessage( ""+myNPC.name+" are following you!" );
        }
    }
    if( strSaid == "all protect" )
    {
        if( myNPC.owner == myPlayer )
        {
        myNPC.frozen = 0;
        myNPC.aitype = 32;
        myNPC.TurnToward( myPlayer );
        myNPC.TextMessage( "*"+myNPC.name+" is protecting you!*" );
        }
    }
    if( strSaid == "all kill" )
    {
        if( myNPC.owner == myPlayer )
        {
        myNPC.frozen = 0;
        myPlayer.CustomTarget( 0, "Select the target you want your creature attack." );
        SetTarget( myPlayer, myNPC );
        AttackTarget( myNPC );
        }
    }
    if( strSaid == "all stop" )
    {
        if( myNPC.owner == myPlayer )
        {
        myNPC.frozen = 1;
        myNPC.atWar = 0;
        myNPC.aitype = 0;
        myNPC.TurnToward( myPlayer );
        myNPC.TextMessage( "*Immobile*" );
        myPlayer.SysMessage( ""+myNPC.name+" stay waiting you say new order  to him!" );
        }
    }
    if( strSaid == "all free" )
    {
        if( myNPC.owner == myPlayer )
        {
        myNPC.TurnToward( myPlayer );
        myNPC.frozen = 1;
        myNPC.TextMessage( "Until next master" );
        myNPC.StaticEffect( FumaçaEfeitoID, 0, 10 );
        myNPC.SoundEffect( DispelSom, true );
        myNPC.StartTimer( 1500, 2, true );
        }
    }
}


function onDeathBlow( pKilled, pKiller )
{
    pKilled.StaticEffect( FumaçaEfeitoID, 0, 10 );
    pKilled.SoundEffect( DispelSom, true );
    pKilled.StartTimer( 50, 1, true );
}


function onTimer( pKilled, timerID )
{
    var socket = pKilled.socket;
    if( timerID == 1 )
    {
    pKilled.Delete();
    }
}


function onTimer( myNPC, timerID )
{
    var socket = myNPC.socket;
    if( timerID == 2 )
    {
    myNPC.Delete();
    }
}
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

I really need to update the JS docs. The AttackTarget() and SetTarget() functions were removed a long time ago :/

You want to do something like this:
function onSpeech( strSaid, myPlayer, myNPC )
{
    ...
    if( strSaid == "all kill" )
    {
        myNPC.frozen = 0;
       
        //Temporarily save the NPC in player's socket tempObj variable
        myPlayer.socket.tempObj = myNPC;
        myPlayer.CustomTarget( 0, "Select the target you want your creature to attack." );
    }
    ...
}

//The number behind onCallback is linked to the CustomTarget number (in this case, 0)
function onCallback0( socket, myTarget )
{
    myPlayer = socket.currentChar;
   
    //Load NPC from socket's tempObj variable
    myNPC = socket.tempObj;
   
    if( !socket.GetWord( 1 ) && myTarget.isChar && myTarget.vulnerable )
    {
        myNPC.target = myTarget;

        //Make the NPC attack the target
        myNPC.atWar = true;
        myNPC.attackFirst = ( myTarget.target != myNPC );
        myNPC.attacker = myTarget;
       
        //To trigger combat for the target as well.
        //true = set criminal flag on attacker when attacking innocents
        myTarget.Damage( 0, myNPC, true );
       
        //If the hireling/pet turned criminal from attacking something, the owner should too!
        if( myNPC.criminal && myNPC.owner )
            myNPC.owner.criminal = true;
    }
    else
        socket.SysMessage( "You must target a character." );
}
Edit: Updated myNPC.attackFirst() part to only be true if the target didn't already have myNPC as a target.
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Alternative way to make an NPC attack someone:
myPlayer.tempObj = myNPC;
myPlayer.PopUpTarget( 23, "Select target to attack:" );

This will trigger the hardcoded "pet attack" code, which will handle both target-validation and criminal-flags. This gives you less control of what happens though, as you can no longer do custom target validation or make the targets say stuff etc.

In fact, any hardcoded targeting-function can be triggered through the PopUpTarget() JS method, if you know the target-function ID to reference (23 = pet attack target code).
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

To make NPCs stop attacking... that's harder, because even if you clear their target (myNPC.target = null), attacker (myNPC.attacker = null), and take them out of combat (myNPC.atWar = false) - they will still fight back if someone else attacks them - so if they're fighting an NPC who's hitting them in return, they will defend themselves and re-enter combat when they get hit.

I'm adding a new AI to the next UOX3 version to get around this problem:
  • NPCAI 7 - AI_PASSIVE
An NPC with this AI will never initiate an attack, and won't defend in combat. So if you change the NPC's AI to 7, clear the targets and take them out of combat, they'll stay out of combat until you say otherwise (even if they get attacked).
-= Ho Eyo He Hum =-
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Ohh, very good Xuri, excellent! It worked perfectly here!

Thanks for your help and congratulations for the work that has been developing.

Now one doubt. The elemental obey only the character from a distance of 6 tiles. In the script has as to increase the distance that it npc obeys you for 10 tiles or more?
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

The distance for onSpeech JS event (as well as hardcoded range for NPCs detecting speech) is based on a value for when characters are "in range" of one another. Currently this value is defined as 7 in the code, and it's also used for non-speech related things, so changing it directly would affect other stuff as well.

I could possibly add another range-check value to use specifically for speech-stuff, though. What would be a good range for that? 7 was possibly chosen originally so it wouldn't trigger for all NPCs on screen when you talked, for instance, only those within a reasonable range :P
-= Ho Eyo He Hum =-
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Questioned about it because I think 7 tiles are too small for the elementals. I think 10 or a little more it would be good.

I also asked because I created a script for the npcs open the gump for purchase if you say "buy /comprar " or sale if you say "sell / vender", only there for them, 7 tiles is a lot, there should be 1 or at most 2 tiles .
Post Reply