Game Development Community

Aggro system

by Christian · in Torque Game Engine · 02/22/2007 (11:09 am) · 7 replies

Yo, I am attempting an aggro/hate system for mobs. I think the place to do that is in player.cs in ::onDamage

I could use a little help in basically seeing who has the most damage to a particular mob.

function Armor::onDamage(%this, %obj, %delta)
{
$this1 = %this;
$obj1 = %obj;

$obj1.aggro[$this];
$aggro1 = %obj.damage[combat];

I know that the code above would be incorrect, but something along those lines i'd assume would be the way to go. Any help is appreciated.

#1
02/22/2007 (11:15 am)
In the MMOKIT, we handled this by maintaining an attacker list on the mob, along with damages (using the onDamage routine) and when it had a chance to attack, it would run through the attacker list and choose the highest damager. So you may be off to a good start.
#2
02/22/2007 (11:49 am)
Hmm. Dave. What about taking healing into consideration and taunting related abilities? I think those would make fantastic additions to the kit.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#3
02/22/2007 (12:11 pm)
@Jonathon

Agreed. I used some simple rules and did this is a similar way in ondamage by keeping an array containing direct damage and hate.

Hate amounts at 2 point for each direct damage point incurred, at 1 point for each health point regenerated ( whether by magic or potion) and at 1 point for each point of taunt added during combat in real time.

Damage is limited to direct damage only.

Rewards in the form of loot are provided and locked to the person causing direct damage first unless that person only applied one direct hit during combat or did less than 5% total. (Trying to stop the hit then run tactic).

This makes the monster target the most hated independant of damage caused and makes healers think about the way they operate. In the early stages of a fight, a heal over time is much safer than a direct heal for hate control.

I also have certain mobs linked in groups so hate becomes very important in that while fighting one mob, it's partner will react only to hate, often the healer :)

Regards

Graham
#4
02/22/2007 (1:12 pm)
@Graham Hey man! How's the game comin!? You drop out of sight for too long at a time ;).

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#5
02/25/2007 (9:59 am)
In ::onDamage, how do you determine who did the damaging, or is this something that every spell had to do individually?
#6
02/25/2007 (11:22 am)
Hi Christian...

in armor::Damage... not ondamage I use this function to determine who did damage...

switch$ (%sourceObject.getClassName())
	 {
     case "afxMagicSpell":
		%caster = %sourceObject.getCaster();
     case "afxProjectile":
		%caster = %sourceObject.afxOwner.getCaster();
     case "Player":
		%caster = %sourceObject;
	 }

     %name = %caster.getShapeName();

This gives me the the id as %caster based on the type of damage.. spell projectile or melee and if required the name of that character in %name.

Jeff provided this code for me when I had a similar problem.. Thanks Jeff.

Hopefully it will work for you as is, but at least may give you some pointers based on your own development requirements.

What we are doing is finding out who caused the damage based in the damage type which is not known when the damage is caused, but what is known is who the caster of a spell or a projectile was, so thats why we use the fields from the object causing the damage to work backwards to get the "caster".

it will thow a console error if the ai player kills itself as I haven't bothered to put in a case for AIplayer as the source of damage, but nothing to worry about, it wont cause a crash :)


Hope this helps..

Regards

Graham
#7
02/25/2007 (1:05 pm)
Yes Graham, just what I needed. Thanks.