paulocf Posted May 13, 2013 Share Posted May 13, 2013 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? Link to comment
Castillo Posted May 13, 2013 Share Posted May 13, 2013 Of which event(s) are you talking about? You can attach the event just to the local player instead of to root @ addEventHandler. Link to comment
paulocf Posted May 13, 2013 Author Share Posted May 13, 2013 (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 May 13, 2013 by Guest Link to comment
Castillo Posted May 13, 2013 Share Posted May 13, 2013 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
paulocf Posted May 13, 2013 Author Share Posted May 13, 2013 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
Castillo Posted May 13, 2013 Share Posted May 13, 2013 You mean that you want to know who's owner is the vehicle that entered on the colshape? Link to comment
paulocf Posted May 13, 2013 Author Share Posted May 13, 2013 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 IIYAMA Posted May 14, 2013 Moderators Share Posted May 14, 2013 -- 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
paulocf Posted May 14, 2013 Author Share Posted May 14, 2013 -- 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now