Jump to content

addEventHandler()


Nonameman

Recommended Posts

Hey All!

I'm a newbie, so sorry if I ask stupid things.

In the addEventHandler() command, I don't know what should be the second parameter.

I use the wiki to get help, but there's a lot of variations to this params, GetRootElement()/GetLocalPlayer(),

What to use in different situations? What is it for?

Thanks

Nonameman

Link to comment
Hey All!

I'm a newbie, so sorry if I ask stupid things.

In the addEventHandler() command, I don't know what should be the second parameter.

I use the wiki to get help, but there's a lot of variations to this params, GetRootElement()/GetLocalPlayer(),

What to use in different situations? What is it for?

Thanks

Nonameman

seriusly, i don't know i ever use getRootElement()

Link to comment

client-side scripts are running INDEPENDLY on each client (player) - outputChatBox will output chat to that player who is running that scripts.

like (in words) - you are checking for current vehicle speed every second, and if its > 50, you are outputting text - its doing (independly) the same thing on every client, but only client driving faster than 50 will see message.

addEventHandler - 2nd parameter is attached element.

every event is triggered by something (this is called "source" in handler function).

if you are making onMarkerHit - attached element could be one marker, or all markers, example:

  
myMarker = createMarker(arguments, we, dont, care, in_, this, example) 
otherMarker = createMarker(arguments, we, dont, care, in_, this, example) 
  
function myMarkerHandler(element, matchingDimensions) 
  outputChatBox("something hit my marker") 
end 
function anyMarkerHandler(element, matchingDimensions) 
  outputChatBox("something hit some marker, it can be ANY marker") 
  if (source==myMarker) then 
    outputChatBox("oh, and it was MY marker") 
  end 
end 
  
addEventHandler("onMarkerHit", myMarker, myMarkerHandler) 
addEventHandler("onMarkerHit", getRootElement(), anyMarkerHandler) 
  

see the difference? try it out :)

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