Jump to content

Recommended Posts

Posted (edited)

First of all let you know im a little new to understand AI so have pacience if im missunderstanding something

 

Im trying to create a npc for rol event who ask you one ripple and let player 15 seconds to repply before disappear. someone have clues about how create a timer ? i've tried to understand timer functions based on current npcs maded by ncsoft

 

Here i will list timer functions i've found and comment how i think they works

 

First function:

 

  myself::Say( "timer 4 . counting 60 seconds . addtimerex");
  myself::AddTimerEx( 4, 60000 );                                               // i believe : (1 * 60 * 1000 = 1 min)  . // is 4 the index ?

Second:

  myself::Say( "i will count 15 . settimerperiodbytrick ");      // I believe once specified time happends it return to run the next instruction ?
  SetTimerPeriodByTick(15);

 

Third:

  myself::Say( "settimeperiod");            // setup a timer that when end enables  "   EventHandler TIMER_FIRED() " ?
  SetTimerPeriod(18);   

 

 

So can someone tell me accurated info about this ? . exist any documentation in english ? . Thanks in advance here is the entire code:

 

 

 

class 1 wiseman : citizen
{
parameter:
  string  wiseman_challenge_1 = "wiseman_challenge_1.htm";
  string  wiseman_challenge_2 = "wiseman_challenge_2.htm";
  string  wiseman_challenge_3 = "wiseman_challenge_3.htm";
  string  wiseman_challenge_4 = "wiseman_challenge_4.htm";
  string  wiseman_challenge_5 = "wiseman_challenge_5.htm";

handler:


EventHandler CREATED()
  {
    myself::Shout( "All we have to decide is what to do with the time that is given us." );
  }


  EventHandler TALKED( talker )
  {
        

  myself::Say( "timer 4 . counting 60 seconds . addtimerex");
  myself::AddTimerEx( 4, 60000 );  // (1 * 60 * 1000 = 1 min) 


  myself::Say( "i will count 15 . settimerperiodbytrick ");
  SetTimerPeriodByTick(15);

  myself::Say( "settimeperiod");
  SetTimerPeriod(18);    

    
    

        if( gg::Rand( 5 ) == 0 && myself.i_ai0 == 1 )
        {
    myself::ShowPage( talker, wiseman_challenge_1 );
    myself.i_ai0 = 0;
        }

        else if( gg::Rand( 5 ) == 1 && myself.i_ai0 == 1 )
        {
    myself::ShowPage( talker, wiseman_challenge_2 );
    myself.i_ai0 = 0;
        }

        else if( gg::Rand( 5 ) == 2 && myself.i_ai0 == 1 )
        {
    myself::ShowPage( talker, wiseman_challenge_3 );
    myself.i_ai0 = 0;
        }

        else if( gg::Rand( 5 ) == 3 && myself.i_ai0 == 1 )
        {
    myself::ShowPage( talker, wiseman_challenge_4 );
    myself.i_ai0 = 0;
        }

        else if( gg::Rand( 5 ) == 4 && myself.i_ai0 == 1 )
        {
    myself::ShowPage( talker, wiseman_challenge_5 );
    myself.i_ai0 = 0;
        }

        else if (myself.i_ai0 == 1 )
        {
     myself::ShowPage( talker, wiseman_challenge_5 );
    myself.i_ai0 = 0;
        }

    
  }



  EventHandler MENU_SELECTED( talker, ask, reply, fhtml0 )
  {

 target = talker;

  if ( ask == -1 )
    {


     if ( reply == 1 )
       {
       myself::Say( "Correct answer");
       if( gg::Rand( 10 ) < 2 )
       {                
        myself::GiveItem1( target, 7863, 1 );              
       }
    myself::Despawn();
       }

     if ( reply == 2 )
       {
    myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 3 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 4 )
       {
           myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 5 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }
     

    }

  if (ask == -2)
    {


     if ( reply == 1 )
       {
        myself::Say( "Correct answer");
        if( gg::Rand( 10 ) < 2 )
        {                
        myself::GiveItem1( target, 7863, 1 );              
        }
    myself::Despawn();
       }

     if ( reply == 2 )
       {
    myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 3 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 4 )
       {
           myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 5 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }
     

    }

  if (ask == -3)
    {


     if ( reply == 1 )
       {
        myself::Say( "Correct answer");
        if( gg::Rand( 10 ) < 2 )
        {                
        myself::GiveItem1( target, 7863, 1 );              
        }
    myself::Despawn();
       }

     if ( reply == 2 )
       {
    myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 3 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 4 )
       {
           myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 5 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }
     
    }

  if (ask == -4)
    {


     if ( reply == 1 )
       {
        myself::Say( "Correct answer");
        if( gg::Rand( 10 ) < 2 )
        {                
        myself::GiveItem1( target, 7863, 1 );              
        }
    myself::Despawn();
       }

     if ( reply == 2 )
       {
    myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 3 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 4 )
       {
           myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 5 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }
     
    }

  if (ask == -5)
    {


     if ( reply == 1 )
       {
        myself::Say( "Correct answer");
        if( gg::Rand( 10 ) < 2 )
        {                
        myself::GiveItem1( target, 7863, 1 );              
        }
    myself::Despawn();
       }

     if ( reply == 2 )
       {
    myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 3 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 4 )
       {
           myself::Say( "nope");
    myself::Despawn();
       }

     if ( reply == 5 )
       {
        myself::Say( "nope");
    myself::Despawn();
       }
     
    }

 


  }


