Jump to content

[HELP] ElementData and destroyElement


Hell-Mate

Recommended Posts

Hello community ,,

i've scripted a simple code to destroy elements when not in the job. so i used getElementData and if not this data then destroy this element but there is an error saying : bad argument @destroyElements and sometime it says bad argument @getElementData ( argument 3 ) got string "seadelivery" .. here is the code and i hope someone can help. Thanks

addEventHandler ( "onClientRender", getRootElement(), 
    function( ) 
    local notdutyplayers = getElementsByType("player") 
    if (#notdutyplayers > 0) then 
    for k,player in ipairs(notdutyplayers) do 
    local pData = getElementData ( player, 'job', "seadelivery" ) 
    if not pData then  
    triggerEvent ( "destroyonleave", localPlayer ) 
    end 
    end 
    end 
    end) 

and here is the destroyonleave event >>

addEvent ( "destroyonleave", true ) 
function destroyonleave () 
destroyElement ( deliveryMarker ) 
destroyElement ( deliveryBlip ) 
end 
addEventHandler ( "destroyonleave", getRootElement (), destroyonleave ) 

Regards ,,

Link to comment
addEventHandler ( "onClientRender", getRootElement(), 
function( ) 
local notdutyplayers = getElementsByType("player") 
    if (#notdutyplayers > 0) then 
        for k,player in ipairs(notdutyplayers) do 
            local pData = getElementData ( player, 'job' ) 
            if not (pData == "seadelivery") then 
                triggerEvent ( "destroyonleave", localPlayer ) 
            end 
        end 
    end 
end) 

And where is deliveryMarker and deliveryBlip defined?

Link to comment
function pCountC() 
    local theTable = { } 
    local players = getElementsByType("player") 
  
    for i,v in pairs(players) do 
        theTable[#theTable+1]=v 
      end 
    return theTable 
end 
  
    function test1( ) 
local Tplayers = tonumber ( pCountC() ) or 0 
    if Tplayers > 0 then 
    for _, v in ipairs(getElementsByType("player") do 
    local pData = getElementData ( v, "job")    
    if not pData ==  "seadelivery" then  
    triggerEvent ( "destroyonleave", localPlayer ) 
removeEventHandler ( "onClientRender", root, test1 ) 
    end 
    end 
    end 
    end  
addEventHandler ("onClientResourceStart", resourceRoot,  
function () 
addEventHandler ( "onClientRender", root, test1 ) 
end )  

EDIT: Just saw DNL's post btw don't you think a timer would be more good instead calling the function every second or more?

Link to comment
EDIT: Just saw DNL's post btw don't you think a timer would be more good instead calling the function every second or more?

Yes, loop through all players on every render really isn't good.

But, he could verify if the player job matches with "seadelivery" when the player hits the marker, or create that marker only for players with the element data corresponding with "seadelivery" when resource starts. And create that marker for the player who join this job.

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