Someone help me with this script?

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

Someone help me with this script?

Post by Blue Dragon »

Good, I used the script that the Dragon Slayer has made to the ettin and gave a small modified to become a script for dragons spitting fire.

All variables work less "var combatAnim", being that put this for a test only and I do not know how to run it. It would be to make the npc perform a particular animation of your own chart. How would there? In the case would be chart 0xc and animarion number 12.

Already at the "onCombatStart", some times I put if would wait a few seconds in certain places, this would be possible? believe that with a helping hand in these parties cited the rest I could edit alone, but if someone if enable to pick up the idea and improve or make another script also wouldn't have problems, hehehe. Any AI for npcs would be better than just giving common scams.
var fireID = 0x3888;// Gráfico de quando o fogo atinge o personagem
var firemovingEffect = 0x382A;// Gráfico do efeito de movimento de quando o dragão cospe o fogo
var fireSound = 0x15e;// Som que o fogo faz ao ser disparado no personagem
var fire2Sound = 0x306;// Som que o fogo faz ao atingir o personagem
var baforadaSound= 0x16b; // Som que o dragão faz na baforada
var drakeMsg = "*Toma um folego profundo*";
var drake1Msg = "*Bastante irritado*";
var hitMsg = "Voce foi atingido de raspao por uma rajada de fogo!";
var hit2Msg = "Voce foi atingido por uma rajada de fogo!";
var hit3Msg = "Voce foi atingido em cheio por uma poderosa rajada de fogo!";
var dismountMsg = "O impacto foi tao forte que voce foi derrubado de sua montaria!";
var combatAnim = 12; ??????????????????????????  How does animation variable to fight?


function onCombatStart( pAttacker, pDefender )
{
    if( pDefender.isonhorse )
    {
          pAttacker.SoundEffect( baforadaSound, true );
          pAttacker.EmoteMessage( drakeMsg );
          // is how to wait 5 seconds here?
          pAttacker.combatAnim( 12 ); // ???????????????????????  here would be the animation of the graphic 0xc 12 (12) dragon. I do not know how to do it.
          DoMovingEffect( pAttacker, pDefender, firemovingEffect, 0x10, 0x00, false );
          pDefender.SoundEffect( fireSound, true );
          // is how to wait 2 seconds here?
          pDefender.StaticEffect( fireID, 0, 15 );
          pDefender.SoundEffect( fire2Sound, true );
          pDefender.EmoteMessage( hit2Msg );
          pDefender.health = (pDefender.health -20);
          pDefender.stamina = (pDefender.stamina -1);
      return true;
        }
        else
          pAttacker.SoundEffect( baforadaSound, true );
          pAttacker.EmoteMessage( drakeMsg );
          pAttacker.combatAnim( 12 ); // ???????????????????????
          DoMovingEffect( pAttacker, pDefender, firemovingEffect, 0x10, 0x00, false );
          pDefender.SoundEffect( fireSound, true );
          pDefender.StaticEffect( fireID, 0, 15 );
          pDefender.SoundEffect( fire2Sound, true );
          pDefender.EmoteMessage( hit2Msg );
          pDefender.health = (pDefender.health -20);
          pDefender.stamina = (pDefender.stamina -1);
      return true;
}

function onDefense( pAttacker, pDefender )
{
   var iNum = RandomNumber( 0, 1000 );
   if( iNum > 500 )
   {
      if( pDefender.health < pDefender.maxhp )
      {
        var dice;
        dice = RollDice(1,20,0);

        if (dice < 3)
        {
       if( pAttacker.isonhorse )
       {
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drake1Msg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit3Msg );
             pAttacker.health = (pAttacker.health -30);
             pAttacker.stamina = (pAttacker.stamina -5);
             pAttacker.Dismount();
             pAttacker.SysMessage( dismountMsg );
             return false;
           }
           else
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drake1Msg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit3Msg );
             pAttacker.health = (pAttacker.health -30);
             pAttacker.stamina = (pAttacker.stamina -5);
             return false;
        }
        if (dice < 6)
        {
       if( pAttacker.isonhorse )
       {
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drakeMsg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit2Msg );
             pAttacker.health = (pAttacker.health -20);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
           }
           else
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drakeMsg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit2Msg );
             pAttacker.health = (pAttacker.health -20);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
        }
        if (dice < 16)
        {
       if( pAttacker.isonhorse )
       {
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drakeMsg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hitMsg );
             pAttacker.health = (pAttacker.health -5);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
           }
           else
             pAttacker.SoundEffect( baforadaSound, true );
             pAttacker.EmoteMessage( drakeMsg );
             pAttacker.combatAnim( 12 ); // ???????????????????????
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hitMsg );
             pAttacker.health = (pAttacker.health -5);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
        }
        return false;
      }
   }
}

