Page 1 of 2

New LUA Function: AddHate

Posted: Thu Dec 11, 2008 4:03 am
by Scatman
We needed a function to add hate from LUA for the taunt spells so I took a stab at it. Everything worked originally but we noticed that it put you in combat. On live, if you taunt something, and you're not already in combat, you stay out of combat but the taunt still applies (as long as it's only a taunt with no other effects). Let me know if this is the best way to do it, or if there's an easier way.

Code: Select all

Index: Combat.cpp
===================================================================
--- Combat.cpp	(revision 175)
+++ Combat.cpp	(working copy)
@@ -563,4 +563,8 @@
 		MLooters.unlock();
 	}
 	return ret;
-}
\ No newline at end of file
+}
+
+NPC_AI* Combat::GetNPCAI() {
+	return &npc_ai;
+}
Index: Combat.h
===================================================================
--- Combat.h	(revision 175)
+++ Combat.h	(working copy)
@@ -46,6 +46,7 @@
 	bool CheckLootAllowed(Entity* dead, Entity* spawn);
 	bool AttackAllowed(Entity* attacker, Spawn* victim, bool calculate_distance = true);
 	void ClearCombat();
+	NPC_AI* GetNPCAI();
 
 protected:
 	void ProcessAttack(Entity* attacker, Spawn* victim, int8 damage_type, bool primary_weapon = true);
Index: LuaFunctions.cpp
===================================================================
--- LuaFunctions.cpp	(revision 175)
+++ LuaFunctions.cpp	(working copy)
@@ -553,6 +553,22 @@
 	return 0;
 }
 
+int EQ2Emu_lua_AddHate(lua_State* state) {
+	Entity* player = (Entity*)(lua_interface->GetSpawn(state));
+	Spawn* npc = (NPC*)(lua_interface->GetSpawn(state, 2));
+	int16 amount = lua_interface->GetInt16Value(state, 3);
+
+	Combat* combat = player->GetZone()->GetCombat();
+	NPC_AI* npc_ai = combat->GetNPCAI();
+
+	combat->Attack(player, npc, 1);
+	player->InCombat(false);
+
+	npc_ai->AddHate((NPC*)npc, player, amount);
+
+	return 0;
+}
+
 int EQ2Emu_lua_AddSpawnAccess(lua_State* state){
 	Spawn* spawn = lua_interface->GetSpawn(state);
 	Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
Index: LuaFunctions.h
===================================================================
--- LuaFunctions.h	(revision 175)
+++ LuaFunctions.h	(working copy)
@@ -104,6 +104,7 @@
 int EQ2Emu_lua_AddConversationOption(lua_State* state);
 int EQ2Emu_lua_StartConversation(lua_State* state);
 int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state);
+int EQ2Emu_lua_AddHate(lua_State* state);
 
 //Quest Stuff
 int EQ2Emu_lua_SetStepComplete(lua_State* state);
Index: LuaInterface.cpp
===================================================================
--- LuaInterface.cpp	(revision 175)
+++ LuaInterface.cpp	(working copy)
@@ -404,6 +404,7 @@
 	lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
 	lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
 	lua_register(state, "Zone", EQ2Emu_lua_Zone);
+	lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
 	
 	lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
 	lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);

Posted: Thu Dec 11, 2008 6:08 pm
by LethalEncounter
OK, I added your function but I rewrote it a bit. I created a new method in Combat called AddHate(NPC* victim, Entity* attacker, sint32 amount). I also did some checks on the types before you cast them to Entity or NPC to ensure that if you got the parameters wrong it didnt crash the server.
This does what your previous one did but shouldn't put the player in combat. In addition I changed the hate variables to be unsigned, which means you can call the AddHate LUA function with a negative number to reduce the hate as well. I figured you would need that soon for hate reducing spells :P

Posted: Thu Dec 11, 2008 6:31 pm
by Scatman
LethalEncounter wrote:In addition I changed the hate variables to be unsigned, which means you can call the AddHate LUA function with a negative number to reduce the hate as well. I figured you would need that soon for hate reducing spells :P
Wow, I totally forgot about those. Nice thinkin, thanks :)

