[LUA] Как заспавнить машину

local spawnPos = Vector(1017.008667, 3560.307617, -131.968750)
local vehicleModel = "prop_vehicle_jeep"

local function spawnVehicle(pl)
	if (pl.vehicles_spawned or 0) >= 1 then
		pl:ChatPrint("Вы заспавнили " .. pl.vehicles_spawned .. " машин(у) и достигли лимита")
		return
	end

	local veh = ents.Create(vehicleModel)
	veh:SetPos(spawnPos)
	veh:SetKeyValue("vehiclescript" ,"path_to_script.txt")
	veh:Spawn()
	veh:Activate()
	veh:SetModel("models/models/dreams/peugeotp4.mdl")

	pl.vehicles_spawned = (pl.vehicles_spawned or 0) + 1

	veh:CallOnRemove("ChangeSpawnedCounter", function(ent)
		if not IsValid(pl) then return end
		pl.vehicles_spawned = pl.vehicles_spawned - 1
	end)

	pl:EnterVehicle(veh)
end

concommand.Add("spawn_vehicle", spawnVehicle)
1 лайк