  EventHandler SEE_CREATURE( creature )
  {
myself::Say( "Who are there ?");

    if( myself.p_state != 3 && myself::GetLifeTime() > 7 )
    {
      if( myself::DistFromMe( creature ) > 200 )
      {
        myself::InstantTeleport( myself.sm, myself::FloatToInt( creature.x ),
                                 myself::FloatToInt( creature.y ),
                                 myself::FloatToInt( creature.z ) );
        if( myself::Skill_GetConsumeMP( TeleportEffect ) < myself.sm.mp &&
            myself::Skill_GetConsumeHP( TeleportEffect ) < myself.sm.hp &&
            myself::Skill_InReuseDelay( TeleportEffect ) == 0 )
        {
          myself::AddUseSkillDesire( myself.sm, TeleportEffect, 1, 1,
                                     1000000 );
        }
      }

    }
  }



  EventHandler NO_DESIRE()
  {
    myself::AddMoveAroundDesire( 5, 5 );
  }

    EventHandler TIMER_FIRED()        //tiempo agotado
    {    

    if( timer_id == 4 )
    {
    myself::Say( "bye");
        myself::Despawn();
    }

    myself::Say( "bye");
    myself::Despawn();

    }



  EventHandler MY_DYING( target , last_attacker )
  {

         
  }


}
 

 

 

Edited by madocter
Posted

This should works....

 

myself::AddTimerEx( 1, 30 * 1000 ); //30 seconds ?

 

EventHandler TIMER_FIRED_EX( timer_id )

{

if( timer_id == 1 )

{

myself::Despawn();

}

super;

}

Posted (edited)

Here is the working code

 

NASC:

 

 

class 1 wiseman : citizen

{

parameter:

  string  wiseman_challenge_1 = "wiseman_challenge_1.htm";

  string  wiseman_challenge_2 = "wiseman_challenge_2.htm";

  string  wiseman_challenge_3 = "wiseman_challenge_3.htm";

  string  wiseman_challenge_4 = "wiseman_challenge_4.htm";

  string  wiseman_challenge_5 = "wiseman_challenge_5.htm";

handler:

 

 

EventHandler CREATED()

  {

    myself::Shout( "All we have to decide is what to do with the time that is given us." );

  }

 

 

  EventHandler TALKED( talker )

  {

 

    if( myself.i_ai0 == 1 )

    {

    myself::Say( "bye");

        myself::Despawn();

    }

        

 

        myself::AddTimerEx( 1, 30 * 1000 );

 

 

        if( gg::Rand( 5 ) == 0 && myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_1 );

    myself.i_ai0 = 1;

        }

 

        else if( gg::Rand( 5 ) == 1 && myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_2 );

    myself.i_ai0 = 1;

        }

 

        else if( gg::Rand( 5 ) == 2 && myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_3 );

    myself.i_ai0 = 1;

        }

 

        else if( gg::Rand( 5 ) == 3 && myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_4 );

    myself.i_ai0 = 1;

        }

 

        else if( gg::Rand( 5 ) == 4 && myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_5 );

    myself.i_ai0 = 1;

        }

 

        else if (myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_5 );

    myself.i_ai0 = 1;

        }

 

    

  }

 

 

 

  EventHandler MENU_SELECTED( talker, ask, reply, fhtml0 )

  {

 

 target = talker;

 

  if ( ask == -1 )

    {

 

 

     if ( reply == 1 )

       {

       myself::Say( "Correct answer");

       if( gg::Rand( 10 ) < 2 )

       {                

        myself::GiveItem1( target, 7863, 1 );              

       }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -2)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

        if( gg::Rand( 10 ) < 2 )

        {                

        myself::GiveItem1( target, 7863, 1 );              

        }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -3)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

        if( gg::Rand( 10 ) < 2 )

        {                

        myself::GiveItem1( target, 7863, 1 );              

        }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

     

    }

 

  if (ask == -4)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

        if( gg::Rand( 10 ) < 2 )

        {                

        myself::GiveItem1( target, 7863, 1 );              

        }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

     

    }

 

  if (ask == -5)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

        if( gg::Rand( 10 ) < 2 )

        {                

        myself::GiveItem1( target, 7863, 1 );              

        }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

    myself::Despawn();

       }

     

    }

 

 

 

 

  }

 

 

  EventHandler SEE_CREATURE( creature )

  {

myself::Say( "Who are there ?");

 

    if( myself.p_state != 3 && myself::GetLifeTime() > 7 )

    {

      if( myself::DistFromMe( creature ) > 200 )

      {

        myself::InstantTeleport( myself.sm, myself::FloatToInt( creature.x ),

                                 myself::FloatToInt( creature.y ),

                                 myself::FloatToInt( creature.z ) );

        if( myself::Skill_GetConsumeMP( TeleportEffect ) < myself.sm.mp &&

            myself::Skill_GetConsumeHP( TeleportEffect ) < myself.sm.hp &&

            myself::Skill_InReuseDelay( TeleportEffect ) == 0 )

        {

          myself::AddUseSkillDesire( myself.sm, TeleportEffect, 1, 1,

                                     1000000 );

        }

      }

 

    }

  }

 

 

 

  EventHandler NO_DESIRE()

  {

    myself::AddMoveAroundDesire( 5, 5 );

  }

 

