'LinKin Posted May 12, 2014 Share Posted May 12, 2014 Hi, local teamPlayers = getPlayersInTeam(aTeam) triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers , "test") Warning: triggerClientEvent, expected element at argument 3, got table. Isn't it supposed that triggerClientEvent allows this only to players element's table? Thanks. Link to comment
justn Posted May 12, 2014 Share Posted May 12, 2014 Try this. local teamPlayers = getPlayersInTeam(aTeam) for playerKey, playerValue in ipairs ( teamPlayers ) do triggerClientEvent(playerValue , "dxUpdateVsBar", playerValue , "test") end Link to comment
'LinKin Posted May 12, 2014 Author Share Posted May 12, 2014 Of course that works. But shouldn't it work as I was doing it before? I'm passing a player element's table. Link to comment
Dealman Posted May 12, 2014 Share Posted May 12, 2014 I don't think it support tables, but I believe you can use JSON. Link to comment
DakiLLa Posted May 12, 2014 Share Posted May 12, 2014 triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers[ math.random( 1, #teamPlayers ) ], "test") This should work. As wiki says, this function expects "element" type of the 3rd argument. In this line I took random player from a team and sent it as source of the event. Link to comment
cheez3d Posted May 12, 2014 Share Posted May 12, 2014 Or just make the team element the source of the event. Link to comment
'LinKin Posted May 13, 2014 Author Share Posted May 13, 2014 Ahh! So for example, with DakiLLa's code: triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers[ math.random( 1, #teamPlayers ) ], "test") All the players in the team will recieve the data sent by the event, but the source would be only 1 player of that team. Am I right? Link to comment
pa3ck Posted May 13, 2014 Share Posted May 13, 2014 Ahh!So for example, with DakiLLa's code: triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers[ math.random( 1, #teamPlayers ) ], "test") All the players in the team will recieve the data sent by the event, but the source would be only 1 player of that team. Am I right? No, it is going to be sent to a random player from a specific team. You're right, a table should work, if it doesn't, it's an MTA bug. Wiki: If you specify a single player it will just be sent to that player. This argument can also be a table of player elements. Link to comment
Arnold-1 Posted May 13, 2014 Share Posted May 13, 2014 tables only works with events. Link to comment
'LinKin Posted May 14, 2014 Author Share Posted May 14, 2014 Tables only work with events? What do you mean? Aren't I using an event? (triggerClientEvent) Link to comment
DakiLLa Posted May 14, 2014 Share Posted May 14, 2014 Ahh!So for example, with DakiLLa's code: triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers[ math.random( 1, #teamPlayers ) ], "test") All the players in the team will recieve the data sent by the event, but the source would be only 1 player of that team. Am I right? No, it is going to be sent to a random player from a specific team Why? Specifiyng random player as a 'source' (the 3rd argument) of the event doesn't mean it will trigger only for that player, or I'm wrong? Anyway, the suggestion of Cheez3D is the best at the moment, imo. Link to comment
MIKI785 Posted May 14, 2014 Share Posted May 14, 2014 It will get sent to all playera in team, the table is fine.. the only problem is that you use the table as the source as well and you obviously cant do that.. either use the team element or root, whatever suits you. Link to comment
pa3ck Posted May 14, 2014 Share Posted May 14, 2014 Ahh!So for example, with DakiLLa's code: triggerClientEvent(teamPlayers , "dxUpdateVsBar", teamPlayers[ math.random( 1, #teamPlayers ) ], "test") All the players in the team will recieve the data sent by the event, but the source would be only 1 player of that team. Am I right? No, it is going to be sent to a random player from a specific team Why? Specifiyng random player as a 'source' (the 3rd argument) of the event doesn't mean it will trigger only for that player, or I'm wrong? Anyway, the suggestion of Cheez3D is the best at the moment, imo. Oh yea, you're right, I mixed up the two arguments by accident. Link to comment
Arnold-1 Posted May 14, 2014 Share Posted May 14, 2014 Tables only work with events? What do you mean?Aren't I using an event? (triggerClientEvent) i meant only with addEventHandler. Link to comment
Moderators Citizen Posted May 14, 2014 Moderators Share Posted May 14, 2014 So yeah to keep everything clear: You had to give an element that has player elements as children of that element and not a table of player elements. So just give the team element. Here is a useless but working example: local customPlayerRoot = createElement("lol") for k, player in ipairs(getElementsByType("player")) do setElementParent(player, customPlayerRoot) end --output to all players outputChatBox("outputChatBox using customPlayerRoot", customPlayerRoot) Ofc it will works with triggerClientEvent too. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now