Soulless
Super Moderator
Posts: 335
Likes Given: 29
Likes Received: 49 in 27 posts
Joined: Jun 2012
Reputation: 12
Ye Olde Sphere
|
RE: NPCS - Town stones
here's my AI as of now. i feel like the weapon selection part could be simplified, but i wanted to make the npc as brilliant as possible. incase the project grows and he ends up looting random weapons/shields. checks for the strongest damage weapon + skill of npc factors into weapon selection. if the best weapon is 1 handed the npc then looks for the best shield in its bag and equips it. its missing a ranged weapon selection process but has a spot for it. the rest is stuff i gutted from the npc_ai script in the addon from the SCP pack.
as a side note, does anyone know how to make it so that an NPC will walk from one spot on the map to another. like say from britain graveyard to britain bank, id like him to run the whole way. anyone know how to do that?
Code:
[defname custom_ai_settings]
fearofdeath 60
healself 60
[events e_custom_AI]
on=@gethit
if ((<body>==c_man) || (<body>==c_woman)) && (<memoryfindtype.memory_war_targ>)
if (<distance <memoryfindtype.memory_war_targ.link.uid>> < 3) //equip the best melee weapon i can find, enemy is close range
ref1=<uid>
ref2=<findlayer.1.uid> //if i have a weapon in my hand start with it
if (strmatch(t_weapon*,<findlayer.2.type>) && (<findlayer.2.type>!=t_shield) && (<findlayer.2.type>!=t_weapon_bow) && (<findlayer.2.type>!=t_weapon_xbow)
ref2=<findlayer.2.uid> //if i'm holding a two hand weapon start with that (not a shield or ranged weapon)
endif
forcont <findlayer.21.uid> 1
if (strmatch(t_weapon*,<type>) && (<type>!=t_weapon_arrow) && (<type>!=t_weapon_bolt) && (<type>!=t_weapon_bow) && (<type>!=t_weapon_xbow)
if !(<ref2>) //if i'm not holding any weapons start with the first on you find in my bag
ref2=<uid>
endif
if <eval (<damavg <dam>>+(<ref1.<serv.skill.<skill>.key>>/10))> > <eval(<damavg <ref2.dam>>+(<ref1.<serv.skill.<ref2.skill>.key>>/10))>
ref2=<uid> //if this weapon is best so far that i have skill in, keep it in mind
endif
endif
endfor
if (<ref2>!=<findlayer.1.uid>) && (<ref2>!=<findlayer.2.uid>)
ref1.equip <ref2> //equip the best weapon ive got (skill accounted for also)
endif
if (!<findlayer.2.uid>) || !(strmatch(t_weapon*,<findlayer.2.type>) //now that i'm holding my best weapon, if it's one handed see if i have a shield
ref2= //clear reference 2
if (<findlayer.2.type>==t_shield)
ref2=<findlayer.2.uid>
endif
forcont <findlayer.21.uid> 1
if (<type>==t_shield) //if i don't have a shield equipped start with first one found in bag
if !(<ref2>)
ref2=<uid>
endif
if (<damavg <armor>> > <damavg <ref2.armor>>)
ref2=<uid> //if this shield is the best so far, keep it in mind
endif
endif
endfor
if (<ref2>)
ref1.equip <ref2> //equip the best shield ive got
endif
endif
elseif (<distance <memoryfindtype.memory_war_targ.link.uid>> > 3)
return 0//i'm being attacked at range, if i have a bow or crossbow, equip it
endif
endif
if (<hits> < <eval (<str>*<def0.fearofdeath>)/100>)
//if !(<findid.i_potion_heal>)
if (<src.uid> != <uid>)
act = <src.uid>
flee 20
tag0.fleeing = 1
damage <argn1> <argn2> <uid>
return 1
endif
//endif
endif
//heal myself with a potion if i have one, when im below 'def.healself'% health
if (<hits> <= <eval (<maxhits>*<def0.healself>)/100>)
if (<findid.i_potion_heal>)
findid.i_potion_heal.useitem
return 0
endif
endif
//heal myself with magic if im able, when im below 'def.healself'% health
if (<hits> <= <eval (<maxhits>*<def0.healself>)/100>)
if (<cancast s_greater_heal>)
npccast s_greater_heal,<uid>
endif
endif
//dispell conjured/summoned pets that are attacking me
if (<src.flags>&statf_conjured)
if (<mana> > <serv.spell.s_dispel.manause>)
src.spelleffect s_dispel,1500
src.sound snd_spell_dispel
mana -= <serv.spell.s_dispel.manause>
endif
endif
//attack the person dealing the most damage to me
local.mosthits = 0
local.most_dangerous_enemy = 0
for n 0 <eval <attacker> -1 >
if (<attacker.<dlocal.n>.dam> > <local.mosthits>) && (<canseelos <attacker.<dlocal.n>>>)
local.mosthits = <attacker.<dlocal.n>.dam>
local.most_dangerous_enemy = <attacker.<dlocal.n>>
endif
endfor
attack <local.most_dangerous_enemy>
on=@npcactfight
if (<tag0.fleeing>)
argn = -1
endif
[function damavg]
return <eval ((<argv[0]>+<argv[1]>)/2)>
[chardef c_icedragon]
name=IceDragon
id=c_man
dam=15,20
armor=//20
tevents=e_custom_ai
category=Custom
subsection=NPCs
description=IceDragon
on=@create
npc=brain_human
color=colors_skin
str={151 165}
dex={151 165}
int={151 165}
swordsmanship=100.0
tactics=100.0
magicresistance=100.0
healing=100.0
itemnewbie=i_hair_ponytail
color=colors_hair
itemnewbie=i_beard_goatee
color=match_hair
on=@npcrestock
item=i_platemail_gloves
item=i_platemail_helm
item=i_platemail_arms
item=i_platemail_gorget
item=i_platemail_chest
item=i_platemail_leggings
item=i_halberd
item=i_cape
color=0386
item=i_tunic
color=020
item=i_kilt
color=0386
item=i_potion_heal
item=i_potion_heal
(This post was last modified: 07-13-2012 02:16 AM by Soulless.)
|
|
07-13-2012 02:15 AM |
|
|