function onCombatEnd( pDefender, pAttacker )
{
    if( pAttacker.isonhorse )
    {
          pAttacker.SoundEffect( baforadaSound, true );
          pAttacker.EmoteMessage( drakeMsg );
          pAttacker.combatAnim( 12 ); // ???????????????????????
          DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
          pAttacker.SoundEffect( fireSound, true );
          pAttacker.StaticEffect( fireID, 0, 15 );
          pAttacker.SoundEffect( fire2Sound, true );
          pAttacker.EmoteMessage( hit2Msg );
          pAttacker.health = (pAttacker.health -20);
          pAttacker.stamina = (pAttacker.stamina -1);
          pAttacker.Dismount();
          pAttacker.SysMessage( dismountMsg );
          return true;
        }
        else
          pAttacker.SoundEffect( baforadaSound, true );
          pAttacker.EmoteMessage( drakeMsg );
          pAttacker.combatAnim( 12 ); // ???????????????????????
          DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
          pAttacker.SoundEffect( fireSound, true );
          pAttacker.StaticEffect( fireID, 0, 15 );
          pAttacker.SoundEffect( fire2Sound, true );
          pAttacker.EmoteMessage( hit2Msg );
          pAttacker.health = (pAttacker.health -20);
          pAttacker.stamina = (pAttacker.stamina -1);
      return true;
}
Last edited by Blue Dragon on Sun Jan 22, 2012 4:46 am, edited 1 time in total.
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 »

far as i know all fight animations might be hard coded into the client not uox3. I could be totaly wrong
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Forget everything I said in my first post :shock:.

I managed to make the Dragon make the animation of spit fire before really spit it :o.

Somehow, I also managed to put breaks during some steps to ensure that everything happens at the right time...

Apparently things are as I wish they were, but still lack to do the Dragon if turn towards the direction of the player, before make the animation of spit fire. In the above lines of "pAttacker.EmoteMessage( pAttacker.name + drakeMsg ); " would be the space reserved for the dragon to turn to the character before spitting fire. Therefore, just missing this...

However one small problem is occurring. When the dragon will breath a fire, the game starts to brake, but then returns to normal. Someone who understands the thing, I would like to test the script and find a way to make it work correctly, as mentioned, though without such problems? Or by following the same line of reasoning to create a similar work that way?

var fireID = 0x3888;// Gráfico de quando o fogo atinge o personagem - pode ser também o gráfico 0x3898
var firemovingEffect = 0x382A;// Gráfico do efeito de movimento de quando o dragão cospe o fogo
var fireSound = 0x15e;// Som que o fogo faz ao ser disparado no personagem
var fire2Sound = 0x306;// Som que o fogo faz ao atingir o personagem
var baforadaSound = 0x16b; // Som que o dragão faz na baforada
var drakeMsg = " toma um folego profundo";
var drake1Msg = " esta bastante irritado";
var hitMsg = "Voce foi atingido de raspao por uma rajada de fogo!";
var hit2Msg = "Voce foi atingido por uma rajada de fogo!";
var hit3Msg = "Voce foi atingido em cheio por uma poderosa rajada de fogo!";
var dismountMsg = "O impacto foi tao forte que voce foi derrubado de sua montaria!";

function sleep(ms)
{
    var dt = new Date();
    dt.setTime(dt.getTime() + ms);
    while (new Date().getTime() < dt.getTime());
}

function onCombatStart( pAttacker, pDefender )
{
    if( pDefender.isonhorse )
    {
          pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
          sleep(2000);
          pAttacker.DoAction( 12 );
          pAttacker.SoundEffect( baforadaSound, true );
          sleep(3000);
          DoMovingEffect( pAttacker, pDefender, firemovingEffect, 0x10, 0x00, false );
          pDefender.SoundEffect( fireSound, true );
          sleep(1500);
          pDefender.StaticEffect( fireID, 0, 15 );
          pDefender.SoundEffect( fire2Sound, true );
          pDefender.EmoteMessage( hit2Msg );
          pDefender.health = (pDefender.health -20);
          pDefender.stamina = (pDefender.stamina -1);
      return true;
     }
        else
          pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
          sleep(2000);
          pAttacker.DoAction( 12 );
          pAttacker.SoundEffect( baforadaSound, true );
          sleep(3000);
          DoMovingEffect( pAttacker, pDefender, firemovingEffect, 0x10, 0x00, false );
          pDefender.SoundEffect( fireSound, true );
          sleep(1500);
          pDefender.StaticEffect( fireID, 0, 15 );
          pDefender.SoundEffect( fire2Sound, true );
          pDefender.EmoteMessage( hit2Msg );
          pDefender.health = (pDefender.health -20);
          pDefender.stamina = (pDefender.stamina -1);
      return true;
}

