View Full Version : [AI TUT] aggro mobs: changing aggro logic
humordwarf
19.04.2006, 14:38
first lets look on common code for aggro mobs:
class warrior_aggressive_patrol : warrior_patrol
inside SEE_CREATURE handler:
EventHandler SEE_CREATURE(creature, myself) {
if ((GetLifeTime() > 7) && InMyTerritory(myself.sm)) {
AddAttackDesire(creature, 1, 200);
}
}
// 3 functions called (1+2)
we see, mob will attack only if his lifetime>7 (to let player go away after mob respawn), he is in hometerritory (not too far from respawn point) and [s:da6fe7aa15]also attack desire will be adden only if distance_to_creature < 200[/s:da6fe7aa15]
sorry, 200 - is not distance.. its something like probability
easy, we can change 200 to 500 or to 50 to some mobs, just for diversify somehow mobs behaviour
or we can add something like "if Rand(100)<5" so mob will desire attack only 5%
and turn on your lively imagination =)
example 1: what if mob desire attack players with level>40 only?
example 2: what if mob desire attack only if player not have some quest item (OwnItemCount function) hmm.. (almost same as "silence" skill =))?
example 3: what if mob desire attack orcs only ?
etc... etc...
humordwarf
19.04.2006, 16:01
example 1: what if mob desire attack players with level>40 only?
example 2: what if mob desire attack only if player not have some quest item (OwnItemCount function) hmm.. (almost same as "silence" skill =))?
example 3: what if mob desire attack orcs only ?
1.
EventHandler SEE_CREATURE(creature, myself) {
if ((GetLifeTime() > 7) && (creature.level > 40) && InMyTerritory(myself.sm)) {
AddAttackDesire(creature);
}
}
2.
EventHandler SEE_CREATURE(creature, myself) {
if ((GetLifeTime() > 7) && (OwnItemCount(creature, MaigcItemID)!=0) && InMyTerritory(myself.sm)) {
AddAttackDesire(creature);
}
}
3.
EventHandler SEE_CREATURE(creature, myself) {
if ((GetLifeTime() > 7) && (creature.race == OrcRaceID) && InMyTerritory(myself.sm)) {
AddAttackDesire(creature);
}
}
humordwarf
19.04.2006, 16:11
example 4. coward mob (run from high level players) =)
EventHandler SEE_CREATURE(creature, myself) {
if ((creature.level-myself.level)>20)
{
AddFleeDesire(creature, 200);
}
else if ((GetLifeTime() > 7) && InMyTerritory(myself.sm)) {
AddAttackDesire(creature);
}
}
attack desire will be adden only if distance_to_creature < 200
With this can I make a guard kill a player who has become PK in front of him? (Now the guards won't kill him unless he goes away and then come back with karma).
humordwarf
19.04.2006, 18:43
attack desire will be adden only if distance_to_creature < 200
With this can I make a guard kill a player who has become PK in front of him? (Now the guards won't kill him unless he goes away and then come back with karma).
i dont think so...
guard handler is just:
EventHandler SEE_CREATURE(creature) {
if (creature.karma > 0) {
AddAttackDesire(creature, 0, 1500);
}
}
// 1 functions called (1+0)
1. called periodicaly but not frequently (or by some logic) for existing players.
2. called each time when new player appears nearby
3. called ? after EnableMakingSeeEvent() (not tested, if its true - add this using AddTimerEx(), handlers CREATED, TIMER_FIRED using e.g. 30 seconds)
you can also try to use handler from class guard_move_around
EventHandler NO_DESIRE() {
AddMoveAroundDesire(5, 5);
}
only make sure your guard will not go too far from point
or try put there EnableMakingSeeEvent(); instead of around desire...
anyway... more expeiments = better results
Thanks, we'll try this (moving around maybe) and also if there is any fox for veil when you're PK.
Great tutorial. Respect HD ;)
attack desire will be adden only if distance_to_creature < 200
With this can I make a guard kill a player who has become PK in front of him? (Now the guards won't kill him unless he goes away and then come back with karma).
give me an example
toolpunk
19.04.2006, 21:11
he didnt say its possible...
he ASKED IF its possible... ;)
what about time ?
som like spawn mob only on monday? or mog say somthing every hour (for example "2:00 PM ! please take a rest for eat !").
and other thing:
mob teleport/kill/giveitem only 2/3/5 playres choisen by som criteria.
(now i use stupid system when mog when choise player by see_creature(own item) taking damage and when choic another just die and cant choice more >< )
thx forward.
toolpunk
19.04.2006, 22:04
what about time ?
som like spawn mob only on monday? or mog say somthing every hour (for example "2:00 PM ! please take a rest for eat !").
i think timers should be able to handle that...
at least the 2nd thingy when used together with the Say function... (NASC)
Firedaemon
20.04.2006, 06:10
Various time thingies from nasc
EventHandler TIME() {}
Castle_GetRawSystemTime();
EnableTimeEvent(i0);
SayInt(time);
All of which would allow you to manage timed events.
silverdog
20.04.2006, 13:32
Another good job HD, you are sexy <3
humordwarf
20.04.2006, 13:58
also... u can use somthing like below to see when handler works
EventHandler SEE_CREATURE(creature) {
Say(creature.name);
}
Mmm, this is like the printfs for a first debugging, great idea, I'll consider it when I have time to "play" with AI.
Thank you very much master ;)
sorry, 200 - is not distance.. its something like probability
Small correction!
200 it's a desire! :roll:
But you have a nice idea! :wink:
EventHandler SEE_CREATURE(creature) {
if (creature.karma > 0) {
AddAttackDesire(creature, 0, 1500);
}
}
// 1 functions called (1+0)
Look at this
EventHandler SEE_CREATURE(creature) {
if (creature.karma > 0) {
if (creature.karma > 1000) AddAttackDesire(creature, 1, 1500);
else AddAttackDesire(creature, 0, 1500);
}
}
btw
on oficial servers some mobs use only magic. no physical attack.
ive make som changes in warrior_casting_ddmagic and create new class
here is example
EventHandler ATTACKED(attacker, damage)
{
{
if(attacker.is_pc != 0 || IsInCategory(@summon_npc_group, attacker.npc_class_id))
AddUseSkillDesire(attacker, DDMagic, @ST_ATTACK, @AMT_MOVE_TO_TARGET, 1000000);
AddAttackDesire(attacker, @AMT_MOVE_TO_TARGET, (damage/myself.sm.max_hp/0.05) * 100);
}
}
mob strikes back magic attack.
but skills have reload time and when skill is reloading mob hit by physical attack.
ive createt special class and replace all warrior_casting_ddmagic with that. and aggro to.
looks nice.
kitchenknife
05.05.2006, 17:50
if it works it sounds like an awsome idea
NASC seems to be haunted with some kind of evil force that opposes me when I try to do smth with ai :))
I can't understand why when I first compile a txt file with a script, NASC says that there are errors, but when I add a space somewhere in script, compile it, than remove that space - and NASC says "Success!!!".
Moving a "{" symbol to the next line could "fix" a bunch of errors... What the ?.. Is there some kind of "random error generator" built-in in NASC?))
ccline123
19.05.2006, 12:09
handler 5 have problem
because handler 5 is l2NPC offer one touch off event
NPC must update npcinfo all the time
you can made a test
you fist summon a guard_npc
then //setkarma
npc must update npcinfo ,so,npc attack you