Jump to content

onClient events


paulocf

Recommended Posts

Posted

Hi there!

So I have an issue, I want to send a message to local player when something made BY HIM happens, is there a way to know if the event was triggered by the local player rather than a close other player?

Posted

Of which event(s) are you talking about?

You can attach the event just to the local player instead of to root @ addEventHandler.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

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
Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

  • Moderators
Posted
-- 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() 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

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