Jump to content

triggerClientEvent (sendTo Player's Element Table)


'LinKin

Recommended Posts

Posted

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.

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

Try this.

local teamPlayers = getPlayersInTeam(aTeam) 
for playerKey, playerValue in ipairs ( teamPlayers ) do 
triggerClientEvent(playerValue , "dxUpdateVsBar", playerValue , "test") 
end 

Datastore - Store data to a database quickly. (Useful for saving scripted tables)

Posted

Of course that works. But shouldn't it work as I was doing it before?

I'm passing a player element's table.

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

I don't think it support tables, but I believe you can use JSON.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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

Posted

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?

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

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

Posted

tables only works with events.

Ingame Name: Arnold

If you need my help, contact me on Skype @bshr.ara

NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP

Posted

Tables only work with events? What do you mean?

Aren't I using an event? (triggerClientEvent)

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

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

Posted

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.

Lua Scripter

?ucet=miki_cz

Owner of mshost.cz MTA portal.

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

Posted
Tables only work with events? What do you mean?

Aren't I using an event? (triggerClientEvent)

i meant only with addEventHandler.

Ingame Name: Arnold

If you need my help, contact me on Skype @bshr.ara

NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP

  • Moderators
Posted

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.

The rEvolution is coming ...

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