EventHandler TIMER_FIRED_EX( timer_id )

    {

 

    if( timer_id == 1 )

    {

    myself::Say( "bye");

        myself::Despawn();

    }

 

 

    }

 

 

 

  EventHandler MY_DYING( target , last_attacker )

  {

 

         

  }

 

 

}

 

 

 

 

 

Compiled:

 

class 1 wiseman : citizen

parameter_define_begin

string wiseman_challenge_1 "wiseman_challenge_1.htm"

string wiseman_challenge_2 "wiseman_challenge_2.htm"

string wiseman_challenge_3 "wiseman_challenge_3.htm"

string wiseman_challenge_4 "wiseman_challenge_4.htm"

string wiseman_challenge_5 "wiseman_challenge_5.htm"

parameter_define_end

handler 13 9 // CREATED

variable_begin

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // myself

push_const 704

add

fetch_i

S0. "All we have to decide is what to do with the time that is given us."

push_string S0

func_call 184614978 // func[shout]

shift_sp -1

shift_sp -1

handler_end

 

handler 3 328 // TALKED

variable_begin

"talker"

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 1

equal

branch_false L2

L1

push_event // myself

push_const 704

add

fetch_i

S1. "bye"

push_string S1

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L2

push_event // myself

push_const 704

add

fetch_i

push_const 1

push_const 30

push_const 1000

mul

func_call 184680487 // func[AddTimerEx]

shift_sp -2

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 5

func_call 218169344 // func[Rand]

shift_sp -1

push_const 0

equal

push_reg_sp

fetch_i

branch_false L5

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

and

L5

branch_false L4

L3

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_1

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

jump L6

L4

push_event // gg

push_const 632

add

fetch_i

push_const 5

func_call 218169344 // func[Rand]

shift_sp -1

push_const 1

equal

push_reg_sp

fetch_i

branch_false L9

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

and

L9

branch_false L8

L7

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_2

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

jump L10

L8

push_event // gg

push_const 632

add

fetch_i

push_const 5

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

equal

push_reg_sp

fetch_i

branch_false L13

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

and

L13

branch_false L12

L11

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_3

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

jump L14

L12

push_event // gg

push_const 632

add

fetch_i

push_const 5

func_call 218169344 // func[Rand]

shift_sp -1

push_const 3

equal

push_reg_sp

fetch_i

branch_false L17

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

and

L17

branch_false L16

L15

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_4

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

jump L18

L16

push_event // gg

push_const 632

add

fetch_i

push_const 5

func_call 218169344 // func[Rand]

shift_sp -1

push_const 4

equal

push_reg_sp

fetch_i

branch_false L21

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

and

L21

branch_false L20

L19

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_5

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

jump L22

L20

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

fetch_i4

push_const 0

equal

branch_false L24

L23

push_event // myself

push_const 704

add

fetch_i

push_event // talker

push_const 40

add

fetch_i

push_parameter wiseman_challenge_5

func_call 184680516 // func[showPage]

shift_sp -2

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // i_ai0

push_const 308

add

push_reg_sp

fetch_i

push_const 1

assign4

shift_sp -1

L24

L22

L18

L14

L10

L6

handler_end

 

handler 32 786 // MENU_SELECTED

variable_begin

"talker"

"ask"

"reply"

"fhtml0"

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // target

push_const 96

add

push_reg_sp

fetch_i

push_event // talker

push_const 40

add

fetch_i

assign

shift_sp -1

push_event // ask

push_const 160

add

fetch_i4

push_const 1

negate

equal

branch_false L26

L25

push_event // reply

push_const 164

add

fetch_i4

push_const 1

equal

branch_false L28

L27

push_event // myself

push_const 704

add

fetch_i

S2. "Correct answer"

push_string S2

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 10

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

less

branch_false L30

L29

push_event // myself

push_const 704

add

fetch_i

push_event // target

push_const 96

add

fetch_i

push_const 7863

push_const 1

func_call 184746111 // func[GiveItem1]

shift_sp -3

shift_sp -1

L30

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L28

push_event // reply

push_const 164

add

fetch_i4

push_const 2

equal

branch_false L32

L31

push_event // myself

push_const 704

add

fetch_i

S3. "nope"

push_string S3

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L32

push_event // reply

push_const 164

add

fetch_i4

push_const 3

equal

branch_false L34

L33

push_event // myself

push_const 704

add

fetch_i

S4. "nope"

push_string S4

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L34

push_event // reply

push_const 164

add

fetch_i4

push_const 4

equal

branch_false L36

L35

push_event // myself

push_const 704

add

fetch_i

S5. "nope"

push_string S5

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L36

push_event // reply

push_const 164

add

fetch_i4

push_const 5

equal

branch_false L38

L37

push_event // myself

push_const 704

add

fetch_i

S6. "nope"

push_string S6

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L38

L26

push_event // ask

push_const 160

add

fetch_i4

push_const 2

negate

equal

branch_false L40

L39

push_event // reply

push_const 164

add

fetch_i4

push_const 1

equal

branch_false L42

L41

push_event // myself

push_const 704

add

fetch_i

S7. "Correct answer"

push_string S7

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 10

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

less

branch_false L44

L43

