New LUA Function: AddHate
Posted: Thu Dec 11, 2008 4:03 am
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);