Limit the number of spawns

init

function vehiclespawn(ply, com, args)
    jeep = ents.Create("prop_vehicle_jeep")
    jeep:SetModel("models/buggy.mdl")
    jeep:SetPos(ply:GetPos()+ply:GetForward()*180)
    jeep:SetAngles(ply:GetAngles())
    jeep:SetNetworkedEntity("owner",ply)
    jeep:SetKeyValue("vehiclescript","scripts/vehicles/jeep_test.txt")
    jeep:Spawn()
    jeep:Activate()
end
concommand.Add("spawnjeep", vehiclespawn)

cl_init

    local DermaButton = vgui.Create( "DButton" )
    DermaButton:SetParent( DermaPanel )
    DermaButton:SetText( "Spawn Car" )
    DermaButton:SetPos( 25, 50 )
    DermaButton:SetSize( 150, 50 )
    DermaButton.DoClick = function ()
        RunConsoleCommand( "spawnjeep" )
    end

Basically I want it only lets you spawn one jeep. I thought about using a variable which it checks if they have a car or not but i couldn’t get this to work. Any help would be appreciated .

[lua]function vehiclespawn(ply, com, args)
if ply.HasJeep then return end – If the player has the HasJeep variable set then deny spawning a jeep.
ply.HasJeep = true – At this point we know the player didn’t have a jeep, so we set HasJeep to true
jeep = ents.Create(“prop_vehicle_jeep”)
jeep:SetModel(“models/buggy.mdl”)
jeep:SetPos(ply:GetPos()+ply:GetForward()*180)
jeep:SetAngles(ply:GetAngles())
jeep:SetNetworkedEntity(“owner”,ply)
jeep:SetKeyValue(“vehiclescript”,“scripts/vehicles/jeep_test.txt”)
jeep:Spawn()
jeep:Activate()
jeep:CallOnRemove(“JeepCount”,function() ply.HasJeep = false end,ply) – When the jeep is removed the player no longuer has a jeep
end
concommand.Add(“spawnjeep”, vehiclespawn)[/lua]

Totally untested but I think this would work.