/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// "Custom AI EVENTS" by Extreme for SphereCommunity.
// Contact via PM in SphereCommunity Forum or in the thread.
// Thread link: http://forum.spherecommunity.net/showthread.php?tid=1684
//
// - Setup
//
// -- Copy this script to your Scripts folder.
// -- Find C_RAT, C_A_RAT_SEWER and C_RAT_GIANT and set TEVENTS=E_AI_RAT, MOVERATE 20 and increase their INT and DEX to be smarter to flee.
// -- Find C_CAT and set TEVENTS=E_AI_CAT, MOVERATE 50 and increase their INT and DEX to be smarter and quick.
// -- Find C_DOG and set TEVENTS=E_AI_DOG, MOVERATE 50 and increase their INT and DEX to be smarter and quick.
// -- Find C_WOLF, C_A_WOLF_GRAY, C_A_WOLF_WHITE and C_A_DIREWOLF, and set TEVENTS=E_AI_WOLF, MOVERATE 50 and change their INT and DEX.
// -- Find all snakes and set TEVENTS=E_AI_SNAKE
// -- Find all birds and eagle and set TEVENTS=E_AI_BIRD
// -- Find all bears and set TEVENTS=E_AI_BEAR
// -- Find C_CHICKEN and set TEVENTS=E_AI_CHICKEN
//
//
// 1.0 Update [19/08/2012]
// -- Added E_AI_WOLF
// Will attack any mob that aren't carnivores, cats, dogs, rats and rabbits.
// Will seek and destroy the first target until it death or be dead.
// If get attacked by anything, will attack back.
// They will get +5 in each status bonus if have other wolves near.
// Every 5s it will be checked if they are in radius of 18 tiles (not using forchars, is just <DISTANCE>)
// If the wolf leave the radius, the one that gained the bonus will lose it.
// @ 2 debug lines that are commented if you want to test, just uncomment them.
// //SERV.B @026,,1 <NAME> loosing bonus from <QVAL <UID.<REF1>>?<REF1.NAME>:a dead wolf>
// //SERV.B @044,,1 <NAME> getting bonus from <SRC.NAME>
// -- Added E_AI_RAT
// Will try flee of any npc, player or monster comes near or try attack.
// -- Added E_AI_CAT
// Will attack any rat, birds and rabbits.
// Will try flee from wolves and dogs.
// -- Added E_AI_DOG
// Will attack any rat and cats.
// Will fight with wolves if get attacked.
//
// 1.1 Update [20/08/2012]
// -- E_AI_BIRD
// Will attack all snake kind except giant snake.
// Will try flee from other mobs.
// -- Added E_AI_SNAKE
// Will attack all birds, rats, cats, rabbits and dogs.
// Will try flee from other mobs.
// -- Added C_RABBIT and C_A_JACKRABBIT in combat table. Cats and Snakes will attack them.
//
// 1.2 Update [20/08/2012]
// -- Added rat memory and rat poop.
// All rats will pee in ground every 30~60s.
// When steping the rat poop, if <SRC> is rat or already poisoned or ISGM, nothing will happen.
// Else it will get poisoned.
// -- Added E_AI_BEAR.
// They will attack any BRAIN_ANIMAL except Bears if they are stronger than the target.
// They will seek and destroy the targets like wolves.
// They will not have bonuses of near bears.
// They will fish if near water, 50% chance to pull out a fish. Will eat and toss the head.
// * The fish will be eaten only one time, preventing 2 bears eat the same fish and create 2 head for 1 fish.
// -- All AI's will come back to their HOME if they DISTANCE > HOMEDIST
// -- Added E_AI_CHICKEN
// They will lay eggs on ground in every 120~180s.
// When stepped, they will crack and deleted in 10~30s.
// * They are not eating anything yet.
// * The eggs will not be cracked by snakes and chickens.
// -- Modified E_AI_SNAKE
// They will lay eggs on ground in every 120~180s.
// They will eat chicken and snake eggs, but not yours.
//
// 1.3 Update [21/08/2012]
// -- Eggs now will decay in 60~120s.
// -- When the eggs crush, it will change their DISPID.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
[FUNCTION F_WOLVES_PACK]
IF <EVAL <ARGV[0]>> == 1
STR += 5
INT += 5
DEX += 5
MAXHITS += 5
MAXMANA += 5
MAXSTAM += 5
HITS += 5
MANA += 5
STAM += 5
ELSE
REF1 <ARGS>
IF <UID.<REF1>>
IF <DISTANCE <REF1>> <= 18
TIMERF 5, F_WOLVES_PACK <REF1>
RETURN 1
ENDIF
ENDIF
//SERV.B @026,,1 <NAME> loosing bonus from <QVAL <UID.<REF1>>?<REF1.NAME>:a dead wolf>
TAG.<REF1>
STR -= 5
INT -= 5
DEX -= 5
MAXHITS -= 5
MAXMANA -= 5
MAXSTAM -= 5
HITS -= 5
MANA -= 5
STAM -= 5
RETURN 1
ENDIF
[EVENTS E_AI_WOLF]
ON=@NPCLOOKATCHAR
IF STRMATCH(*CARNIVORES*,<SERV.CHARDEF.<SRC.BASEID>.AVERSIONS>) || STRMATCH(*<SRC.BASEID>*,C_CAT,C_DOG,C_A_RAT_SEWER,C_RAT_GIANT)
IF <FINDID.I_WOLF_BERSERKER>
IF !<UID.<FINDID.I_WOLF_BERSERKER.TAG.ATTACK>>
FINDID.I_WOLF_BERSERKER.TAG.ATTACK <SRC>
ENDIF
FINDID.I_WOLF_BERSERKER.TIMER 0
ELSE
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_WOLF_BERSERKER
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TAG.ATTACK <SRC>
REF1.TIMER 0
ENDIF
ENDIF
IF STRMATCH(*WOLF*,<SRC.BASEID>)
IF !<dTAG.<SRC>>
TAG.<SRC> 1
F_WOLVES_PACK 1
//SERV.B @044,,1 <NAME> getting bonus from <SRC.NAME>
TIMERF 5, F_WOLVES_PACK <SRC>
ENDIF
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
ON=@NpcActFight
ARGN2 1000
ON=@ATTACK
IF STRMATCH(*<SRC.BASEID>*,C_RAT,C_A_RAT_SEWER)
SRC.FLEE 10
ENDIF
[ITEMDEF I_WOLF_BERSERKER]
ID I_MEMORY
TYPE T_EQ_SCRIPT
NAME Wolf Berserker
ON=@CREATE
COLOR 026
ON=@TIMER
IF <UID.<TAG0.ATTACK>>
IF <CONT.DISTANCE <TAG0.ATTACK>> > 1
CONT.TAG.OVERRIDE.MOVERATE 10
CONT.TIMERF 2,TAG.OVERRIDE.MOVERATE 50
CONT.GOTO <UID.<TAG0.ATTACK.P>
CONT.ATTACK <TAG0.ATTACK>
TIMER 5
RETURN 1
ENDIF
ENDIF
TIMER 1
RETURN 1
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_RAT]
ON=@NPCLOOKATCHAR
IF !<FINDID.I_RAT_MEM>
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_RAT_MEM
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TIMER 0
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
ON=@NPCActFollow
ARGN1 -1000
ON=@GETHIT
FLEE 10
ON=@HITTRY
FLEE 10
ON=@NPCACTFIGHT
ARGN2 -1000
[ITEMDEF I_RAT_MEM]
ID I_MEMORY
NAME Rat Memory
TYPE T_EQ_SCRIPT
ON=@CREATE
COLOR 044
ON=@TIMER
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_RAT_POOP
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.P <CONT.P>
REF1.TAG.RAT <CONT>
REF1.FIX
TIMER <EVAL {30 60}>
RETURN 1
[ITEMDEF I_RAT_POOP]
ID I_BLOOD_POOL_LARGE
NAME Rat poop
TYPE T_EQ_SCRIPT
ON=@CREATE
COLOR 035
ATTR ATTR_MOVE_NEVER|ATTR_CAN_DECAY
DORAND 5
DISPID 0122a
DISPID 0122b
DISPID 0122c
DISPID 0122d
DISPID 0122e
ENDDO
TIMER <R10,15>
ON=@TIMER
REMOVE
RETURN 1
ON=@STEP
IF <SRC.FLAGS>&STATF_POISONED
RETURN 1
ENDIF
IF STRMATCH(*RAT*,<SRC.BASEID>)
RETURN 1
ENDIF
IF <SRC.ISGM>
RETURN 1
ENDIF
IF <UID.<TAG.RAT>>
// I set poison attacker as the target to avoid the mislinked item when the attacker (rat) die.
// Then I do one damage using the rat uid to create the fight memory.
SRC.SPELLEFFECT S_POISON,500,<SRC.UID>
SRC.DAMAGE 1 01 <TAG.RAT>
ELSE
SRC.POISON 500,<SRC.UID>
ENDIF
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_CAT]
ON=@NPCLOOKATCHAR
IF STRMATCH(*<SRC.BASEID>*,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ATTACK
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
ON=@NPCActFollow
IF STRMATCH(*<SRC.BASEID>*,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ATTACK
ENDIF
ON=@NPCActFight
IF STRMATCH(*<SRC.BASEID>*,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ARGN2 1000
ELIF STRMATCH(*<SRC.BASEID>*,C_DOG,C_WOLF,C_A_WOLF_GRAY,C_A_WOLF_WHITE,C_A_DIREWOLF)
ARGN2 -1000
ENDIF
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_DOG]
ON=@NPCLOOKATCHAR
IF STRMATCH(*<SRC.BASEID>*,C_CAT,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT)
ATTACK
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
ON=@NPCActFollow
IF STRMATCH(*<SRC.BASEID>*,C_CAT,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT)
ATTACK
ENDIF
ON=@NPCActFight
IF STRMATCH(*<SRC.BASEID>*,C_CAT,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_WOLF,C_A_WOLF_GRAY,C_A_WOLF_WHITE,C_A_DIREWOLF)
ARGN2 1000
ENDIF
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_BIRD]
ON=@NPCLOOKATCHAR
IF STRMATCH(*<SRC.BASEID>*,C_SNAKE,C_ICE_SNAKE,C_LAVA_SNAKE)
ATTACK
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
ON=@NPCActFollow
IF STRMATCH(*<SRC.BASEID>*,C_SNAKE,C_ICE_SNAKE,C_LAVA_SNAKE)
ATTACK
ENDIF
ON=@NPCActFight
IF STRMATCH(*<SRC.BASEID>*,C_SNAKE,C_ICE_SNAKE,C_LAVA_SNAKE)
ARGN2 1000
ELSE
ARGN2 -1000
ENDIF
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_SNAKE]
ON=@NPCLOOKATCHAR
IF STRMATCH(*<SRC.BASEID>*,C_BIRD,C_BIRD_CROW,C_BIRD_EAGLE,C_BIRD_MAGPIE,C_BIRD_RAVEN,C_BIRD_TROPICAL,C_BIRD_JUNGLE,C_EAGLE,C_CAT,C_DOG,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ATTACK
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
IF !<FINDID.I_SNAKE_MEM>
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_SNAKE_MEM
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TIMER 0
ENDIF
ON=@NPCActFollow
IF STRMATCH(*<SRC.BASEID>*,C_BIRD,C_BIRD_CROW,C_BIRD_EAGLE,C_BIRD_MAGPIE,C_BIRD_RAVEN,C_BIRD_TROPICAL,C_BIRD_JUNGLE,C_EAGLE,C_CAT,C_DOG,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ATTACK
ENDIF
ON=@NPCActFight
IF STRMATCH(*<SRC.BASEID>*,C_BIRD,C_BIRD_CROW,C_BIRD_EAGLE,C_BIRD_MAGPIE,C_BIRD_RAVEN,C_BIRD_TROPICAL,C_BIRD_JUNGLE,C_EAGLE,C_CAT,C_DOG,C_RAT,C_A_RAT_SEWER,C_RAT_GIANT,C_RABBIT,C_A_JACKRABBIT)
ARGN2 1000
ELSE
ARGN2 -1000
ENDIF
[ITEMDEF I_SNAKE_MEM]
ID I_MEMORY
TYPE T_EQ_SCRIPT
NAME Snake Memory
ON=@CREATE
COLOR 044
ON=@TIMER
IF <dMOREX> <= 0
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_EGGS_FRESH
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.NAME Snake eggs
REF1.TAG.SNAKE <CONT>
REF1.P <CONT.P>
REF1.FIX
REF1.ATTR ATTR_DECAY
REF1.TIMER <EVAL {60 120}>
MOREX <EVAL {180 300}>
ENDIF
CONT.F_SNAKE_EAT_EGGS
MOREX -= 15
TIMER 15
RETURN 1
[FUNCTION F_SNAKE_EAT_EGGS]
REF1 <UID>
FORITEMS 3
IF STRMATCH(*eggs*,<NAME>) && STRMATCH(*I_EGGS_FRESH*,<BASEID>) && !<dTAG.EATEN> && (<DISPID>==I_EGGS_FRESH)
IF <TAG0.SNAKE>
IF <TAG0.SNAKE> != <REF1>
LOCAL.EGGS <UID>
ENDIF
ELSE
LOCAL.EGGS <UID>
ENDIF
ENDIF
ENDFOR
IF <LOCAL.EGGS>
UID.<LOCAL.EGGS>.TAG.EATEN 1
REF1.TIMERF 2,EMOTE eating the eggs
REF1.ANIM 10
REF1.TIMERF 1,ANIM 10
UID.<LOCAL.EGGS>.TIMERF 2,REMOVE
ENDIF
RETURN 1
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_BEAR]
ON=@NPCLOOKATCHAR
IF (<SRC.BRAIN> == BRAIN_ANIMAL) && !(STRMATCH(*BEAR*,<SRC.BASEID>)) && (<STR> > <SRC.STR>)
IF <FINDID.I_BEAR_BERSERKER>
IF !<UID.<FINDID.I_BEAR_BERSERKER.TAG.ATTACK>>
FINDID.I_BEAR_BERSERKER.TAG.ATTACK <SRC>
ENDIF
FINDID.I_BEAR_BERSERKER.TIMER 0
ELSE
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_BEAR_BERSERKER
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TAG.ATTACK <SRC>
REF1.TIMER 0
ENDIF
ENDIF
IF !STRMATCH(*-1,-1*,<HOME>) && <HOME>
IF <DISTANCE <HOME>> > <HOMEDIST>
GOTO <HOME>
ENDIF
ENDIF
IF !<FINDID.I_BEAR_MEM>
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_BEAR_MEM
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TIMER 0
ENDIF
ON=@NPCActFight
ARGN2 1000
[ITEMDEF I_BEAR_MEM]
ID I_MEMORY
TYPE T_EQ_SCRIPT
NAME Bear Memory
ON=@CREATE
COLOR 044
ON=@TIMER
IF <R2> == 1
IF <CONT.ISNEARTYPE.T_WATER 3>
CONT.EMOTE pulling out a fish from water
LOCAL.OLDNEW <NEW>
SERV.NEWITEM { i_fish_raw_whole 1 01e16 1}
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.P <CONT.P>
REF1.FIX
CONT.GOTO <REF1.P>
ENDIF
ENDIF
CONT.F_BEAR_EAT_FISH
TIMER 5
RETURN 1
[FUNCTION F_BEAR_EAT_FISH]
REF1 <UID>
FORITEMS 1
IF STRMATCH(*raw fish*,<NAME>) && !<dTAG.EATEN>
LOCAL.FISH <UID>
ENDIF
ENDFOR
IF <LOCAL.FISH>
UID.<LOCAL.FISH>.TAG.EATEN 1
REF1.TIMERF 2,EMOTE eating the fish and tossing the head
REF1.ANIM 10
REF1.TIMERF 1,ANIM 10
LOCAL.OLDNEW <NEW>
SERV.NEWITEM { 01E19 1 01E1A 1}
REF2 <NEW>
NEW <LOCAL.OLDNEW>
REF2.P 1,1
REF2.ATTR 010
REF2.TIMERF 2,P <UID.<LOCAL.FISH>.P>
REF2.TIMERF 2,FIX
REF2.TIMERF <EVAL {15 30}>,REMOVE
UID.<LOCAL.FISH>.TIMERF 2,FIX
UID.<LOCAL.FISH>.TIMERF 2,REMOVE
ENDIF
RETURN 1
[ITEMDEF I_BEAR_BERSERKER]
ID I_MEMORY
TYPE T_EQ_SCRIPT
NAME Bear Berserker
ON=@CREATE
COLOR 026
ON=@TIMER
IF <UID.<TAG0.ATTACK>>
IF <CONT.DISTANCE <TAG0.ATTACK>> > 1
CONT.TAG.OVERRIDE.MOVERATE 10
CONT.TIMERF 2,TAG.OVERRIDE.MOVERATE 50
CONT.GOTO <UID.<TAG0.ATTACK.P>
CONT.ATTACK <TAG0.ATTACK>
TIMER 5
RETURN 1
ENDIF
ENDIF
TIMER 1
RETURN 1
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EVENTS E_AI_CHICKEN]
ON=@NPCLOOKATCHAR
IF !<FINDID.I_CHICKEN_MEM>
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_CHICKEN_MEM
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.CONT <UID>
REF1.TIMER 0
ENDIF
[ITEMDEF I_CHICKEN_MEM]
ID I_MEMORY
NAME Chicken Memory
TYPE T_EQ_SCRIPT
ON=@CREATE
COLOR 044
ON=@TIMER
LOCAL.OLDNEW <NEW>
SERV.NEWITEM I_EGGS_FRESH
REF1 <NEW>
NEW <LOCAL.OLDNEW>
REF1.NAME Chicken eggs
REF1.TAG.CHICKEN <CONT>
REF1.P <CONT.P>
REF1.FIX
REF1.ATTR ATTR_DECAY
REF1.TIMER <EVAL {60 120}>
TIMER <EVAL {180 300}>
RETURN 1
/////////////////////////////////////////////////////////////////////////////////////////////////////
[TYPEDEF T_FOOD_RAW]
ON=@STEP
IF (<BASEID> == I_EGGS_FRESH) && (<DISPID> != I_EGGSHELLS) && !(STRMATCH(*CHICKEN*,<SRC.BASEID>)) && !(STRMATCH(*SNAKE*,<SRC.BASEID>))
SRC.EMOTE crush <NAME>
NAME eggshells
SOUND 01c3 //skeletal crush sound
DISPID I_EGGSHELLS
UPDATE
ATTR ATTR_DECAY|ATTR_MOVE_NEVER
TIMER <EVAL {30 45}>
ENDIF
/////////////////////////////////////////////////////////////////////////////////////////////////////
[EOF]