Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [HELP] AI coding (https://postpacific.loc-online.com/showthread.php?t=4939)

Dave 24.06.2006 17:55

[HELP] AI coding
 
I am trying to create an ai for npc that i have that will buff with specific skill once you click on him, can anyone give me some help on this.

localhost 24.06.2006 18:02

Hrmmm I remember someone posting an awesome guide about ai a little while back... can't seem to find it though...

EDIT: Try this https://postpacific.loc-online.com/f...ad.php?id=1407

FidoW 24.06.2006 18:46

If you only need npc give 1 buff.... is very simple.

Code:

class citizen { }

class buffer_npc : citizen {

  parameter:
    int Buff1 = 308226;  // Wind Walk lvl 2

  handler:

  EventHandler TALKED(talker)
  {
    AddUseSkillDesire(talker, Buff1, 0, 1, 1000000); 
  }

}


Change Buff1 value for other buff skill id (skill_pch.txt) that you wish npc give to u when u talk to him.

Alexandros 24.06.2006 23:07

Well i made with a little help of some topics this ai:

Code:

class clanhallbuffer : default_npc
parameter_define_begin
  string fnHi "ch_hi.htm"
  string fnNextBuff "chbuffmenu.htm"
  int Might 1112323
  int Shield 1112067
  int Focus 1115907
  int WindWalk 1111554
  int Guidance 1115651
  int Agility 278275
  int Acumen 1114883
  int Empower 1115139
  int Haste 1115394
  int DeathWisper 1116163
  int HolyWeapon 1031169
  int MagicBarrier 1113346
  int BlessBody 1112838
  int BlessSoul 1113094
  int Regeneration 267267
  int Berserker 1114114
  int RessistShock 1113604
  int BlessShield 318212
  int MentalShield 264963
  int DecreaseWeight 1111811
parameter_define_end

handler 3  //  TALKED
  variable_begin
      "talker"
      "myself"
      "_choiceN"
      "_code"
      "_from_choice"
  variable_end

 
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter fnHi
  func_call 43  //  func[ShowPage]
  shift_sp -2
  shift_sp -1

handler_end

handler 32  //  MENU_SELECTED
  variable_begin
      "ask"
      "reply"
      "talker"
      "myself"
      "_choiceN"
      "_code"
      "_from_choice"
  variable_end


L100221


  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 201
  negate
  equal
  branch_false L100201

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Might
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100201
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 202
  negate
  equal
  branch_false L100202

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Shield
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100202
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 203
  negate
  equal
  branch_false L100203

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Focus
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100203
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 204
  negate
  equal
  branch_false L100204

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter WindWalk
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100204
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 205
  negate
  equal
  branch_false L100205

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Guidance
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100205
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 206
  negate
  equal
  branch_false L100206

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Agility
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100206
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 207
  negate
  equal
  branch_false L100207

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Acumen
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100207
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 208
  negate
  equal
  branch_false L100208

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Empower
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100208
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 209
  negate
  equal
  branch_false L100209

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Haste
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100209
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 210
  negate
  equal
  branch_false L100210

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter DeathWisper
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100210
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 211
  negate
  equal
  branch_false L100211

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter HolyWeapon
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100211
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 212
  negate
  equal
  branch_false L100212

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter MagicBarrier
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100212
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 213
  negate
  equal
  branch_false L100213

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter BlessBody
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100213
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 214
  negate
  equal
  branch_false L100214

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter BlessSoul
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100214
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 215
  negate
  equal
  branch_false L100215

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Regeneration
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100215
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 216
  negate
  equal
  branch_false L100216

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter Berserker
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100216
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 217
  negate
  equal
  branch_false L100217

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter RessistShock
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100217
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 218
  negate
  equal
  branch_false L100218

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter BlessShield
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100218
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 219
  negate
  equal
  branch_false L100219

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter MentalShield
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100219
  push_event  //  ask
  push_const 100
  add
  fetch_i
  push_const 220
  negate
  equal
  branch_false L100220

  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter DecreaseWeight
  push_const 0
  push_const 1
  push_const 1000000
  func_call 10  //  func[AddUseSkillDesire]
  shift_sp -5
  shift_sp -1
  jump L100220

L100220
  shift_sp 1
  push_event  //  talker
  push_const 32
  add
  fetch_i
  push_parameter fnNextBuff
  func_call 43  //  func[ShowPage]
  shift_sp -2
  shift_sp -1
 


 
 handler_end

class_end

Its a simple buffer.Not special functions of Checking LvL/Karma/Clan or asking for money.


This is the code of the HTMLs'
Code:

<html><body>




 

  Hello.What do u want?</p>

<pre></pre>

<center>

 


    <a action="link chbuffmenu.htm">Buff me</a></br></p>
</center></body></html>

Code:

<html><body><center>
<font color="000000">BUFF MENU</font>





<a action="bypass -h menu_select?ask=-201">Might</a>

<a action="bypass -h menu_select?ask=-202">Shield</a>

<a action="bypass -h menu_select?ask=-203">Focus</a>

<a action="bypass -h menu_select?ask=-204">Windwalk</a>

<a action="bypass -h menu_select?ask=-205">Guidance</a>

<a action="bypass -h menu_select?ask=-206">Agility</a>

<a action="bypass -h menu_select?ask=-207">Acumen</a>

<a action="bypass -h menu_select?ask=-208">Empower</a>

<a action="bypass -h menu_select?ask=-209">Haste</a>

<a action="bypass -h menu_select?ask=-210">Death Whisper</a>

<a action="bypass -h menu_select?ask=-211">Holy Weapon</a>

<a action="bypass -h menu_select?ask=-212">Magic Barrier</a>

<a action="bypass -h menu_select?ask=-213">Bless the Body</a>

<a action="bypass -h menu_select?ask=-214">Bless the Soul</a>

<a action="bypass -h menu_select?ask=-215">Regeneration</a>

<a action="bypass -h menu_select?ask=-216">Berserker</a>

<a action="bypass -h menu_select?ask=-217">Ressist Shock</a>

<a action="bypass -h menu_select?ask=-218">Bless the Shield</a>

<a action="bypass -h menu_select?ask=-219">Mental Shield</a>

<a action="bypass -h menu_select?ask=-220">Decrease Weight</a>




<a action="link ch_hi.htm">Return</a>
</center></body></html>

I am not sure if it is working as i cant test it.If u want try this or it would be really good if some1 else would try this for me and tell me if it works

2 Questions that i have:
1) i am not sure for the action of the HTML of buffmenu.Does it needs also the reply?
2) I saw also this post https://postpacific.loc-online.com/f...?p=50774#50774
I noticed a difference on the ai at the casting buff.My ai and the one that posted the other ai there differ in the following:

I use push_parameter HolyWeapon whereas the other guy there uses push_event // reply
push_const 104

What is the difference?

tpuNIsher 25.06.2006 02:16

just use nasc =p

Code:

class clanhallbuffer : default_npc {

  parameter:

  string fnHi = "ch_hi.htm";
  string fnNextBuff = "chbuffmenu.htm";
  int Might = 1112323;
  int Shield = 1112067;
  int Focus = 1115907;
  int WindWalk = 1111554;
  int Guidance = 1115651;
  int Agility = 278275;
  int Acumen = 1114883;
  int Empower = 1115139;
  int Haste = 1115394;
  int DeathWisper = 1116163;
  int HolyWeapon = 1031169;
  int MagicBarrier = 1113346;
  int BlessBody = 1112838;
  int BlessSoul = 1113094;
  int Regeneration = 267267;
  int Berserker = 1114114;
  int RessistShock = 1113604;
  int BlessShield = 318212;
  int MentalShield = 264963;
  int DecreaseWeight = 1111811;

  handler:

  EventHandler TALKED(talker) {
    ShowPage(talker, fnHi);
  }
 


  EventHandler MENU_SELECTED(ask, talker) {
    if (ask == -201) {
      AddUseSkillDesire(talker, Might, 0, 1, 1000000);
    }
    else {
      if (ask == -202) {
        AddUseSkillDesire(talker, Shield, 0, 1, 1000000);
      }
      if (ask == -203) {
        AddUseSkillDesire(talker, Focus, 0, 1, 1000000);
      }
      if (ask == -204) {
        AddUseSkillDesire(talker, WindWalk, 0, 1, 1000000);
      }
      if (ask == -205) {
        AddUseSkillDesire(talker, Guidance, 0, 1, 1000000);
      }
      if (ask == -206) {
        AddUseSkillDesire(talker, Agility, 0, 1, 1000000);
      }
      if (ask == -207) {
        AddUseSkillDesire(talker, Acumen, 0, 1, 1000000);
      }
      if (ask == -208) {
        AddUseSkillDesire(talker, Empower, 0, 1, 1000000);
      }
      if (ask == -209) {
        AddUseSkillDesire(talker, Haste, 0, 1, 1000000);
      }
      if (ask == -210) {
        AddUseSkillDesire(talker, DeathWisper, 0, 1, 1000000);
      }
      if (ask == -211) {
        AddUseSkillDesire(talker, HolyWeapon, 0, 1, 1000000);
      }
      if (ask == -212) {
        AddUseSkillDesire(talker, MagicBarrier, 0, 1, 1000000);
      }
      if (ask == -213) {
        AddUseSkillDesire(talker, BlessBody, 0, 1, 1000000);
      }
      if (ask == -214) {
        AddUseSkillDesire(talker, BlessSoul, 0, 1, 1000000);
      }
      if (ask == -215) {
        AddUseSkillDesire(talker, Regeneration, 0, 1, 1000000);
      }
      if (ask == -216) {
        AddUseSkillDesire(talker, Berserker, 0, 1, 1000000);
      }
      if (ask == -217) {
        AddUseSkillDesire(talker, RessistShock, 0, 1, 1000000);
      }
      if (ask == -218) {
        AddUseSkillDesire(talker, BlessShield, 0, 1, 1000000);
      }
      if (ask == -219) {
        AddUseSkillDesire(talker, MentalShield, 0, 1, 1000000);
      }
      if (ask == -220) {
        AddUseSkillDesire(talker, DecreaseWeight, 0, 1, 1000000);
      }
      ShowPage(talker, fnNextBuff);
    }
   

  }

That's what ur code looks like decompiled =p

FidoW 25.06.2006 03:34

Code:

class citizen { }

class buffer_npc : citizen {

