Jump to content

Why when i click on the PED it output double message


Hero192

Recommended Posts

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) 

Link to comment

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.

Link to comment

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) 
  

Link to comment

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