Jump to content

Asking for an explanation


Hero192

Recommended Posts

Can I just know what's the difference between the first example and the second one? I mean if we attached root to the event and if we attached localplayer.

--1st Example:

function targeting ( target ) 
    if ( target ) then 
        --code 
    end 
end 
addEventHandler ( "onClientPlayerTarget", getRootElement(), targeting ) 

--2nd Example:

function targeting ( target ) 
    if ( target ) then 
        --code 
    end 
end 
addEventHandler ( "onClientPlayerTarget", getLocalPlayer(), targeting ) 

Link to comment
This event is triggered whenever the local player targets an element.

Either one will produce the same result. Whenever the local player (meaning client-side, for only that one player) targets, the function tied to that event will be triggered.

onClientPlayer* --> These only work for the local player

onClient* --> These work for any element that is synced client-side (can also be local player, vehicles created server-side etc)

Link to comment

It's what element the event is attached to. So when something happens to that element, the event triggers a function. root would mean whenever something happens to any element (that fits within the scope of the event obviously). localPlayer would attach the event to the local player. So when anything happens to the local player, as long as it's in the scope of the event, it will trigger a function.

When something happens to any element --> Do this (root)

When something happens to the local player --> Do this (local player)

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