push_event // myself

push_const 704

add

fetch_i

push_event // target

push_const 96

add

fetch_i

push_const 7863

push_const 1

func_call 184746111 // func[GiveItem1]

shift_sp -3

shift_sp -1

L44

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L42

push_event // reply

push_const 164

add

fetch_i4

push_const 2

equal

branch_false L46

L45

push_event // myself

push_const 704

add

fetch_i

S8. "nope"

push_string S8

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L46

push_event // reply

push_const 164

add

fetch_i4

push_const 3

equal

branch_false L48

L47

push_event // myself

push_const 704

add

fetch_i

S9. "nope"

push_string S9

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L48

push_event // reply

push_const 164

add

fetch_i4

push_const 4

equal

branch_false L50

L49

push_event // myself

push_const 704

add

fetch_i

S10. "nope"

push_string S10

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L50

push_event // reply

push_const 164

add

fetch_i4

push_const 5

equal

branch_false L52

L51

push_event // myself

push_const 704

add

fetch_i

S11. "nope"

push_string S11

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L52

L40

push_event // ask

push_const 160

add

fetch_i4

push_const 3

negate

equal

branch_false L54

L53

push_event // reply

push_const 164

add

fetch_i4

push_const 1

equal

branch_false L56

L55

push_event // myself

push_const 704

add

fetch_i

S12. "Correct answer"

push_string S12

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 10

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

less

branch_false L58

L57

push_event // myself

push_const 704

add

fetch_i

push_event // target

push_const 96

add

fetch_i

push_const 7863

push_const 1

func_call 184746111 // func[GiveItem1]

shift_sp -3

shift_sp -1

L58

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L56

push_event // reply

push_const 164

add

fetch_i4

push_const 2

equal

branch_false L60

L59

push_event // myself

push_const 704

add

fetch_i

S13. "nope"

push_string S13

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L60

push_event // reply

push_const 164

add

fetch_i4

push_const 3

equal

branch_false L62

L61

push_event // myself

push_const 704

add

fetch_i

S14. "nope"

push_string S14

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L62

push_event // reply

push_const 164

add

fetch_i4

push_const 4

equal

branch_false L64

L63

push_event // myself

push_const 704

add

fetch_i

S15. "nope"

push_string S15

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L64

push_event // reply

push_const 164

add

fetch_i4

push_const 5

equal

branch_false L66

L65

push_event // myself

push_const 704

add

fetch_i

S16. "nope"

push_string S16

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L66

L54

push_event // ask

push_const 160

add

fetch_i4

push_const 4

negate

equal

branch_false L68

L67

push_event // reply

push_const 164

add

fetch_i4

push_const 1

equal

branch_false L70

L69

push_event // myself

push_const 704

add

fetch_i

S17. "Correct answer"

push_string S17

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 10

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

less

branch_false L72

L71

push_event // myself

push_const 704

add

fetch_i

push_event // target

push_const 96

add

fetch_i

push_const 7863

push_const 1

func_call 184746111 // func[GiveItem1]

shift_sp -3

shift_sp -1

L72

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L70

push_event // reply

push_const 164

add

fetch_i4

push_const 2

equal

branch_false L74

L73

push_event // myself

push_const 704

add

fetch_i

S18. "nope"

push_string S18

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L74

push_event // reply

push_const 164

add

fetch_i4

push_const 3

equal

branch_false L76

L75

push_event // myself

push_const 704

add

fetch_i

S19. "nope"

push_string S19

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L76

push_event // reply

push_const 164

add

fetch_i4

push_const 4

equal

branch_false L78

L77

push_event // myself

push_const 704

add

fetch_i

S20. "nope"

push_string S20

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L78

push_event // reply

push_const 164

add

fetch_i4

push_const 5

equal

branch_false L80

L79

push_event // myself

push_const 704

add

fetch_i

S21. "nope"

push_string S21

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L80

L68

push_event // ask

push_const 160

add

fetch_i4

push_const 5

negate

equal

branch_false L82

L81

push_event // reply

push_const 164

add

fetch_i4

push_const 1

equal

branch_false L84

L83

push_event // myself

push_const 704

add

fetch_i

S22. "Correct answer"

push_string S22

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // gg

push_const 632

add

fetch_i

push_const 10

func_call 218169344 // func[Rand]

shift_sp -1

push_const 2

less

branch_false L86

L85

push_event // myself

push_const 704

add

fetch_i

push_event // target

push_const 96

add

fetch_i

push_const 7863

push_const 1

func_call 184746111 // func[GiveItem1]

shift_sp -3

shift_sp -1

L86

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L84

push_event // reply

push_const 164

add

fetch_i4

push_const 2

equal

branch_false L88

L87

push_event // myself

push_const 704

add

fetch_i

S23. "nope"

push_string S23

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L88

push_event // reply

push_const 164

add

fetch_i4

push_const 3

equal

branch_false L90

L89

push_event // myself

push_const 704

add

fetch_i

S24. "nope"

push_string S24

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L90

push_event // reply

push_const 164

add

fetch_i4

push_const 4

equal

branch_false L92

L91

push_event // myself

push_const 704

add

fetch_i

S25. "nope"

push_string S25

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L92

push_event // reply

push_const 164

add

fetch_i4

push_const 5

equal

branch_false L94

L93

push_event // myself

push_const 704

