Jump to content

root and localPlayer


Hero192

Recommended Posts

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

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