Posted: Thu Dec 11, 2008 10:33 pm
by John Adams
This is why he gets paid the big bucks.
Oh wait... nm.
Awesome work, Scatman. Keep the goodies coming!

Posted: Sun Dec 14, 2008 12:17 pm
by alfa
And what about aggro positions and aggro stuck ?
Exemple
Rescue increase hate amount and give you 3 position (so if you are 5th in aggro list it switch you at 2nd position)
And there is some spell prevent target to change cible for a time like (in french) Peler for monk

Posted: Sun Dec 14, 2008 2:55 pm
by Scatman
Ya I forgot about rescue. That's a good point thanks. For aggro stuck, I believe you are referring to something like Monk's Peel spells which guarantees you aggro for a bit?

Posted: Sun Dec 14, 2008 3:12 pm
by alfa
Yep and Guardians/Zerkers have a similar spell with TSO AA (Warrior's Cry :: Prevent target for switch cible for 8 sec).
And aggro position are used for some other spell in TSO AA and for the Guardians 's renforcement (DoF lvl 52) and maybe some other spells.
But I stell can't determine how they do for calculate aggro with amount / posiions.

Posted: Sun Dec 14, 2008 3:51 pm
by John Adams
Scatman and I had a long debate about aggro while working through the AddHate() LUA function. He told me that aggro in EQ2 was as simple as, you do 10 pts of damage, you gain 10 pts of Hate. My personal experience with hate lists come from EQ1, which as far as I understood were way more complex than simple 1:1 damage:hate.
Now I am hearing talk of positions on lists. So now you can explain to me, if a Guardian does 10,000 damage and has 10,000 hate - and suddenly a Monk comes along and "peels" the mob off for a duration - how does the Monk shoot up to 10,001 hate for 'x' seconds, then drop back down to whatever hate he had before, thus returning the aggro to the Guardian?
I still think Hate calcs are a little more complex than 1:1, but I am not the expert in this area so I will go with whatever you guys tell me. :)

Posted: Sun Dec 14, 2008 3:58 pm
by Scatman
It was actually posted by a developer about the 1:1 ratios. It was a while ago but I haven't heard about anything changing. It wouldn't be hard to calculate the amount of hate the player has 3 index positions away and just increase the caster's hate by that much + some extra.

Posted: Sun Dec 14, 2008 4:15 pm
by Bion
hate is based 1 point of dmg = 1 point of hate..heals are a little less i think / 5 i am not 100% on that i vaugely remember a dev post about this but it is a good bit less. for every tick in the fight you lose hate
now that is just basic hate then you have to factor in all the taunts and other aggro spell/skills for instance monks have a hate buff everytime it procs it adds a little bit to his hate add that with the dmg he is doing it is really easy to pull a single target off anyone as a monk. with aa's monks also have a skill that is opposite of that instead of increasing hate it decreases it and one that will turn there avoidance buff into a hate transfer
just about every class that is consider a "dps" class has some form of hate decrease to help them do more dmg in form of spells/skills with scouts they have ignorant bliss it is a poison that decreases aggro when it procs. also they have other skills like evade and surveillance and hate transfers that helps them dump aggro. there is alot more and a bit different for each class but works basically the same.

Posted: Sun Dec 14, 2008 4:27 pm
by John Adams
John Adams wrote:I still think Hate calcs are a little more complex than 1:1, but I am not the expert in this area so I will go with whatever you guys tell me. :)
By this, I certainly do not mean Scatman is incorrect. Just call me a pessimist; that somewhere down the line, someone is going to drop the proverbial anvil on me and say "Oh those 10,000 spells you set up? Yeah, Hate doesn't work that way". Mark my word, it's gonna happen. :)

Posted: Sun Dec 14, 2008 4:39 pm
by LethalEncounter
You aren't calling AddHate for every damage spell are you? This should only be used for the Hate specific spells.

