Jump to content

getElementData<


Hazard|

Recommended Posts

Hello, I'm wondering how you use getElementData in this example (below) to disable / enable the blowVehicle, like if you do /speckill then it outputs to the chatbox > Hazard enables spectator kill / Hazard disables spectator kill.

disable = normal (not blowing any vehicles)

enable = blows all the vehicles in the spectatorteam

  
function spectatorkill () 
  local theSpectatorTeam = getTeamFromName("Spectators") 
        if ( theSpectatorTeam ) then 
        local players = getPlayersInTeam ( theSpectatorTeam ) 
        for key, player in ipairs ( players ) do 
            local theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
        blowVehicle(theVehicle,false) 
            end 
        end 
    end 
end) 
addCommandHandler("speckill", spectatorkill) 

Could you do it? I would really appreciate that. Thanks alot

This is what I mean with getElementData

function toggleRespawnModeFunc ( player ) 
        local now = getElementData ( getRootElement ( ), "cwRespawn",  true )  
        if now then 
            state = "disabled" 
        else 
            state = "enabled" 
        end 
        echo ( "*"..getUncolored ( player ).. " has " ..state.." respawn mode" ) 
        setElementData ( getRootElement ( ), "cwRespawn",  not now )  
        setElementData ( resRoot, "respawn", getElementData ( getRootElement ( ), "cwRespawn" )  ) 
    -- end 
end 
addCommandHandler ( "respawn", toggleRespawnModeFunc ) 
setElementData ( resRoot, "respawn", getElementData ( getRootElement ( ), "cwRespawn" ) ) 
  

Link to comment

Code:

function spectatorkill() 
    if (getElementData(getRootElement(),"BlowVehicleEnabled")) then 
      local theSpectatorTeam = getTeamFromName("Spectators") 
            if ( theSpectatorTeam ) then 
            local players = getPlayersInTeam ( theSpectatorTeam ) 
            for key, player in ipairs ( players ) do 
                local theVehicle = getPedOccupiedVehicle ( player ) 
                if ( theVehicle ) then 
                    blowVehicle(theVehicle,false) 
                end 
            end 
        end 
    else 
        outputChatBox("This command is disabled!") 
    end 
end 
addCommandHandler("speckill", spectatorkill) 

By default, it will be disabled. To enable it, use setElementData.

Link to comment

Like this? :arrowdown:

function spectatorkill() 
    if (getElementData(getRootElement(),"BlowVehicleEnabled")) then 
    setElementData ( getRootElement ( ), "BlowVehicleEnabled",  true ) 
      local theSpectatorTeam = getTeamFromName("Spectators") 
            if ( theSpectatorTeam ) then 
            local players = getPlayersInTeam ( theSpectatorTeam ) 
            for key, player in ipairs ( players ) do 
                local theVehicle = getPedOccupiedVehicle ( player ) 
                if ( theVehicle ) then 
                    blowVehicle(theVehicle,false) 
                end 
            end 
        end 
    else 
        outputChatBox("This command is disabled!") 
    end 
end 
addCommandHandler("speckill", spectatorkill) 
  

Link to comment

Well that additional setElementData that you added won't do anything since it already has to be true to even execute that part of the code. Element data is not predefined, think of it like a variable storage for element or object.

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