Jump to content

onClient events


paulocf

Recommended Posts

Let me elaborate better: I have a script that detects if a player has entered a colshape client-side and push him back, there is a protected base inside the colshape so the shape acts as a shield. Then I proceed to outputChatBox("You're being watched!", 255, 0, 0), but this message is sent to everyone in the server as if the detection would count towards people that enters a colshape and is *close* to the localplayer, the message should be sent only to the person who is trying to enter a base, not everyone around (this is why I chose a client-side event, instead of a server-side).

It starts:

addEventHandler("onClientColShapeHit", getRootElement(), 
    function(hitElement, matchingDimension) 

Edited by Guest
Link to comment

That's because onClientColShapeHit is triggered by all elements ( even remote players ), so you must check if the hit element is the local player, like this:

function onColShapeHit ( hitElement ) 
    if ( hitElement == localPlayer ) then 
        -- Your code here 
    end 
end 

Link to comment
That's because onClientColShapeHit is triggered by all elements ( even remote players ), so you must check if the hit element is the local player, like this:
function onColShapeHit ( hitElement ) 
    if ( hitElement == localPlayer ) then 
        -- Your code here 
    end 
end 

It works almost perfectly, but I need to check vehicles being controlled or thrown at the colshape, I really needed to know if the event is triggered for the localPlayer so I'd know if they were in a car, or the vehicle thrown at the base was controlled by them.

If there isn't a way to tell by who the event was started, I might go for your idea... thanks!

Link to comment
You mean that you want to know who's owner is the vehicle that entered on the colshape?

Yes but not only that, I need to detect: local player entering a colshape, vehicle in which localplayer is driving entering a colshape, and a thrown-out car which was thrown by localplayer. If I don't filter for localplayer everything client-side is shared among all logged players, which is not intended.

Edit: Would this work out?

addEventHandler("onClientPlayerDamage", getLocalPlayer(), myFunction) 

getLocalPlayer() instead of getRootElement()? I saw this in a DayZ mode, so I take it works only for that client?

Link to comment
  • Moderators
-- Only check your self. 
 addEventHandler("onClientPlayerDamage", getLocalPlayer(), myFunction)  
 addEventHandler("onClientPlayerDamage", localPlayer, myFunction) -- the same. localPlayer = getLocalPlayer() 
--Yes getLocalPlayer()/localPlayer is only client.  
  
  
-- Check every single player. 
 addEventHandler("onClientPlayerDamage", getRootElement(), myFunction)  
 addEventHandler("onClientPlayerDamage", root, myFunction)  -- the same. root = getRootElement() 

Link to comment
-- Only check your self. 
 addEventHandler("onClientPlayerDamage", getLocalPlayer(), myFunction)  
 addEventHandler("onClientPlayerDamage", localPlayer, myFunction) -- the same. localPlayer = getLocalPlayer() 
--Yes getLocalPlayer()/localPlayer is only client.  
  
  
-- Check every single player. 
 addEventHandler("onClientPlayerDamage", getRootElement(), myFunction)  
 addEventHandler("onClientPlayerDamage", root, myFunction)  -- the same. root = getRootElement() 

Thanks, that settles it.

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