  parameter:

  string fnHi = "buffer_npc001.htm";
  string fnYouAreChaotic = "buffer_npc002.htm";
  string fnNotEnoughAdena = "not_enough_adena.htm";
  string fnWait = "buffer_npc_wait.htm";
  int Adena = 1000;
  int Delay = 250;

  handler:

  EventHandler TALKED(talker)
  {
    if (talker.karma > 0) ShowPage(talker, fnYouAreChaotic);
    else ShowPage(talker, fnHi);
    super;
  }

  EventHandler CREATED() {
    myself.i_ai0 = 0;
  }

  EventHandler MENU_SELECTED(ask, reply, talker) {
    if ( (ask == -201) && (OwnItemCount(talker, @adena) >= Adena) ) {
      if (myself.i_ai0 == 0) {
        myself.i_ai0 = 1;
        DeleteItem1(talker, @adena, Adena);
        AddUseSkillDesire(talker, reply, 0, 1, 1000000); 
        ShowPage(talker, fnHi);
        AddTimerEx(1, Delay);
      }
      else ShowPage(talker, fnWait);
    }
    else ShowPage(talker, fnNotEnoughAdena);
  }
 
  EventHandler TIMER_FIRED_EX(timer_id) {
    if (timer_id == 1) myself.i_ai0 = 0;
  } 
 
}

This is my version of buffer_npc... with little delay between buffs for prevent pay adena and dont get buff... reply is skill_pch value, be carefull if u arent using tontor patch to prevent HTML bug... because a modified html can get any buff (for example Super Haste).... dont use this code without html fix...

Alexandros 25.06.2006 08:01

Thnx both for your answers really helpfull :)
Another 2 questions ....
--what is the myself.i_ai0 = 0 (and then it is used also with = 1) ? Basically i dont understand the
Code:

EventHandler CREATED() {
    myself.i_ai0 = 0;
  }

--Also FidoW in your ai what is the "super" u have added at the EventHandler Talked?

FidoW 25.06.2006 11:39

When NPC is spawned (CREATED)... i_ai0 is set to 0...

When someone request a buff a condition check if i_ai0 is 0 -> if (myself.i_ai0 == 0)

If is 0 means no one is using the buffer at this moment, because the first line when i request a buff is -> myself.i_ai0 = 1; now someone is using npc... and i add a timer -> AddTimerEx(1, Delay); ... this timer set i_ai0 to 0 again, now is possible to use buffer again... Delay value is set to 250 (0,25 seconds) is very little delay, maybe need increment this value, but help a lot right now.

I do that because if a lot of people is trying to get buff at the same time... npc only give to a few players, but delete adena of all.

"Adena" variable is amount of adena player need to be buffed.

super; is call_super parameter in AI.obj, i use this because in citizen AI i have more code to use (greetings when talked)

Alexandros 25.06.2006 14:23

Aahh i understood now.Thnx really for your help :)

m4rk 25.06.2006 15:49

Sorry for OFFtopic: This could be stickied, it has good explanations and good practical examples!

Dave 26.06.2006 16:04

ai npc coding
 
I have two question about AI.

fist of all I would like to create ai for mobs to have both physicalspicial and DDmagic skills. Can someone provide me an example. I have tried but it will only do one or the other not both.

secondly,
I have the AI code to make npc move (ie. wave, explain) I was wondering is there a code for mobs that make them move like c4 official. (i.e. bend, stretch and such)


All times are GMT. The time now is 16:39.