Jump to content

Vehicle destroy


mouadys

Recommended Posts

Posted

Hello , i made a script to spawn vehicle and set player as driver , and it only works if you are admin .

But i want to destroy that vehicle with a command and i dont know how .

function createVehicleForPlayer(thePlayer, command, ...) 
    local x,y,z = getElementPosition(thePlayer) -- get the position of the player 
  x = x + 3 
  local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
  local vehicleName = table.concat({...}, " ") 
  local vehID = getVehicleModelFromName ( vehicleName ) 
  if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
  local createdVehicle = createVehicle( vehID,x,y,z ) 
  warpPedIntoVehicle ( thePlayer, createdVehicle ) 
  setVehicleDamageProof(createdVehicle, true) 
     if (createdVehicle == false) then 
        -- if so, output a message to the chatbox, but only to this player. 
         outputChatBox("Failed to create vehicle.",thePlayer) 
     else outputChatBox("Vehicle has been created",thePlayer) 
 end 
 end 
end 
addCommandHandler("cv", createVehicleForPlayer) 
function destroy(thePlayer, command ) 
  destroyElement ( createdVehicle ) 
end 
addCommandHandler ("dv", destroy) 

Posted

createdVehicle is local, so u cant use it in that second function. You have to declare it outside of any function.

But you should probably store them in a table anyway.

vehicles = {}

vehicles[player] =

Posted
vehicle = {} 
function createVehicleForPlayer(thePlayer, command, ...) 
    local x,y,z = getElementPosition(thePlayer) -- get the position of the player 
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
    local vehicleName = table.concat({...}, " ") 
    local vehID = getVehicleModelFromName ( vehicleName ) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
        vehicle[thePlayer] = createVehicle( vehID,x,y,z ) 
        warpPedIntoVehicle ( thePlayer, vehicle[thePlayer] ) 
        setVehicleDamageProof(vehicle[thePlayer], true) 
        if (vehicle[thePlayer] == false) then 
            -- if so, output a message to the chatbox, but only to this player. 
            outputChatBox("Failed to create vehicle.",thePlayer) 
        else 
            outputChatBox("Vehicle has been created",thePlayer) 
        end 
    end 
end 
addCommandHandler("cv", createVehicleForPlayer) 
  
function destroy(thePlayer, command ) 
  if isElement(vehicle[thePlayer]) then destroyElement ( vehicle[thePlayer] ) end 
end 
addCommandHandler ("dv", destroy) 

Please do not PM me with scripting related question nor support, use the forums instead.

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