Z4Zy Posted August 23, 2018 Share Posted August 23, 2018 So, I just created below code. Client Side Code :- local screenW, screenH = guiGetScreenSize() local marker = createMarker( 0, 0, 2, "cylinder", 2, 255, 255, 0, 255 ) function drawAlert() dxDrawText("You Hit The Marker", (screenW - 340) / 2, (screenH - 53) / 2, ((screenW - 340) / 2) + 340, ( (screenH - 53) / 2) + 53, tocolor(255, 0, 0, 255), 3.00, "default", "left", "top", false, false, false, false, false) dxDrawLine(296, 358, 719, 358, tocolor(32, 222, 55, 255), 1, false) dxDrawLine(296, 411, 719, 411, tocolor(32, 222, 55, 255), 1, false) end function onMarkerHit() addEventHandler("onClientRender", root, drawAlert) end addEventHandler("onClientMarkerHit", marker, onMarkerHit) function onMarkerLeave() removeEventHandler("onClientRender", root, drawAlert) end addEventHandler("onClientMarkerLeave", marker, onMarkerLeave) The problem is that, since onClientRender event use root, when one player hit the marker, alert [ drawAlert function ] will draw on all players' screen ! How to draw that alert [ drawAlert function ] only on marker hit player's screen ?? Link to comment
SycroX Posted August 23, 2018 Share Posted August 23, 2018 function onMarkerHit(hitElement) if hitElement and getElementType(hitElement) == "player" and hitElement == localPlayer then addEventHandler("onClientRender", root, drawAlert) end end addEventHandler("onClientMarkerHit", marker, onMarkerHit) function onMarkerLeave(hitElement) if hitElement == localPlayer then removeEventHandler("onClientRender", root, drawAlert) end end addEventHandler("onClientMarkerLeave", marker, onMarkerLeave) 1 Link to comment
Z4Zy Posted August 23, 2018 Author Share Posted August 23, 2018 9 minutes ago, #َxLysandeR said: function onMarkerHit(hitElement) if hitElement and getElementType(hitElement) == "player" and hitElement == localPlayer then addEventHandler("onClientRender", root, drawAlert) end end addEventHandler("onClientMarkerHit", marker, onMarkerHit) function onMarkerLeave(hitElement) if hitElement == localPlayer then removeEventHandler("onClientRender", root, drawAlert) end end addEventHandler("onClientMarkerLeave", marker, onMarkerLeave) Are you sure that this trick will work ? because if the hitElement was the localPlayer, drawAlert function will render to root element means all players ?!?! Link to comment
SycroX Posted August 23, 2018 Share Posted August 23, 2018 (edited) 7 minutes ago, DeadthStrock said: Are you sure that this trick will work ? because if the hitElement was the localPlayer, drawAlert function will render to root element means all players ?!?! it's not a trick .. + yes iam sure + seems that you didn't understand addEventHandler right so i suggest to read this page one time again https://wiki.multitheftauto.com/wiki/AddEventHandler Edited August 23, 2018 by #َxLysandeR Link to comment
Discord Moderators Pirulax Posted August 23, 2018 Discord Moderators Share Posted August 23, 2018 (edited) Source of 'onClientRender' is client's root element. Edited August 23, 2018 by Pirulax Link to comment
Z4Zy Posted September 19, 2018 Author Share Posted September 19, 2018 On 23/08/2018 at 18:22, #َxLysandeR said: it's not a trick .. + yes iam sure + seems that you didn't understand addEventHandler right so i suggest to read this page one time again https://wiki.multitheftauto.com/wiki/AddEventHandler But where it says that root element of an event can be change Link to comment
MIKI785 Posted September 19, 2018 Share Posted September 19, 2018 On 23/08/2018 at 13:50, DeadthStrock said: Are you sure that this trick will work ? because if the hitElement was the localPlayer, drawAlert function will render to root element means all players ?!?! No it doesn't. It's on the client side, meaning that root is the client's root element. Link to comment
Z4Zy Posted September 19, 2018 Author Share Posted September 19, 2018 49 minutes ago, MIKI785 said: No it doesn't. It's on the client side, meaning that root is the client's root element. And this is also client side :- local screenW, screenH = guiGetScreenSize() local marker = createMarker( 0, 0, 2, "cylinder", 2, 255, 255, 0, 255 ) function drawAlert() dxDrawText("You Hit The Marker", (screenW - 340) / 2, (screenH - 53) / 2, ((screenW - 340) / 2) + 340, ( (screenH - 53) / 2) + 53, tocolor(255, 0, 0, 255), 3.00, "default", "left", "top", false, false, false, false, false) dxDrawLine(296, 358, 719, 358, tocolor(32, 222, 55, 255), 1, false) dxDrawLine(296, 411, 719, 411, tocolor(32, 222, 55, 255), 1, false) end function onMarkerHit() addEventHandler("onClientRender", root, drawAlert) end addEventHandler("onClientMarkerHit", marker, onMarkerHit) function onMarkerLeave() removeEventHandler("onClientRender", root, drawAlert) end addEventHandler("onClientMarkerLeave", marker, onMarkerLeave) Why is client's root element changed in this code that leads render to everyone ? Link to comment
MIKI785 Posted September 19, 2018 Share Posted September 19, 2018 Because onClientMarkerHit is triggered for all players and you're not checking if it's the localPlayer. Link to comment
Z4Zy Posted September 19, 2018 Author Share Posted September 19, 2018 1 hour ago, MIKI785 said: Because onClientMarkerHit is triggered for all players and you're not checking if it's the localPlayer. so .. when checking that the "hitelement" is localplayer, "onClientRender" event gets the root element as localPlayer isn't it ? Link to comment
MIKI785 Posted September 19, 2018 Share Posted September 19, 2018 You still don't get it.. root element never changes. Root is root.. all other elements are underneath this element in the element tree (see here: https://wiki.multitheftauto.com/wiki/Element_tree), hence the name root. What happens here is that onClientMarkerHit gets triggered on all clients, doesn't matter which player hit the marker. If you check if the hitelement is the localPlayer then the onClientRender event will be handled only for the player that hit the marker. 1 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