add

fetch_i

S26. "nope"

push_string S26

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L94

L82

handler_end

 

handler 5 177 // SEE_CREATURE

variable_begin

"creature"

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // myself

push_const 704

add

fetch_i

S27. "Who are there ?"

push_string S27

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // p_state

push_const 280

add

fetch_i4

push_const 3

not_equal

push_reg_sp

fetch_i

branch_false L97

push_event // myself

push_const 704

add

fetch_i

func_call 184549406 // func[GetLifeTime]

push_const 7

greater

and

L97

branch_false L96

L95

push_event // myself

push_const 704

add

fetch_i

push_event // creature

push_const 112

add

fetch_i

func_call 184614996 // func[DistFromMe]

shift_sp -1

push_const 200

greater

branch_false L99

L98

push_event // myself

push_const 704

add

fetch_i

push_event // myself

push_const 704

add

fetch_i // sm

push_const 544

add

fetch_i

push_event // myself

push_const 704

add

fetch_i

push_event // creature

push_const 112

add

fetch_i // x

push_const 8

add

fetch_d

func_call 184615005 // func[FloatToInt]

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

push_event // creature

push_const 112

add

fetch_i // y

push_const 16

add

fetch_d

func_call 184615005 // func[FloatToInt]

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

push_event // creature

push_const 112

add

fetch_i // z

push_const 24

add

fetch_d

func_call 184615005 // func[FloatToInt]

shift_sp -1

func_call 184811596 // func[instantTeleport]

shift_sp -4

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

push_parameter TeleportEffect

func_call 184615128 // func[skill_GetConsumeMP]

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // sm

push_const 544

add

fetch_i // mp

push_const 400

add

fetch_d

less

push_reg_sp

fetch_i

branch_false L102

push_event // myself

push_const 704

add

fetch_i

push_parameter TeleportEffect

func_call 184615127 // func[skill_GetConsumeHP]

shift_sp -1

push_event // myself

push_const 704

add

fetch_i // sm

push_const 544

add

fetch_i // hp

push_const 392

add

fetch_d

less

push_reg_sp

fetch_i

branch_false L103

push_event // myself

push_const 704

add

fetch_i

push_parameter TeleportEffect

func_call 184615133 // func[skill_InReuseDelay]

shift_sp -1

push_const 0

equal

and

L103

and

L102

branch_false L101

L100

push_event // myself

push_const 704

add

fetch_i

push_event // myself

push_const 704

add

fetch_i // sm

push_const 544

add

fetch_i

push_parameter TeleportEffect

push_const 1

push_const 1

push_const 1000000

func_call 184877074 // func[AddUseSkillDesire]

shift_sp -5

shift_sp -1

L101

L99

L96

handler_end

 

handler 0 9 // NO_DESIRE

variable_begin

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // myself

push_const 704

add

fetch_i

push_const 5

push_const 5

func_call 184680455 // func[AddMoveAroundDesire]

shift_sp -2

shift_sp -1

handler_end

 

handler 12 24 // TIMER_FIRED_EX

variable_begin

"timer_id"

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

push_event // timer_id

push_const 236

add

fetch_i4

push_const 1

equal

branch_false L105

L104

push_event // myself

push_const 704

add

fetch_i

S28. "bye"

push_string S28

func_call 184614973 // func[say]

shift_sp -1

shift_sp -1

push_event // myself

push_const 704

add

fetch_i

func_call 184549616 // func[Despawn]

shift_sp -1

L105

handler_end

 

handler 10 0 // MY_DYING

variable_begin

"target"

"last_attacker"

"myself"

"_choiceN"

"_code"

"_from_choice"

variable_end

 

handler_end

 

class_end

 

 

 

 

 

HTM Example:

 

 

 

<html><head>

 

<body>

Wiseman challenge: <br>

<br>

What has roots as nobody sees, <br>

Is taller than trees, <br>

Up, up it goes, <br>

And yet never grows? <br>

<br>

<br><a action="bypass -h menu_select?ask=-1&reply=2">" hair "</a>

<br><a action="bypass -h menu_select?ask=-1&reply=3">" clouds "</a>

<br><a action="bypass -h menu_select?ask=-1&reply=1">" mountain "</a>

<br><a action="bypass -h menu_select?ask=-1&reply=4">" palm "</a>

<br><a action="bypass -h menu_select?ask=-1&reply=5">" rock "</a>

<br>

<br>

</body></html>

 

 

 

 

 

Edited by madocter
Posted

Yah, AI is a bit strange, still learning it myself though could have helped with this if i had seen it sooner. :P

Glad you figured it out!

 

I beautified and re-uploaded your code here:

http://pastebin.com/LKqgncrn

 

Have some questions about it:

- Line 18: What is i_ai0? Just an empty int placeholder in the NPC instance? What's the different between doign this and using one of the registers i0, i1, etc?

- Line 65: Why do you assign talker to target? Just for convenience / sanity?

- Line 259: What is p_state?

Posted (edited)

- Line 18: What is i_ai0? Just an empty int placeholder in the NPC instance? What's the different between doign this and using one of the registers i0, i1, etc?

That's an integer variable designed to be used by the AI. Each NPC instance has a separate set of these vars.

 

There is absolutely no difference which vars to use. You simply need to make sure you do not interfere with the logic of the parent classes. Of course, if you override associated handlers not to do 'super()', you can then reuse vars that are in use by parent class(es).

 

