Browse Source

LUA CheckLOS(spawn,target) and CheckLOSByCoordinates(spawn,x,y,z) returns 1 if in view

Image 4 years ago
parent
commit
ded66a36bf

+ 23 - 0
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -9157,4 +9157,27 @@ int EQ2Emu_lua_ProcHate(lua_State* state) {
 	static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
 	caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
 	return 0;
+}
+
+int EQ2Emu_lua_CheckLOS(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+	Spawn* spawn = lua_interface->GetSpawn(state);
+	Spawn* target = lua_interface->GetSpawn(state, 2);
+	if (spawn && target)
+		return spawn->CheckLoS(target);
+
+	return 0;
+}
+int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+	Spawn* spawn = lua_interface->GetSpawn(state);
+	float x = lua_interface->GetFloatValue(state, 2);
+	float y = lua_interface->GetFloatValue(state, 3);
+	float z = lua_interface->GetFloatValue(state, 4);
+	if (spawn)
+		return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
+
+	return 0;
 }

+ 3 - 0
EQ2/source/WorldServer/LuaFunctions.h

@@ -410,4 +410,7 @@ int EQ2Emu_lua_GetSpellID(lua_State* state);
 int EQ2Emu_lua_StartTransmute(lua_State* state);
 int EQ2Emu_lua_CompleteTransmute(lua_State* state);
 int EQ2Emu_lua_ProcHate(lua_State* state);
+
+int EQ2Emu_lua_CheckLOS(lua_State* state);
+int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state);
 #endif

+ 3 - 0
EQ2/source/WorldServer/LuaInterface.cpp

@@ -1013,6 +1013,9 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
 	lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
 	lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
+
+	lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
+	lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
 }
 
 void LuaInterface::LogError(const char* error, ...)  {