Skip to content

Commit

Permalink
FIX _get_player #1
Browse files Browse the repository at this point in the history
  • Loading branch information
SantaSpeen committed Aug 16, 2023
1 parent acb2b45 commit e9815cd
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/modules/PluginsLoader/lua_plugins_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def CancelEventTimer(self, event_name: str):

def TriggerLocalEvent(self, event_name, *args):
self.log.debug("request TriggerLocalEvent()")
self.log.debug(f"Calling local lua event: '{event_name}'")
self.log.debug(f"Calling local lua event: '{event_name} ({args})'")
funcs_data = []
if event_name in self._local_events.keys():
for func_name in self._local_events[event_name]:
Expand Down Expand Up @@ -157,7 +157,7 @@ def TriggerClientEvent(self, player_id, event_name, data):
to_all = False
if player_id < 0:
to_all = True
client = client[0]
client = client[0] if len(client) > 0 else None
if client and event_name and data:
t = self.loop.create_task(client.send_event(event_name, data, to_all=to_all))
self.tasks.append(t)
Expand All @@ -168,7 +168,7 @@ def TriggerClientEvent(self, player_id, event_name, data):
return False, "Can't found event_name or data"

def TriggerClientEventJson(self, player_id, event_name, data):
self.log.debug("request TriggerClientEventJson()")
self.log.debug(f"request TriggerClientEventJson({player_id, event_name, data})")
data = self._lua.globals().Util.JsonEncode(data)
self.TriggerClientEvent(player_id, event_name, data)

Expand Down Expand Up @@ -232,8 +232,9 @@ def GetPlayerVehicles(self, player_id):

def GetPlayers(self):
self.log.debug("request GetPlayers()")
clients = ev.call_event("_get_players", cid=-1)
return self._lua.table_from(clients)
clients = ev.call_event("_get_player", cid=-1)
self.log.debug(f"clients {clients}")
return self._lua.table_from(clients) if len(clients) > 0 else None

def IsPlayerGuest(self, player_id) -> bool:
self.log.debug("request IsPlayerGuest()")
Expand Down Expand Up @@ -312,12 +313,18 @@ def _recursive_dict_encode(self, table):
return {k: v for k, v in new_dict.items() if v is not None}

def JsonEncode(self, table):
self.log.debug("requesting JsonEncode()")
if all(isinstance(k, int) for k in table.keys()):
data = self._recursive_list_encode(table)
else:
data = self._recursive_dict_encode(table)
return json.dumps(data)
data = {}
try:
self.log.debug("requesting JsonEncode()")
if all(isinstance(k, int) for k in table.keys()):
data = self._recursive_list_encode(table)
else:
data = self._recursive_dict_encode(table)
except Exception as e:
self.log.exception(e)
data = json.dumps(data)
self.log.debug(f"Encoded: {data}")
return data

def JsonDecode(self, string):
self.log.debug("requesting JsonDecode()")
Expand Down

0 comments on commit e9815cd

Please sign in to comment.