There's really nothing more into it.

 

 

Also, I must point out that TALKED is extremely biased towards showing wiseman_challenge_5. You might think the code guarantees a 20% chance for each page, but in reality you will be getting wiseman_challenge_5 at a rate of 41%.

 

 

These are the actual page show rates:

  • 1 – 20%
  • 2 – 16%
  • 3 – 12.8%
  • 4 – 10.24%
  • 5 – 40.96%
Edited by Zeeyo
Posted (edited)

That's an integer variable designed to be used by the AI. Each NPC instance has a separate set of these vars.

 

There is absolutely no difference which vars to use. You simply need to make sure you do not interfere with the logic of the parent classes. Of course, if you override associated handlers not to do 'super()', you can then reuse vars that are in use by parent class(es).

 

There's really nothing more into it.

 

 

Also, I must point out that TALKED is extremely biased towards showing wiseman_challenge_5. You might think the code guarantees a 20% chance for each page, but in reality you will be getting wiseman_challenge_5 at a rate of 41%.

 

 

These are the actual page show rates:

  • 1 – 20%
  • 2 – 16%
  • 3 – 12.8%
  • 4 – 10.24%
  • 5 – 40.96%

 

 

Ahh, right that would make sense.

I guess the i_ai0 is set for the entire length of the NPC's lifetime versus the i0 register which is only valid during handler execution.

Thanks!

 

 

Yah the incorrect chance i think is to due with using if else statements instead of a switch case. Or even a bunch of If's and then return's.

Something like would make more sense.

myself.i_ai0 = gg::Rand(5);
switch (myself.i_ai0)
    {
        case 1:
	{
	    myself::ShowPage( talker, wiseman_challenge_ );
	    break;
	}
	case 2:
	{
      	    myself::ShowPage( talker, wiseman_challenge_2 );
	    break;
	}
	// blah blah....
}

Though TBH i am wondering if this AI would work consistently with more than one player talking to the NPC at once.

If the i_ai0 is internal to the instance, one player is going to overwrite the other if two were talking.

I'd think this is a good time to use a register or if the value needs to be preserved and accessed later, use a Cookie: 

myself.SetCookie(CSharedCreature* talker, string cookieName, int cookieValue);

Edited by tk422
Posted

Though TBH i am wondering if this AI would work consistently with more than one player talking to the NPC at once.

If the i_ai0 is internal to the instance, one player is going to overwrite the other if two were talking.

That's correct. You can check GF PC Cafe buff code: it checks a register designated for 'busy, buffing' state and does not allow players to get buffed until all casts (at fixed time intervals) are finished for the first target.

Posted (edited)

Yah, AI is a bit strange, still learning it myself though could have helped with this if i had seen it sooner. :P

Glad you figured it out!

 

I beautified and re-uploaded your code here:

http://pastebin.com/LKqgncrn

 

Have some questions about it:

- Line 18: What is i_ai0? Just an empty int placeholder in the NPC instance? What's the different between doign this and using one of the registers i0, i1, etc?

- Line 65: Why do you assign talker to target? Just for convenience / sanity?

- Line 259: What is p_state?

Thanks for your interest tk422

 

Line 65 = an error this is not working code but a "preview"

Line 259 can be physical state i dont know i get that teleportation function from vampire wizard a npc (when see a player teleport near him)

Line 18 :

 

Ahh, right that would make sense.

I guess the i_ai0 is set for the entire length of the NPC's lifetime versus the i0 register which is only valid during handler execution.

Thanks!

Yes i use it to prevent npc being talked more than one time so players cant trick it. maybe im wrong but i believe it can work even if 2 players try to talk at same time

 

About create a register - cookie is good idea , pity i dont know how such functions works

 

Thanks also Zeeyo

 

 

This is working code:

 

 

class 1 wiseman : citizen

{

parameter:

  string  wiseman_challenge_1 = "wiseman_challenge_1.htm";

  string  wiseman_challenge_2 = "wiseman_challenge_2.htm";

  string  wiseman_challenge_3 = "wiseman_challenge_3.htm";

  string  wiseman_challenge_4 = "wiseman_challenge_4.htm";

  string  wiseman_challenge_5 = "wiseman_challenge_5.htm";

  string  Reward = "coffer_of_the_dead:wiseman_reward:1:5000sec";

  string  Reward_2 = "__sand:wiseman_buffer:1:5000sec";

  string  Conversion = "giant_toad:giant_toad:1:5000sec";

       

 

handler:

 

 

EventHandler CREATED()

  {

    myself::Shout( "All we have to decide is what to do with the time that is given us." );

  }

 

 

  EventHandler TALKED( talker )

  {

 

    if( myself.i_ai0 == 1 )

    {

    myself::Say( "bye");

        myself::CreatePrivates( Conversion );

        myself::Despawn();

    }

        

 

        myself::AddTimerEx( 1, 13 * 1000 );

    myself::Say( "Hurry up you have a few seconds to answer");

 

 

 

    switch ( gg::Rand( 5 ) )

        {

 

        case 1:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_1 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 2:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_2 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 3:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_3 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 4:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_4 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 5:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_5 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        }

 

 

    

  }

 

 

 

  EventHandler MENU_SELECTED( talker, ask, reply, fhtml0 )