Posted: Sun Dec 14, 2008 4:39 pm
by Scatman
Well I just checked the EQ2 forums to try and find that dev post but I couldn't find it. I read other people's posts about it and it seems pretty 50/50. Everyone agrees on the 1:1 damage:hate ratio. But half seem to think that the heal:hate ratio is less and half seem to think the heal:hate ratio is 1:1. From my own experience being raiding guild, it seems heals and wards are a 1:1 ratio. Pre-heals in a raid are ALWAYS a no-no when a tank cannot start pulls with attacks or taunts because the raid will wipe due to the healer pre-warding and pre-healing and causing so much aggro the tanks cannot get it back. So I'm going to keep searching so we can get a deffinite answer on the heals and wards, since everyone seems to agree with the damage:hate ratio.

Posted: Sun Dec 14, 2008 4:40 pm
by Scatman
No LE we're not, I remember seeing you took care of that already in the code.

Posted: Sun Dec 14, 2008 4:42 pm
by Bion
from eq2forums this is a copy paste of a players post that had copied the dev lockeye post

1) How much damage is equal to one point of hate gain (if there is a direct relation at all)?
1 hate point = 1 damage point
2) Why does spike damage to a mob seem to draw more aggro than damage over time?
(Does damage have some type of exponential function associated with it? i.e. If I hit a mob for 500 dmg 2x or hit a mob for 1000 dmg 1x, do they generate the same hate on the mob? Or just for the sake of throwing a number in there, does each hit get an exponential multiplier like 500^2 [(dmg)^(multiplier)] or 1000^2? If this were the case, I would be generating 500k hate from the 2 hits of 500 but 1000k hate from 1 hit of 1000.)
The same amount of hate is generated when the damage is dealt. 1:1
3) Does hate decrease over time, and if so at what rate? This would be another reason for spike damage to pull more aggro than damage over time. If player A does 5 hits of 200 dmg over the course of 10 seconds, and player B does 1000 damage all at second 10 in the fight, player B then has the hate from all 1k dmg while the mob thinks that player A has only done maybe 800. (Just throwing out some numbers.)
Hate naturally decays very slowly, but it can never naturally reach zero alone.
4) How much hate is generated by someone's pet dying? Does the hate which was previously on the pet get directly transferred to the owner?
A pet's death causes the hate they generated to be applied towards the caster.
5) Do taunts generate more hate when a mob is debuffed by a Dispatch or another spell of a similar nature? I assume this to be true, but it's hard to tell with no hard numbers to see how much a person is actually taunting. If this is the case, would it be too much to ask to have my actual taunt numbers displayed?
Taunt amounts are not affected by resists, but lowering resists can help a Taunt from being outright resisted.
6) At what rate does hate decrease? I would assume this would have to be a function of the players level. i.e. Hate is decreased at something like (time * level). So after 10 seconds a level 1 character would have 10 hate decreased, a level 50 would have 500 decreased, and a level 70 would have 700 decreased. (Also I would assume some multiplier in there like (time * level * constant) as 10 hate, 500 hate, and 700 hate reduced for the respective levels in 10 seconds is basically nothing.)
I would have to double check on this one, but natural hate decay is a slow process.
7) How much hate does healing / being healed generate? (This includes wards.) Does healing/warding give a 1 to 1 threat output? When I am healed/warded do I gain some amount of hate from this act, and how much do I gain?
Heals/Wards have less than a 1:1 threat return.
SMILEY How much hate do debuffs accrue, if any? The best example I can think of is a Brigand's Dispatch. It seems that this spell generates far more hate than just what the damage component reads. This would also include stuns/stifles. It seems that brawlers do a lot of this and seem to pull more aggro than someone else doing the exact same amount of damge. This leads me to believe that extra hate is generated when a mob is stunned/stifled or even if the spell attempts to stun/stifle the mob and doesn't.

Each debuff spell generally causes the same amount of hate appropriate for their level, as do control abilities have amounts of hate that they each generate for their level. Dispatch itself is not the primary cause of grabbing hate, rather it is how a Brigand often combines it with Subdue and Double Up (Subdue having both high damage and a control component hate, and Dispatch having high damage and debuff hate).


from Lockeye's post that will get lost one day, wanted to copy here and please sticky for next generations:
http://eqiiforums.station.sony.com/eq2/ ... 8078#M8078