Lalalu Posted November 20, 2022 Share Posted November 20, 2022 Hello, I have a problem with this code, this creates a Dx on you that other players can see, it is activated with a trigger from the server-side and a setElementData, but when I use it at the same time as someone else the render gets bug, It says that it was already handled.. local sX, sY = guiGetScreenSize ( ) local onEmoji4 = {}; local plyEmoji4 = getElementsByType ( "player" ) local showEmoji4 = false function onEmoji4Render ( ) local cx, cy, cz = getCameraMatrix () for i = 1, #plyEmoji4 do local p = plyEmoji4[i] if ( onEmoji4[p] ) then local x, y, z = getPedBonePosition.. --- -- blag blah blah local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah if ( dEmoji4 < 100 ) then if ( isLineOfSightClear ( cx, cy... -- blag blah blah if (getElementData (p, "Emoji4") == true) then local sx, sy = getScreenFromWorldPosition...-- blag blah blah if ( sx ) and ( sy ) then local sEmoji4 = 400 / ...-- blag blah blah dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) ) end end end end end end end function attachEmoji4 ( Emoji4 ) if not ( Emoji4 and isElement ( Emoji4 ) ) then return end onEmoji4[Emoji4] = true addEventHandler ( "onClientRender", root, onEmoji4Render ) setTimer(function() removeEventHandler ( "onClientRender", root, onEmoji4Render ) end, 2000, 1) end addEvent( "StartEmoji", true ) addEventHandler( "StartEmoji", root, attachEmoji4 ) Link to comment
alex17" Posted November 21, 2022 Share Posted November 21, 2022 16 hours ago, Lalalu said: Hello, I have a problem with this code, this creates a Dx on you that other players can see, it is activated with a trigger from the server-side and a setElementData, but when I use it at the same time as someone else the render gets bug, It says that it was already handled.. local sX, sY = guiGetScreenSize ( ) local onEmoji4 = {}; local plyEmoji4 = getElementsByType ( "player" ) local showEmoji4 = false function onEmoji4Render ( ) local cx, cy, cz = getCameraMatrix () for i = 1, #plyEmoji4 do local p = plyEmoji4[i] if ( onEmoji4[p] ) then local x, y, z = getPedBonePosition.. --- -- blag blah blah local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah if ( dEmoji4 < 100 ) then if ( isLineOfSightClear ( cx, cy... -- blag blah blah if (getElementData (p, "Emoji4") == true) then local sx, sy = getScreenFromWorldPosition...-- blag blah blah if ( sx ) and ( sy ) then local sEmoji4 = 400 / ...-- blag blah blah dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) ) end end end end end end end function attachEmoji4 ( Emoji4 ) if not ( Emoji4 and isElement ( Emoji4 ) ) then return end onEmoji4[Emoji4] = true addEventHandler ( "onClientRender", root, onEmoji4Render ) setTimer(function() removeEventHandler ( "onClientRender", root, onEmoji4Render ) end, 2000, 1) end addEvent( "StartEmoji", true ) addEventHandler( "StartEmoji", root, attachEmoji4 ) You must be doing the trigger wrong and instead of triggering a single player it triggers the entire server post the trigger part Link to comment
Lalalu Posted November 21, 2022 Author Share Posted November 21, 2022 (edited) 4 hours ago, alex17" said: You must be doing the trigger wrong and instead of triggering a single player it triggers the entire server post the trigger part Hi, this is my trigger: function EMOJI_Z1 () triggerClientEvent("StartEmoji", root, source ) setElementData(source, "Emoji1", true) setTimer(setElementData, 2000, 1, source, "Emoji1", false) end addEvent ( "EMOJI_Z1", true ) addEventHandler ( "EMOJI_Z1", root, EMOJI_Z1 ) Edited November 21, 2022 by Lalalu Link to comment
Shady1 Posted November 21, 2022 Share Posted November 21, 2022 (edited) hello @Lalalu welcome to the forum, I made an edit about this topic, I recommend you to try it. local sX, sY = guiGetScreenSize ( ) local onEmoji4 = {}; local plyEmoji4 = getElementsByType ( "player" ) local showEmoji4 = false local isEventAdded = false function onEmoji4Render ( ) local cx, cy, cz = getCameraMatrix () for i = 1, #plyEmoji4 do local p = plyEmoji4[i] if ( onEmoji4[p] ) then local x, y, z = getPedBonePosition.. --- -- blag blah blah local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah if ( dEmoji4 < 100 ) then if ( isLineOfSightClear ( cx, cy... -- blag blah blah if (getElementData (p, "Emoji4") == true) then local sx, sy = getScreenFromWorldPosition...-- blag blah blah if ( sx ) and ( sy ) then local sEmoji4 = 400 / ...-- blag blah blah dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) ) end end end end end end end function attachEmoji4 ( Emoji4 ) if not ( Emoji4 and isElement ( Emoji4 ) ) then return end if(isEventAdded) then return end -- if event added don't go onEmoji4[Emoji4] = true addEventHandler ( "onClientRender", root, onEmoji4Render ) isEventAdded = true -- mark as added setTimer(function() removeEventHandler ( "onClientRender", root, onEmoji4Render ) isEventAdded = false -- mark as deleted end, 2000, 1) end addEvent( "StartEmoji", true ) addEventHandler( "StartEmoji", root, attachEmoji4 ) local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah and something caught my eye I'm seeing non-Lua codes, can you explain a bit? In addition, the code I sent you above will fix the eventHandler problem. Edited November 21, 2022 by Shady1 1 Link to comment
alex17" Posted November 22, 2022 Share Posted November 22, 2022 7 hours ago, Lalalu said: Hi, this is my trigger: function EMOJI_Z1 () triggerClientEvent("StartEmoji", root, source ) setElementData(source, "Emoji1", true) setTimer(setElementData, 2000, 1, source, "Emoji1", false) end addEvent ( "EMOJI_Z1", true ) addEventHandler ( "EMOJI_Z1", root, EMOJI_Z1 ) There is the problem. use it like this triggerClientEvent( source, "StartEmoji", source ) 1 Link to comment
AngelAlpha Posted November 22, 2022 Share Posted November 22, 2022 try this local sX, sY = guiGetScreenSize ( ) local onEmoji4 = {}; local plyEmoji4 = getElementsByType ( "player" ) local showEmoji4 = false function onEmoji4Render ( ) local cx, cy, cz = getCameraMatrix () for p in pairs (onEmoji4) do if ( isElement(p) ) then local x, y, z = getPedBonePosition.. --- -- blag blah blah local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah if ( dEmoji4 < 100 ) then if ( isLineOfSightClear ( cx, cy... -- blag blah blah if (getElementData (p, "Emoji4") == true) then local sx, sy = getScreenFromWorldPosition...-- blag blah blah if ( sx ) and ( sy ) then local sEmoji4 = 400 / ...-- blag blah blah dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) ) end end end end end end end function attachEmoji4 ( Emoji4 ) if not Emoji4 or not isElement ( Emoji4 ) then return end onEmoji4[Emoji4] = true addEventHandler ( "onClientRender", root, onEmoji4Render ) setTimer(function() removeEventHandler ( "onClientRender", root, onEmoji4Render ) end, 2000, 1) end addEvent( "StartEmoji", true ) addEventHandler( "StartEmoji", root, attachEmoji4 ) 1 Link to comment
Lalalu Posted November 23, 2022 Author Share Posted November 23, 2022 (edited) Thank everyone for the help, It works better now after modifying the trigger and the lines you helped me with Edited November 23, 2022 by Lalalu 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