Browse Source

Fix crash of spell removal in LUA when zone is not set for caster

Emagi 10 months ago
parent
commit
401ffd3d63
1 changed files with 16 additions and 8 deletions
  1. 16 8
      EQ2/source/WorldServer/LuaFunctions.cpp

+ 16 - 8
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -2454,17 +2454,25 @@ int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
 	LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
 	if (luaspell && luaspell->spell) {
 		ZoneServer* zone = luaspell->caster->GetZone();
+		if(!zone) {
+			zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
+		}
 		Spawn* target = 0;
-		luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
-		for (int32 i = 0; i < luaspell->targets.size(); i++) {
-			target = zone->GetSpawnByID(luaspell->targets[i]);
-			if (target && target->IsEntity()) {
-				((Entity*)target)->RemoveSpellBonus(luaspell);
-				if (target->IsPlayer())
-					((Player*)target)->SetCharSheetChanged(true);
+		if(zone) {
+			luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
+			for (int32 i = 0; i < luaspell->targets.size(); i++) {
+				target = zone->GetSpawnByID(luaspell->targets[i]);
+				if (target && target->IsEntity()) {
+					((Entity*)target)->RemoveSpellBonus(luaspell);
+					if (target->IsPlayer())
+						((Player*)target)->SetCharSheetChanged(true);
+				}
 			}
+			luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
+		}
+		else {
+			LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
 		}
-		luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 	}
 	else if (spawn && spawn->IsEntity()) {
 		((Entity*)spawn)->RemoveSpellBonus(luaspell);