Hero192 Posted February 27, 2016 Share Posted February 27, 2016 Well, I am asking about these question because I feel kinda confiused of the usage of localPlayer / root in some cases For example: If I create a marker in server side and I did a trigger to client side, on addEventHandler should I use localPlayer or root, because the localPlayer who hit the marker and root who see the marker, or I am wrong? Here's the example code, correct me if I am wrong and tell me why , I really want to learn --Server side function onPlayerMarkerHit(player) if getElementType(player) == "player" then triggerClientEvent(player,"showGUI",player) end end addEventHandler("onMarkerHit", root, onPlayerMarkerHit) --Client Side: addEvent("showGUI",true) addEventHandler("showGUI", localPlayer, -- Just tell me if this line is correct? function() -- code end) Link to comment
Captain Cody Posted February 27, 2016 Share Posted February 27, 2016 addEventHandler("onMarkerHit", resourceRoot, onPlayerMarkerHit) And I belive local player does work for the second one. Link to comment
Hero192 Posted February 27, 2016 Author Share Posted February 27, 2016 why resourceRoot and I see most of scripters using root in this case , can you just explain that please? Link to comment
Captain Cody Posted February 27, 2016 Share Posted February 27, 2016 Root = all scripts ResourceRoot = only that resource Link to comment
DakiLLa Posted February 27, 2016 Share Posted February 27, 2016 why resourceRoot and I see most of scripters using root in this case , can you just explain that please? The second argument of addEventHandler() represents the element you are attaching the event to. Attaching "onMarkerHit" to root means that it will trigger everytime when you hit ANY existing marker on the server; to resourceRoot - will trigger if you hit markers created only by this resource (where this script is located). If you want it to trigger only for a specific marker, then you should pass its element as 2nd argument as well. You should have something like this (I guess): local myMarker = createMarker( ... ) ... function markerHitFunc() -- some code here end addEventHandler( "onMarkerHit", myMarker, markerHitFunc ) Link to comment
Captain Cody Posted February 27, 2016 Share Posted February 27, 2016 Man above me is correct, that's how it's done. 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