Jump to content

How to trigger something to a specific client


'LinKin

Recommended Posts

Hello,

I customized a community script which disables the car-smoke.

So, when I type /dissmoke [player] it disables the car-smoke for that player ONLY.

But I'm having one trouble, when I perform that command, it disables the car-smoke of EVERY player.

This is part of the script:

Clientside:

addEvent("sync:forceSmoke", true) 
addEventHandler("sync:forceSmoke",root,toggleSmoke) 

Serverside:

selectedPlayer = getPlayerFromName(theTarget) 
triggerClientEvent("sync:forceSmoke", selectedPlayer) 

I believe it is because of the 'root' in the clientside script; However, I'm not sure...

How can I make it so that it only turns off the car-smoke of the selected player?

Thanks,

- Linkin.

Link to comment

This is first argument (Optional).

sendTo: The event will be sent to all players that are children of the specified element. By default this is the root element, and hence the event is sent to all players. If you specify a single player it will just be sent to that player. This argument can also be a table of player elements.
triggerClientEvent(selectedPlayer, "sync:forceSmoke", selectedPlayer) 

Link to comment
Thanks TALP.

I just found out that in another script I made, I had a similar trouble, so instead of writting 'root' in the clientevent, I wrote getLocalPlayer() and it worked.. What do you say about this getLocalPlayer() ?

This also will work but it's not the right way to do because if you didn't put the first argument of triggerClientEvent it will be by default root which mean it will send packet to every player in the server but the event in the client side will be active only for the source of the trigger event because you attached the event to localPlayer.

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