Jump to content

Limit Car Spawn Help


UsErFaiLed

Recommended Posts

Hello, Guys wanted someone to help me up next I want when I create a car like the script below can only spawn one car at a time type spawns 1 Car

then it is creating another what he is destroyed before cryo Help me Please

Google translate

function car ( thePlayer, command ) 
      local x, y, z = getElementPosition ( thePlayer ) 
      createVehicle ( 432, x, y, z + 10 )  
end 
addCommandHandler ( "createtank", car ) 

Link to comment

Use a flag that equals 0, and changes to 1 if createVehicle == true

function car ( thePlayer, command ) 
     if flag == 1 then return end 
          local flag = 0 
          local x, y, z = getElementPosition ( thePlayer ) 
          local flag_bool = createVehicle ( 432, x, y, z + 10 ) 
          if flag_bool == true then  
               flag = 1 
          end 
end 
addCommandHandler ( "createtank", car ) 

Link to comment
Use a flag that equals 0, and changes to 1 if createVehicle == true
function car ( thePlayer, command ) 
     if flag == 1 then return end 
          local flag = 0 
          local x, y, z = getElementPosition ( thePlayer ) 
          local flag_bool = createVehicle ( 432, x, y, z + 10 ) 
          if flag_bool == true then  
               flag = 1 
          end 
end 
addCommandHandler ( "createtank", car ) 

Thanks

Link to comment

But if there's many players on the server this dont work, I recommend this :

local veh = {} 
  
function car(player, command, arg1) 
    local x, y, z = getElementPosition(player) 
    if veh[player] then 
        destroyElement(veh[player]) 
    end 
    veh[player] = createVehicle(432, x, y, z) 
    if arg1 == "in" then 
        warpPedIntoVehicle(player, veh[player]) 
    end 
end 
addCommandHandler("createtank", car) 
  

And if you type "/createtank in" you are warped into the tank.

Edited by Guest
Link to comment
But if there's many players on the server this dont work, I recommend this :
local veh = {} 
  
function car(player, command, arg1) 
    local x, y, z = getElementPosition(player) 
    if veh[player] then 
        destroyElement(veh[player]) 
    end 
    veh[player] = createVehicle(432, x, y, z) 
    if arg1 == "in" then 
        warpPedIntoVehicle(player, veh[player]) 
    end 
end 
addCommandHandler("ct", car) 
  

And if you type "/createtank in" you are warped into the tank.

Thank you so much better :D

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