  {

 

 target = talker;

 

  if ( ask == -1 )

    {

 

 

     if ( reply == 1 )

       {

       myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -2)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -3)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

  if (ask == -4)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

  if (ask == -5)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

 

 

 

  }

 

 

  EventHandler SEE_CREATURE( creature )

  {

myself::Say( "Who are there ?");

 

    if( myself.p_state != 3 && myself::GetLifeTime() > 7 )

    {

      if( myself::DistFromMe( creature ) > 200 )

      {

        myself::InstantTeleport( myself.sm, myself::FloatToInt( creature.x ),

                                 myself::FloatToInt( creature.y ),

                                 myself::FloatToInt( creature.z ) );

        if( myself::Skill_GetConsumeMP( TeleportEffect ) < myself.sm.mp &&

            myself::Skill_GetConsumeHP( TeleportEffect ) < myself.sm.hp &&

            myself::Skill_InReuseDelay( TeleportEffect ) == 0 )

        {

          myself::AddUseSkillDesire( myself.sm, TeleportEffect, 1, 1,

                                     1000000 );

        }

      }

 

    }

  }

 

 

 

  EventHandler NO_DESIRE()

  {

    myself::AddMoveAroundDesire( 5, 5 );

  }

 

EventHandler TIMER_FIRED_EX( timer_id )

    {

 

    if( timer_id == 1 )

    {

    myself::Say( "bye");

        myself::CreatePrivates( Conversion );

        myself::Despawn();

    }

 

 

    }

 

 

 

  EventHandler MY_DYING( target , last_attacker )

  {

 

         

  }

 

 

}

 

 

 

3TybCjB.jpg

Edited by madocter
Posted (edited)

Thanks for your interest tk422

 

Line 65 = an error this is not working code but a "preview"

Line 259 can be physical state i dont know i get that teleportation function from vampire wizard a npc (when see a player teleport near him)

Line 18 :

 

Yes i use it to prevent npc being talked more than one time so players cant trick it. maybe im wrong but i believe it can work even if 2 players try to talk at same time

 

About create a register - cookie is good idea , pity i dont know how such functions works

 

Thanks also Zeeyo

 

 

This is working code:

 

 

class 1 wiseman : citizen

{

parameter:

  string  wiseman_challenge_1 = "wiseman_challenge_1.htm";

  string  wiseman_challenge_2 = "wiseman_challenge_2.htm";

  string  wiseman_challenge_3 = "wiseman_challenge_3.htm";

  string  wiseman_challenge_4 = "wiseman_challenge_4.htm";

  string  wiseman_challenge_5 = "wiseman_challenge_5.htm";

  string  Reward = "coffer_of_the_dead:wiseman_reward:1:5000sec";

  string  Reward_2 = "__sand:wiseman_buffer:1:5000sec";

  string  Conversion = "giant_toad:giant_toad:1:5000sec";

       

 

handler:

 

 

EventHandler CREATED()

  {

    myself::Shout( "All we have to decide is what to do with the time that is given us." );

  }

 

 

  EventHandler TALKED( talker )

  {

 

    if( myself.i_ai0 == 1 )

    {

    myself::Say( "bye");

        myself::CreatePrivates( Conversion );

        myself::Despawn();

    }

        

 

        myself::AddTimerEx( 1, 13 * 1000 );

    myself::Say( "Hurry up you have a few seconds to answer");

 

 

 

    switch ( gg::Rand( 5 ) )

        {

 

        case 1:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_1 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 2:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_2 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 3:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_3 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 4:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_4 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        case 5:

    {

        if( myself.i_ai0 == 0 )

        {

    myself::ShowPage( talker, wiseman_challenge_5 );

    myself.i_ai0 = 1;

    break;

        }

        break;

    }

 

        }

 

 

    

  }

 

 

 

  EventHandler MENU_SELECTED( talker, ask, reply, fhtml0 )

  {

 

 target = talker;

 

  if ( ask == -1 )

    {

 

 

     if ( reply == 1 )

       {

       myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -2)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

 

    }

 

  if (ask == -3)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

  if (ask == -4)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

  if (ask == -5)

    {

 

 

     if ( reply == 1 )

       {

        myself::Say( "Correct answer");

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward );

       }

 

       if( gg::Rand( 10 ) < 5 )

       {                

       myself::CreatePrivates( Reward_2 );

       }

 

    myself::Despawn();

       }

 

     if ( reply == 2 )

       {

    myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 3 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 4 )

       {

           myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

 

     if ( reply == 5 )

       {

        myself::Say( "nope");

        myself::CreatePrivates( Conversion );

    myself::Despawn();

       }

     

    }

 

 

 

 

  }

 

 

  EventHandler SEE_CREATURE( creature )

  {

myself::Say( "Who are there ?");

 

    if( myself.p_state != 3 && myself::GetLifeTime() > 7 )

    {

      if( myself::DistFromMe( creature ) > 200 )

      {

        myself::InstantTeleport( myself.sm, myself::FloatToInt( creature.x ),

                                 myself::FloatToInt( creature.y ),

                                 myself::FloatToInt( creature.z ) );

        if( myself::Skill_GetConsumeMP( TeleportEffect ) < myself.sm.mp &&

            myself::Skill_GetConsumeHP( TeleportEffect ) < myself.sm.hp &&

            myself::Skill_InReuseDelay( TeleportEffect ) == 0 )

        {

          myself::AddUseSkillDesire( myself.sm, TeleportEffect, 1, 1,

                                     1000000 );

        }

      }

 

    }

  }

 

 

 

  EventHandler NO_DESIRE()

  {

    myself::AddMoveAroundDesire( 5, 5 );

  }

 

