Anubhav Posted August 17, 2014 Share Posted August 17, 2014 Hello everyone!, I want to ask that, how to trigger a event only for a player? It should render something only FOR HIM. My server side code: addEventHandler("onPlayerLogin", root, function() triggerClientEvent(source,"createGUI", root) -- will it only trigger for him? D: end ) I'm not showing my full client sided code due to script leakings! My client side code: function startRendering(forWhom) local whoToRender = forWhom or lp addEventHandler("onClientRender", whoToRender, render) end addEvent("createGUI", true) addEventHandler("createGUI", root, startRendering) Link to comment
Arnold-1 Posted August 17, 2014 Share Posted August 17, 2014 it should work, did you test it with multiple people? Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 I'll test it soon with multiple people. I will reply tommorow maybe. Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 Another doubt: function startRendering() guiSetVisible(windowOne, true) end addEvent("createGUI", true) addEventHandler("createGUI", root, startRendering) So will it set the window visible for everyone? Link to comment
DNL291 Posted August 17, 2014 Share Posted August 17, 2014 Depends on who you'll trigger the event. If you call the function startRendering(), it will execute the function for each client. Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 Can you give me a example for only the player who loginned? :-/ Link to comment
DNL291 Posted August 17, 2014 Share Posted August 17, 2014 Actually, your server-side code above is correct, but the another one is wrong. Use this one: function startRendering() addEventHandler("onClientRender", root, render) end addEvent("createGUI", true) addEventHandler("createGUI", root, startRendering) It should work. Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 If I use guiSetVisible instead of addEventHandler( I removed dx functions. ), will it only be for that plr? Link to comment
DNL291 Posted August 17, 2014 Share Posted August 17, 2014 If I use guiSetVisible instead of addEventHandler( I removed dx functions. ), will it only be for that plr? Yes, of course. But like I said, if you call startRendering without calling it for a specific player, the function will be called for all clients. Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 So if I do like this: lp = localPlayer or getLocalPlayer() addEventHandler("onClientPlayerJoin", root, function() startRendering(lp) end ) correct? Link to comment
DNL291 Posted August 17, 2014 Share Posted August 17, 2014 That function will be called for all players except the local player. This event is triggered when a player joins a server. It is triggered for all players except the local player, as the local player joins the server before their client-side resources are started. If that is what you want then it's right. By the way, lp = localPlayer or getLocalPlayer() is useless. Change it to: lp = localPlayer Link to comment
#DRAGON!FIRE Posted August 17, 2014 Share Posted August 17, 2014 You do not have to do anything in Client .. because u sent the trigger For Player and Client just for local player Link to comment
Anubhav Posted August 17, 2014 Author Share Posted August 17, 2014 If I do it like this: SERVER: [lua] addEventHandler("onPlayerJoin", root, function() triggerClientEvent(source, "createGUI", root, source) end ) Link to comment
#DRAGON!FIRE Posted August 17, 2014 Share Posted August 17, 2014 trigger will send just to player because in First arg u put player .. and arg 3 it's the source of event Link to comment
DNL291 Posted August 17, 2014 Share Posted August 17, 2014 If I do it like this:SERVER: addEventHandler("onPlayerJoin", root, function() triggerClientEvent(source, "createGUI", root, source) end ) You can pass the player element as the source of the event instead of an argument. Link to comment
Arnold-1 Posted August 17, 2014 Share Posted August 17, 2014 Do you understand that a client can't affect another client at all? Link to comment
Saml1er Posted August 17, 2014 Share Posted August 17, 2014 (edited) addEventHandler("onPlayerLogin", root, function() triggerClientEvent(source,"createGUI", source) -- due to first argument, this will trigger for 1 player and 3rd argument is for specifying source of the évent end ) local function startRendering () dxDrawText(...) end addEvent("createGUI",true) addEventHandler("createGUI", root, function() addEventHandler("onClientRender", root, startRendering ) end ) EDIT: I changed the event name to "createGUI". I have no idea how I missed this Edited August 18, 2014 by Guest Link to comment
Et-win Posted August 18, 2014 Share Posted August 18, 2014 Stuff. This event is triggered when a player joins a server. It is triggered for all players except the local player As soon as a client joins the server, you just can use 'onClientResourceStart' (Remember to use the resource-root, not root! (Otherwise it will start by every resource that gets started)) or put: functionname() to start the function. Why? Because when she/he joins, the scripts get started. 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