Jump to content

triggerClientEvent (sendTo Player's Element Table)


'LinKin

Recommended Posts

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
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

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
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
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
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
  • Moderators

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...