Hero192 Posted September 4, 2015 Posted September 4, 2015 Why when i click on the ped it output to the chat a double messages not one addEventHandler ( 'onClientClick', root, function ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) and ( getElementType ( clickedElement ) == 'ped' ) then for i=1, #deliverys do if ( clickedElement == deliverys[i] ) then local x, y, z = getElementPosition(localPlayer) if getDistanceBetweenPoints3D(x, y, z, worldX, worldY, worldZ)<=5 then if ( getElementData ( localPlayer, "Job" ) ~= 'Criminal' ) then outputChatBox(" You must be criminal.",255,0,0) return end setElementData(deliverys[i], "del", true) if getElementData(deliverys[i],"del") then if ( guiGetVisible ( Window ) == false ) then guiSetVisible ( Window,true ) end end end end end end end)
TAPL Posted September 4, 2015 Posted September 4, 2015 1- You may have duplicate row in the table 'deliverys'. 2- You may have duplicate code. It is unlikely to be the loop cause as you have used return within the output and this will stop the loop and the function together which means there's duplicated code.
darhal Posted September 4, 2015 Posted September 4, 2015 check the state addEventHandler ( 'onClientClick', root, function ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if state and ( clickedElement ) and ( getElementType ( clickedElement ) == 'ped' ) then for i=1, #deliverys do if ( clickedElement == deliverys[i] ) then local x, y, z = getElementPosition(localPlayer) if getDistanceBetweenPoints3D(x, y, z, worldX, worldY, worldZ)<=5 then if ( getElementData ( localPlayer, "Job" ) ~= 'Criminal' ) then outputChatBox(" You must be criminal.",255,0,0) return end setElementData(deliverys[i], "del", true) if getElementData(deliverys[i],"del") then if ( guiGetVisible ( Window ) == false ) then guiSetVisible ( Window,true ) end end end end end end end)
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