EventHandler TIMER_FIRED_EX( timer_id )

    {

 

    if( timer_id == 1 )

    {

    myself::Say( "bye");

        myself::CreatePrivates( Conversion );

        myself::Despawn();

    }

 

 

    }

 

 

 

  EventHandler MY_DYING( target , last_attacker )

  {

 

         

  }

 

 

}

 

 

 

3TybCjB.jpg

 

Ah cool! Thanks for the info on p_state!

Do you know what the available states are?

I assume:

- 0 = Ready

- 1 = Busy (Using Skill)

 

Cookie's are like player-properties you can set.

They can only hold int values.

 

Cookies are NOT persisted to the database.

When the player logs out, they are removed.

 

To SET a cookie:

void myself.SetCookie(CSharedCreature* talker, string cookieName, int cookieValue);

 

To GET a cookie:

int myself.GetCookie(CSharedCreature* talker, string cookieName);

 

They're great for something like holding a player's choice before promping for some verification.

 

Example:

I've written a de-level NPC where players select their desired level but then also must enter their current level as a sanity check and to confirm they REALLY want to do this.

Since you can only send back one bit of information from the player's interaction with the NPCs HTML i must get their cookie first, then perform the confirmation.

If the conformation goes though, get the cookie and set their desired level.

 

 

Some additional thoughts:

 

1.
Since a switch case in NASC doesn't provide a default case
you often have to rely on fall-through cases.
 
You code could be made more readable / organized like this:
switch (reply)
{
	case replyIncorrectChoice1:
	case replyIncorrectChoice2:
	case replyIncorrectChoice3:
	case replyIncorrectChoice4:
	{
	    myself::Say( "nope");
            myself::CreatePrivates( Conversion );
    	    myself::Despawn();
    	    break; // Stops "fall through"
	}
	case replyCorrectChoice:
	{
	    myself::Say( "Correct answer");
	    break;
	}
}
2.

Calculating Rand(10 < 5) a bunch of times takes up handler / CPU time unneccisarily.

You only need to do this once.
class 1 wiseman : citizen
{
parameter:
	int replyFinishedChosing = 1000;

handler:
EventHandler MENU_SELECTED(talker, ask, reply, fhtml0, i0)
{
	if (reply == replyFinishedChoosing)
	{
		// I specified in the handler arguments that i'd like
		// to use one of the 10 int registers i0-i9;
		// We can now assign the result of ONE Rand() call to
		// it and then check that.
		i0 = Rand(10);
		if (i0 < 5)
		{
		    // Reward One
		}
		else
		{
		    // Reward Two.
		}
	}
}
Edited by tk422
Posted (edited)

Actually here is a more fleshed out example of how i personally write AI:

http://pastebin.com/ejAEbaZU

 

- I wrote this in SublimeText on a Mac so please excuse any typos.

- I left out actually setting their level.

 

It would be great if we as a community could agree on a set of style guidelines for NASC.

... I vote for mine! :D

Edited by tk422
Posted

Actually here is a more fleshed out example of how i personally write AI:

http://pastebin.com/ejAEbaZU

 

- I wrote this in SublimeText on a Mac so please excuse any typos.

- I left out actually setting their level.

 

It would be great if we as a community could agree on a set of style guidelines for NASC.

... I vote for mine! :D

 

 

Nice code maybe i will take for myself :) will be great too any guide ncsoft artificial intelligence script compiler = nasc

 

2.    but why use   " i0 "  is not used at other handlers ? i've tried create an int value at parameters but it fails like we forced to reuse existing...

 

#

 

Im doing rol event npc currently done wiseman who ask questions , princess who needs be rescued , and marauder that should be walking around roads of all map but create coordinates is weird. check private msq if you want use its working

 

BTW here is code for giran asault by monsters

 

http://pastebin.com/zr7AFkC0

Posted (edited)

In the parentheses for each handler you define which registers you plan to use.

 

In my code for the delevel NPC i should have removed i0, that was a typo. I don't actually use it as you can see.

 

Let me give you an example:

http://pastebin.com/hx1qAbrp

 

You can't define local variables within the code like you would in C / C++.

int mySpecialInt = 56; // Not Allowed! 

You may only use the NPC's instance variables or the registers.

 

I posted a topic asking why the registers worked this way a while back. 

 

mcbigmac answered something like this:

- The VM that runs the compile AI is multi threaded and extremely efficient.

- By limiting the "freedom" of the code you write it allows it to be executed faster and more reliably.

- If handlers were allowed to create their own var's every time they run they'd take up an obscene amount of ram.

 

Hopefully he or someone else will correct me if i'm wrong. :D

 

For your event:

NPC's movement is defined in the GeoData/SuperPoint.bin file.

Take a look at Remy (the moron who runs around TI shouting screaming) and you can see how it works.

 

Check out this post also:

http://www.maxcheaters.com/topic/89864-share-superpointbin-information/

 

It explains how the connections and nodes work.

Edited by tk422

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...