Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Spawn Vehicles for Stock PC/CE maps v1.0 for SAPP
- -- by H® Shaft
- -- This script allows players to:
- -- type "V" to spawn the 'default' vehicle, at their location, and put them in the drivers seat, then if abandoned long enough; destroy the vehicle
- -- This script allows server admins to:
- -- specify a default vehicle, per map, via a table of vehicle tag names (see bottom)
- -- enable or disable, per map, player vehicle spawning via a table of map names (see bottom)
- -- set the destruction time before an abandoned player-spawned-vehicle is destroyed (not the same as "despawning")
- -- limit the number of vehicle spawns that each player can spawn per game (too many vehicles can cause lag, and clutter the game)
- -- Reset: admins may type 'vreset' to reset vehicle spawn counts, and player spawn delay times to 0
- -- script will make an entry into sapp log each time a vehicle spawn is called if there is an error, or no default vehicle name supplied
- -- Does NOT affect gametype vehicle respawn times, or gametype spawned vehicles - ONLY player spawned vehicles
- vehicle_limit = 8 -- | Number of times a player can spawn a vehicle during one game (I recommend leaving this # below 10)
- delay_time = 30 -- | Amount of time in seconds a player must wait before (re)spawning vehicles. change to zero/0 to remove delay
- destroy_time = 45 -- | Amount of time in seconds before a spawned hog is destroyed after players leave it, and if it has 'no driver'.
- -- sapp api version
- api_version = "1.8.0.0"
- -- do not edit --
- --game_started = false
- vehicles_spawned = {}
- spawn_delay = {}
- vehicles = {}
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'],"OnNewGame")
- register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
- register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
- register_callback(cb['EVENT_LEAVE'],"OnPlayerLeave")
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- LoadDefaults()
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- map_name = get_var(1,"$map")
- default_vehicle[map_name] = default_vehicle[map_name] or false
- for i = 1,16 do
- if player_present(i) then
- vehicles_spawned[i] = vehicles_spawned[i] or 0
- spawn_delay[i] = delay_time
- end
- end
- end
- end
- function OnScriptUnload()
- vehicles = {}
- vehicles_spawned = {}
- spawn_delay = {}
- default_vehicle = {}
- vehicle_spawn_enabled = {}
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local isadmin = nil
- if (tonumber(get_var(PlayerIndex,"$lvl"))) > 0 then isadmin = true else isadmin = false end
- local name = get_var(PlayerIndex,"$name")
- local Message = string.lower(Message)
- if (Message == "v") or (Message == "/v") then
- response = false
- if player_present(PlayerIndex) then
- if game_started then
- if player_alive(PlayerIndex) then
- if isinvehicle(PlayerIndex) == false then
- if vehicle_spawn_enabled[map_name] then
- if vehicles_spawned[PlayerIndex] < vehicle_limit then
- if spawn_delay[PlayerIndex] == 0 then
- if default_vehicle[map_name] ~= nil then
- local player_object = get_dynamic_player(PlayerIndex)
- local player_static = get_player(PlayerIndex)
- local x,y,z = read_vector3d(player_object + 0x5C)
- local rotation = read_float(player_static + 0x138)
- local veh_name = default_vehicle[map_name]
- local vehicleId = spawn_object("vehi", veh_name, x, y, z+0.5, rotation)
- table.insert(vehicles, {vehicleId, tonumber(destroy_time)})
- local str2 = string.format("**ERROR!** %s does not have a vehicle. Please find & specify the vehicle tag name for this map.", tostring(map_name))
- enter_vehicle(vehicleId, PlayerIndex, 0)
- vehicles_spawned[PlayerIndex] = vehicles_spawned[PlayerIndex] + 1
- say(PlayerIndex, name.. ": You have " .. vehicle_limit - vehicles_spawned[PlayerIndex] .. " vehicle calls remaining.")
- spawn_delay[PlayerIndex] = delay_time
- else
- say(PlayerIndex, "**ERROR** You cannot spawn a vehicle at this time due to an error. ")
- execute_command("log_note \""..str2.."\"")
- end
- else
- say(PlayerIndex, "**DELAY** You must wait " .. spawn_delay[PlayerIndex] .. " seconds before you can spawn a vehicle.")
- end
- else
- say(PlayerIndex, "**LIMIT** You have reached the max amount of vehicle spawns for this game. ")
- end
- else
- say(PlayerIndex, "**DISABLED** That feature is disabled for this map. " )
- end
- else
- say(PlayerIndex, "**DERP!** You already have a vehicle, duh.")
- end
- else
- say(PlayerIndex, "**DERP!** You cannot spawn a vehicle while dead, duh. ")
- end
- else
- say(PlayerIndex, "**DERP!** You cannot spawn a vehicle until the game begins, duh. ")
- end
- end
- end
- -- allows admins to type vreset to reset player vehicle spawn counts and spawn delays to 0
- if (Message == "vreset") then
- response = false
- if isadmin == true then
- LoadDefaults()
- delay_timer = nil
- cont_check = nil
- delay_timer = timer(1000, "DelayVehicleSpawn")
- cont_check = timer(1000, "continuous_vehicle_check")
- for PlayerIndex = 1,16 do
- if player_present(PlayerIndex) then
- vehicles_spawned[PlayerIndex] = 0
- spawn_delay[PlayerIndex] = 0
- end
- end
- end
- end
- return response
- end
- function continuous_vehicle_check()
- if game_started then
- for _,id in pairs(vehicles) do
- local veh_obj = get_object_memory(id[1])
- if (veh_obj ~= 0) then
- local driver = read_dword(veh_obj + 0x324)
- if (driver == 0xFFFFFFFF) and (id[2] <= 0) then
- timer(34, "destroy_vehicle", id[1])
- elseif (driver == 0xFFFFFFFF) and (id[2] > 0) then
- id[2] = id[2] - 1
- elseif (driver ~= 0xFFFFFFFF) then
- id[2] = destroy_time
- end
- end
- end
- end
- return true
- end
- function destroy_vehicle(ObjectID)
- if game_started then
- local veh_obj = get_object_memory(ObjectID)
- if (veh_obj == 0) then return false end
- table.remove(vehicles, ObjectID)
- destroy_object(ObjectID)
- end
- return false
- end
- function OnPlayerJoin(PlayerIndex)
- if player_present(PlayerIndex) then
- vehicles_spawned[PlayerIndex] = vehicles_spawned[PlayerIndex] or 0
- spawn_delay[PlayerIndex] = delay_time
- end
- end
- function DelayVehicleSpawn()
- for i=1,16 do
- if player_present(i) then
- if spawn_delay[i] ~= nil then
- if spawn_delay[i] > 0 then
- spawn_delay[i] = spawn_delay[i] - 1
- elseif spawn_delay[i] <= 0 then
- spawn_delay[i] = 0
- end
- elseif spawn_delay[i] == nil then
- if player_present(i) then
- spawn_delay[i] = delay_time
- end
- end
- end
- end
- return true
- end
- function OnPlayerLeave(PlayerIndex)
- if player_present(PlayerIndex) then
- vehicles_spawned[PlayerIndex] = {}
- spawn_delay[PlayerIndex] = {}
- end
- end
- function OnNewGame()
- LoadDefaults()
- game_started = true
- for i = 1,16 do
- if player_present(i) then
- vehicles_spawned[i] = vehicles_spawned[i] or 0
- spawn_delay[i] = delay_time
- end
- end
- delay_timer = timer(1000, "DelayVehicleSpawn")
- cont_check = timer(1000, "continuous_vehicle_check")
- end
- function OnGameEnd()
- game_started = false
- vehicles = {}
- vehicles_spawned = {}
- spawn_delay = {}
- default_vehicle = {}
- vehicle_spawn_enabled = {}
- end
- function PlayerIsDriver(PlayerIndex)
- if (player_present(PlayerIndex) == false) then return false end
- local player_object = get_dynamic_player(PlayerIndex)
- local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
- local vehicleId = read_dword(player_object + 0x11C)
- if (vehicleId == 0xFFFFFFFF) then return false end
- local obj_id = get_object_memory(vehicleId)
- return read_dword(obj_id + 0x324) == player_object_id
- end
- function GetplayerVehicleId(PlayerIndex)
- if (player_alive(PlayerIndex) == false) then return false end
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- if (vehicleId ~= 0xFFFFFFFF) then return vehicleId else return false end
- end
- function isinvehicle(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- if vehicleId == 0xFFFFFFFF then
- return false
- else
- return true
- end
- end
- function get_tag_info(obj_type, obj_name)
- local tag_id = lookup_tag(obj_type, obj_name)
- return tag_id ~= 0 and read_dword(tag_id + 0xC) or nil
- end
- function LoadDefaults()
- -- stock PC/CE vehicle tag names you can use in the table "default_vehicle" below:
- -- vehicles\\banshee\\banshee_mp
- -- vehicles\\c gun turret\\c gun turret_mp
- -- vehicles\\ghost\\ghost_mp
- -- vehicles\\rwarthog\\rwarthog
- -- vehicles\\scorpion\\scorpion_mp
- -- vehicles\\warthog\\mp_warthog
- -- default vehicle tag names for spawning for each map. Specify the default vehicle your want for each map:
- default_vehicle = {
- ["beavercreek"] = "vehicles\\warthog\\mp_warthog",
- ["bloodgulch"] = "vehicles\\warthog\\mp_warthog",
- ["boardingaction"] = "vehicles\\warthog\\mp_warthog",
- ["carousel"] = "vehicles\\warthog\\mp_warthog",
- ["chillout"] = "vehicles\\warthog\\mp_warthog",
- ["damnation"] = "vehicles\\warthog\\mp_warthog",
- ["dangercanyon"] = "vehicles\\warthog\\mp_warthog",
- ["deathisland"] = "vehicles\\warthog\\mp_warthog",
- ["gephyrophobia"] = "vehicles\\warthog\\mp_warthog",
- ["hangemhigh"] = "vehicles\\warthog\\mp_warthog",
- ["icefields"] = "vehicles\\warthog\\mp_warthog",
- ["infinity"] = "vehicles\\warthog\\mp_warthog",
- ["longest"] = "vehicles\\warthog\\mp_warthog",
- ["prisoner"] = "vehicles\\warthog\\mp_warthog",
- ["putput"] = "vehicles\\warthog\\mp_warthog",
- ["ratrace"] = "vehicles\\warthog\\mp_warthog",
- ["sidewinder"] = "vehicles\\warthog\\mp_warthog",
- ["timberland"] = "vehicles\\warthog\\mp_warthog",
- ["wizard"] = "vehicles\\warthog\\mp_warthog",
- }
- --Enable/disable vehicle spawn: false = disable, true = enable: specify for each map if vehicle spawning is enabled
- vehicle_spawn_enabled = {
- ["beavercreek"] = false,
- ["bloodgulch"] = true,
- ["boardingaction"] = false,
- ["carousel"] = false,
- ["chillout"] = false,
- ["damnation"] = false,
- ["dangercanyon"] = true,
- ["deathisland"] = true,
- ["gephyrophobia"] = true,
- ["hangemhigh"] = false,
- ["icefields"] = true,
- ["infinity"] = true,
- ["longest"] = false,
- ["prisoner"] = false,
- ["putput"] = false,
- ["ratrace"] = false,
- ["sidewinder"] = true,
- ["timberland"] = true,
- ["wizard"] = false,
- }
- map_name = get_var(1,"$map")
- default_vehicle[map_name] = default_vehicle[map_name] or false
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement