Skip to content

Commit f843736

Browse files
committed
Fix #692: Show an error for clientside elements in triggerServerEvent
1 parent 7febd31 commit f843736

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Event.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,46 @@ int CLuaFunctionDefs::TriggerServerEvent(lua_State* luaVM)
215215

216216
if (!argStream.HasErrors())
217217
{
218-
// Trigger it
219-
if (CStaticFunctionDefinitions::TriggerServerEvent(strName, *pCallWithEntity, Arguments))
218+
if (!pCallWithEntity->IsLocalEntity())
220219
{
221-
lua_pushboolean(luaVM, true);
220+
if (CStaticFunctionDefinitions::TriggerServerEvent(strName, *pCallWithEntity, Arguments))
221+
{
222+
lua_pushboolean(luaVM, true);
223+
}
224+
else
225+
{
226+
lua_pushboolean(luaVM, false);
227+
228+
// Show a warning for clientside elements in the argument chain
229+
for (uint i = 0; i < Arguments.Count(); ++i)
230+
{
231+
CLuaArgument* pArgument = Arguments[i];
232+
233+
if (!pArgument)
234+
continue;
235+
236+
if (pArgument->GetType() != LUA_TLIGHTUSERDATA && pArgument->GetType() != LUA_TUSERDATA)
237+
continue;
238+
239+
CClientEntity* pEntity = pArgument->GetElement();
240+
241+
if (!pEntity || !pEntity->IsLocalEntity())
242+
continue;
243+
244+
// Extra arguments begin at argument 3
245+
m_pScriptDebugging->LogError(luaVM, "clientside element '%s' at argument %u @ 'triggerServerEvent'", pEntity->GetTypeName().c_str(), i + 3);
246+
}
247+
}
248+
222249
return 1;
223250
}
251+
252+
argStream.SetCustomError("element is clientside", "Bad source element");
224253
}
225-
else
254+
255+
if (argStream.HasErrors())
226256
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
227257

228-
// Failed
229258
lua_pushboolean(luaVM, false);
230259
return 1;
231260
}

0 commit comments

Comments
 (0)