Bean666 Posted July 2, 2016 Share Posted July 2, 2016 will this only show the object to the localPlayer? because i don't want any other players to see the object you will spawn. or will i need setElementVisibleTo or nah? any tips? client: function create() if ( source == button ) then if ( getPlayerMoney (localPlayer) <= 4999 ) then return end triggerServerEvent("object", localPlayer) guiSetVisible(classWnd, false) showCursor(false) end end addEventHandler("onClientGUIClick", getRootElement(),create) server: function object() object = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) outputChatBox("created", source) end addEvent("object", true) addEventHandler("object", getRootElement(), object) Link to comment
Anubhav Posted July 2, 2016 Share Posted July 2, 2016 No, you have to trigger it back to client side and like this: triggerClientEvent( source, "someEvent", source ) Link to comment
Bean666 Posted July 2, 2016 Author Share Posted July 2, 2016 can you kindly explain why i'll need to use triggerClientEvent just to make the object show for the localPlayer and others not being able to see it?? so when i use this , it triggers Event for localPlayer right, will the object only show for the localPlayer? i just need yes or no, thanks in advance. i'm just not sure if i triggerServerEvent "object" with localPlayer , other players can see the object that the localplayer created because i'm playing alone, i just need a yes or a no. triggerServerEvent("object", localPlayer) Link to comment
Anubhav Posted July 2, 2016 Share Posted July 2, 2016 can you kindly explain why i'll need to use triggerClientEvent just to make the object show for the localPlayer and others not being able to see it??so when i use this , it triggers Event for localPlayer right, will the object only show for the localPlayer? i just need yes or no, thanks in advance. i'm just not sure if i triggerServerEvent "object" with localPlayer , other players can see the object that the localplayer created because i'm playing alone, i just need a yes or a no. triggerServerEvent("object", localPlayer) You are triggering to server side. Just the source will be the localPlayer in this case because server side does for everyone, it syncs with all players. SO YOU will need to triggerClientSide to make it not sync with the other players, basically then it won't show to others. Link to comment
Tails Posted July 2, 2016 Share Posted July 2, 2016 Hi Shaman123, The object gets created on the server, so it will be visible for everyone. You could use setElementVisibleTo on the server but I've had bad experience with it. I've used it on markers and what I found is that the marker would still be there (onMarkerHit etc.) just not visible. Might be different for objects, or maybe I did something wrong. I can't say for sure. What Anubhav is trying to say is, you can have clients execute commands from the server and use triggerClientEvent( source, "someEvent", source) to trigger a function only for that particular client. You can also use triggerClientEvent to trigger functions on the client for everyone like so: triggerClientEvent("eventName", resourceRoot). This one has no source at the beginning so it gets triggered for every client. Source just stands for the player, it can be any name if you had to define it first. An example: function testFunc(plr,cmd) triggerClientEvent(plr,"myEvent",resourceRoot) end addCommandHandler("trigger",testFunc) Plr could be anything but it's always the player in this particular case (check the wiki for addCommandHandler). Sometimes you don't have to define the player and you can you just use source. On the client you don't have to define it but you can use localPlayer. triggerServerEvent(localPlayer,"myEvent",resourceRoot) is not going to work though. You can't put a player element in front but you can do triggerServerEvent("myEvent",localPlayer). It gets triggered on the server and the player is being sent with it. In the function on the server you can use source as the player. function testFunc(player,cmd) outputChatBox("You're now triggering a client event for everyone",player) triggerClientEvent("myEvent",resourceRoot) end addCommandHandler("trigger",testFunc) Above is self-explanatory Both functions above are server-sided. Keep in mind that you don't always have to trigger everything from the server. You can do a lot via the client alone if it's only meant for the client. To get the player on the client, you can use localPlayer. I'm still learning myself as to what is safe and whether something should be server or client-side and stuff but I know when something is or isn't triggered for a single player. Hopefully this gives you some ideas. Let me know if you have any more questions or if you need someone to test your code. Link to comment
Bean666 Posted July 2, 2016 Author Share Posted July 2, 2016 function object() object = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) outputChatBox("created", source) end addEvent("object", true) addEventHandler("object", getRootElement(), object) so, i'll need to move this in clientside? i kind of get it about the triggerClientEvent, but i don't know what event i am going to trigger from "Client" is it this one? Link to comment
Tails Posted July 2, 2016 Share Posted July 2, 2016 If the objects should only be visible to the localPlayer then yes, you can move the whole function to the client. function create() if ( source == button ) then if ( getPlayerMoney (localPlayer) <= 4999 ) then return end --triggerServerEvent("object", localPlayer) object() guiSetVisible(classWnd, false) showCursor(false) end end addEventHandler("onClientGUIClick", getRootElement(),create) function object() local object = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) outputChatBox("created") end Because you're using onClientGUIClick, any client-side code will only be executed for the client that clicked. Link to comment
Bean666 Posted July 2, 2016 Author Share Posted July 2, 2016 Alright thanks for the help , i get it now! 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