function onDefense( pAttacker, pDefender )
{
   var iNum = RandomNumber( 0, 1000 );
   if( iNum > 500 )
   {
      if( pDefender.health < pDefender.maxhp )
      {
        var dice;
        dice = RollDice(1,20,0);

           if (dice < 3 )
              {
                if( pAttacker.isonhorse )
         {
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit3Msg );
             pAttacker.health = (pAttacker.health -30);
             pAttacker.stamina = (pAttacker.stamina -5);
             pAttacker.Dismount();
             pAttacker.SysMessage( dismountMsg );
             return false;
           }
           else
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit3Msg );
             pAttacker.health = (pAttacker.health -30);
             pAttacker.stamina = (pAttacker.stamina -5);
             return false;
        }
        if (dice < 6)
        {
       if( pAttacker.isonhorse )
       {
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit2Msg );
             pAttacker.health = (pAttacker.health -20);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
           }
           else
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hit2Msg );
             pAttacker.health = (pAttacker.health -20);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
        }
        if (dice < 16)
        {
       if( pAttacker.isonhorse )
       {
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hitMsg );
             pAttacker.health = (pAttacker.health -5);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
           }
           else
             pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
             sleep(2000);
             pAttacker.DoAction( 12 );
             pAttacker.SoundEffect( baforadaSound, true );
             sleep(3000);
             DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
             pAttacker.SoundEffect( fireSound, true );
             sleep(1500);
             pAttacker.StaticEffect( fireID, 0, 15 );
             pAttacker.SoundEffect( fire2Sound, true );
             pAttacker.EmoteMessage( hitMsg );
             pAttacker.health = (pAttacker.health -5);
             pAttacker.stamina = (pAttacker.stamina -1);
             return false;
        }
        return false;
      }
   }
}

function onCombatEnd( pDefender, pAttacker )
{
    if( pAttacker.isonhorse )
    {
          pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
          sleep(2000);
          pAttacker.DoAction( 12 );
          pAttacker.SoundEffect( baforadaSound, true );
          sleep(3000);
          DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
          pAttacker.SoundEffect( fireSound, true );
          sleep(1500);
          pAttacker.StaticEffect( fireID, 0, 15 );
          pAttacker.SoundEffect( fire2Sound, true );
          pAttacker.EmoteMessage( hit2Msg );
          pAttacker.health = (pAttacker.health -20);
          pAttacker.stamina = (pAttacker.stamina -1);
          pAttacker.Dismount();
          pAttacker.SysMessage( dismountMsg );
          return true;
        }
        else
          pAttacker.EmoteMessage( pAttacker.name + drakeMsg );
          sleep(2000);
          pAttacker.DoAction( 12 );
          pAttacker.SoundEffect( baforadaSound, true );
          sleep(3000);
          DoMovingEffect( pDefender, pAttacker, firemovingEffect, 0x10, 0x00, false );
          pAttacker.SoundEffect( fireSound, true );
          sleep(1500);
          pAttacker.StaticEffect( fireID, 0, 15 );
          pAttacker.SoundEffect( fire2Sound, true );
          pAttacker.EmoteMessage( hit2Msg );
          pAttacker.health = (pAttacker.health -20);
          pAttacker.stamina = (pAttacker.stamina -1);
      return true;
}
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 »

Try this one to make the dragon turn towards the target:
pAttacker.TurnToward( pDefender );

As for your problem with the sleep/delay-thing, you should use timers instead of creating custom sleep-functions, as the latter will sleep all of UOX3 and not just your individual script :)

Example of timer usage:
// myObject.StartTimer( numMiliSec, timerID, callback );
//  callback-parameter can be:
//      true (calls back to existing script)
//      false (calls back into object's script)
//      an int (scriptID to call back to)
//      This is an optional parameter, and defaults to false if not specified.

// ...
myObject.StartTimer( 2000, 1, true );
// ...

function onTimer( myObject, timerID )
{
    if( timerID == 1 )
    {
        myObject.DoAction( 12 );
    }
}
-= 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 »

Thank you Xuri! I'll see what I can do here. :D
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 »

nice job :) you might just come a js scripter sooner then later :)
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 started to want to understand seeing your script as an example. They are simple and comprehensible. But now I have a basis for understanding things, but I still understand little, almost nothing yet, I just started to have some notions, hehehe. :D
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 »

best way to learn is work on that script and advance it by looking at other scripts seeing how the look and work.

any questions how how things are done just ask here on boards you will find a awnser I'm sure or some one will help
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Hello all,

Trying to edit Ai's good for dragons and Ettins, I have some doubts.

The function "onCombatStart (pAttacker, pDefender)," makes the NPC make the script when he sees the player and the first attack starts.

The function "onDefense (pAttacker, pDefender)," makes the NPC attack the player when you hit one damage on it, am I right? If not so, is was really going on here.

Well, the function "onCombatEnd (pDefender, pAttacker)" would work that way?

Have a function that the NPC attack the player during combat without a "special condition" (only to start fighting or when hit), the NPC attack every time, then you control how often the script with data or numbers Random?

As an example ... The way I'm doing is okay, but the NPC does not attack the target if it gets reodeando him running, or runs away with the NPC after him.

the NPC does not attack when the player is surrounding him or running away the NPC with in its range of vision. How the NPC launch a "special attacks", would be nice that these fazessem also on these occasions, if so have a way...
Post Reply