Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Race Seating for SAPP (compatible with ALL game types and bungholes)
- -- If player enters a vehicle gunner seat with no driver they are moved to the driver seat and notified
- -- If driver dies, any gunner/passenger is automatically ejected after EJECT_TIME expires - see EJECT_TIME below
- -- Designed specifically to accomodate race AND mixed gametype PREFERENCES:
- -- On-Entry seating priority: driver, then gunner, then passenger based on preferences and gametype
- -- entry into passenger and gunner seats during (non-team) 'free-for-all' games, results in being put into driver seat
- -- will eject gunners/passengers when: no driver, driver dies, ejects, leaves or based on preferences
- -- option to UPGRADE_PASSENGER to better seat of vehicle, 'when entering', (if a better seat is available)
- -- turn seats on/off per your preference
- -- ======= BEGIN CONFIGURATION ============
- -- Amount of time in seconds before a gunner/passenger is ejected if no driver (or when driver dies/leaves).
- -- 3 seconds is perfect: if vehicle is in the air when driver ejects/dies/leaves, we don't want to eject gunner/passenger immediately, or they may die
- -- note: less than 2 seconds NOT recommended
- EJECT_TIME = 3
- -- true or false, whether or not to allow entering specific seats
- -- During 'Non-Team Games' for race gametype, gunner and passenger seats are disabled automatically
- -- recommended: Leave these set to true, see lines 271 and 277 for race defaults
- ALLOW_DRIVER_SEAT = true
- ALLOW_GUNNER_SEAT = true
- ALLOW_PASSENGER_SEAT = true
- -- Require a driver before allowing players to enter other vehicle seats? true or false
- -- true = players can ONLY enter allowed seats if there is a driver
- -- false = can enter allowed seats without a driver
- -- set to true for mixed gametype servers (i.e. R.O.C.K.S.), including race
- -- see lines 284 for race seating defaults
- DRIVER_REQUIRED = false
- -- true or false, whether or not to UPGRADE_PASSENGER to better seat of vehicle, 'when entering', if available, priority:
- -- 1) NO driver: upgrade/move player from passenger to driver seat, then
- -- 2) HAS DRIVER BUT NO GUNNER: upgrade/move player from passenger to gunner seat
- -- note: will only take effect 'if seat is enabled/allowed' if a better seat is available
- UPGRADE_PASSENGER = true
- -- Message given to players who attempts to enter a driverless vehicle
- DRIVERLESS_MESSAGE = "FIRST player to reach vehicle DRIVES!"
- -- Message to players who are ejected from a driverless vehicle - anti-camp
- EJECT_MESSAGE = "|*EJECTED!*| You have NO DRIVER! Please DRIVE!"
- -- The command to use to "reset the map" and to reload
- RESET_COMMAND = "reset"
- -- ======= END CONFIGURATION ============
- -- don't edit below --
- api_version = "1.9.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_VEHICLE_ENTER'], "OnVehicleEnter")
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_TICK'], "OnTick")
- register_callback(cb['EVENT_COMMAND'], "OnCommand")
- players_in_vehicle = {}
- team_play = getteamplay()
- game_type = get_var(0,"$gt")
- game_started = true
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- OnNewGame()
- else
- game_started = false
- end
- end
- function OnScriptUnload()
- players_in_vehicle = {}
- end
- function OnNewGame()
- game_started = true
- SetDefaults()
- end
- function OnGameEnd()
- game_started = false
- end
- function OnVehicleEnter(PlayerIndex, Seat) -- Passenger/Gunner seats: only applies when DRIVER_REQUIRED is set to false
- local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- local vehicle_object = get_object_memory(vehicleId)
- -- gunner seat preferences
- if Seat == "2" then
- if (vehicle_object ~= 0 and game_started == true) then
- local driver = read_dword(vehicle_object + 0x324)
- local gunner = read_dword(vehicle_object + 0x328)
- -- race preferences: put gunner into the driver seat, then set gunner seat as empty
- -- may need to customize for 'gunner is driver' configuration (? don't thinks so, but maybe)
- if (game_type == "race") then
- if (driver == 0xFFFFFFFF and ALLOW_DRIVER_SEAT == true) then
- enter_vehicle(vehicleId, PlayerIndex, 0)
- write_dword(vehicle_object + 0x324, player_object_id)
- write_dword(vehicle_object + 0x328, 0xFFFFFFFF)
- if team_play then
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- " .. DRIVERLESS_MESSAGE .. " You are now the DRIVER!")
- else
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- You were UPGRADED! You are now the DRIVER!")
- end
- elseif (driver ~= 0xFFFFFFFF and gunner == 0xFFFFFFFF and ALLOW_GUNNER_SEAT == true) then
- enter_vehicle(vehicleId, PlayerIndex, 2)
- write_dword(vehicle_object + 0x328, player_object_id)
- end
- -- non-race gametypes
- elseif (game_type ~= "race") then
- if (driver ~= 0xFFFFFFFF and gunner == 0xFFFFFFFF and ALLOW_GUNNER_SEAT == true) then
- enter_vehicle(vehicleId, PlayerIndex, 2)
- write_dword(vehicle_object + 0x328, player_object_id)
- end
- end
- end
- -- passenger seat preferences
- -- UPGRADE_PASSENGER: put passenger into the driver or gunner seat, then set passenger seat as empty
- elseif (Seat == "1" or (tonumber(Seat) > 2)) then
- if (vehicle_object ~= 0 and game_started == true) then
- local driver = read_dword(vehicle_object + 0x324)
- local gunner = read_dword(vehicle_object + 0x328)
- local passenger = read_dword(vehicle_object + 0x32C)
- if (UPGRADE_PASSENGER == true) then
- if (driver == 0xFFFFFFFF and ALLOW_DRIVER_SEAT == true and game_type == "race") then
- enter_vehicle(vehicleId, PlayerIndex, 0)
- write_dword(vehicle_object + 0x324, player_object_id)
- if team_play then
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- " .. DRIVERLESS_MESSAGE .. " You are now the DRIVER!")
- else
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- You were UPGRADED! You are now the DRIVER!")
- end
- write_dword(vehicle_object + 0x32c, 0xFFFFFFFF) -- set seat to empty
- elseif (driver ~= 0xFFFFFFFF and gunner == 0xFFFFFFFF and ALLOW_GUNNER_SEAT == true and game_type == "race") then
- enter_vehicle(vehicleId, PlayerIndex, 2)
- write_dword(vehicle_object + 0x328, player_object_id)
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- You were UPGRADED! You are now the GUNNER!")
- write_dword(vehicle_object + 0x32c, 0xFFFFFFFF) -- set seat to empty
- elseif (driver == 0xFFFFFFFF and ALLOW_DRIVER_SEAT == true and game_type ~= "race") then
- enter_vehicle(vehicleId, PlayerIndex, 0)
- write_dword(vehicle_object + 0x328, player_object_id)
- if team_play then
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- " .. DRIVERLESS_MESSAGE .. " You are now the DRIVER!")
- else
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- You were UPGRADED! You are now the DRIVER!")
- end
- write_dword(vehicle_object + 0x32c, 0xFFFFFFFF) -- set seat to empty
- elseif (driver ~= 0xFFFFFFFF and gunner == 0xFFFFFFFF and ALLOW_GUNNER_SEAT == true and game_type ~= "race") then
- enter_vehicle(vehicleId, PlayerIndex, 2)
- write_dword(vehicle_object + 0x328, player_object_id)
- say(PlayerIndex, get_var(PlayerIndex, "$name") .. " -- You were UPGRADED! You are now the GUNNER!")
- write_dword(vehicle_object + 0x32c, 0xFFFFFFFF) -- set seat to empty
- elseif (driver ~= 0xFFFFFFFF and gunner ~= 0xFFFFFFFF and passenger == 0xFFFFFFFF and ALLOW_PASSENGER_SEAT == true) then
- enter_vehicle(vehicleId, PlayerIndex, tonumber(Seat))
- write_dword(vehicle_object + 0x32c, player_object_id)
- end
- elseif (UPGRADE_PASSENGER == false and passenger == 0xFFFFFFFF and ALLOW_PASSENGER_SEAT == true) then
- enter_vehicle(vehicleId, PlayerIndex, 1)
- write_dword(vehicle_object + 0x32c, player_object_id)
- end
- end
- -- driver seat preferences
- elseif (Seat == "0" and ALLOW_DRIVER_SEAT == true) then
- if (vehicle_object ~= 0 and game_started == true) then
- enter_vehicle(vehicleId, PlayerIndex, 0)
- write_dword(vehicle_object + 0x324, player_object_id)
- end
- end
- end
- function OnTick()-- ejects passengers and gunners if there is no driver, original by 002
- local time = os.clock()
- for i=1,16 do
- if player_alive(i) then
- local player_object = get_dynamic_player(i)
- local vehicleId = read_dword(player_object + 0x11C)
- local vehicle_object = get_object_memory(vehicleId)
- if (vehicle_object ~= 0 and game_started == true) then
- -- gunners
- if (VehicleHasDriver(vehicleId) == false and PlayerIsGunner(i) == true) then
- if (players_in_vehicle[i] == nil) then
- players_in_vehicle[i] = time
- elseif (time > (players_in_vehicle[i] + EJECT_TIME)) then
- -- race gunners
- if (game_type == "race") then
- if (read_byte(player_object + 0x2A3) ~= 27) then
- exit_vehicle(i)
- say(i, get_var(i, "$name") .. ": " .. EJECT_MESSAGE)
- players_in_vehicle[i] = nil
- end
- -- non-race gunners, driver required
- elseif (game_type ~= "race" and DRIVER_REQUIRED == true) then
- if (read_byte(player_object + 0x2A3) ~= 27) then
- exit_vehicle(i)
- say(i, get_var(i, "$name") .. ": " .. EJECT_MESSAGE)
- players_in_vehicle[i] = nil
- end
- end
- end
- -- passengers
- elseif (PlayerIsGunner(i) == false and VehicleHasDriver(vehicleId) == false) then
- if (players_in_vehicle[i] == nil) then
- players_in_vehicle[i] = time
- elseif (time > (players_in_vehicle[i] + EJECT_TIME)) then
- -- race passengers
- if (game_type == "race") then
- if (read_byte(player_object + 0x2A3) ~= 27) then
- exit_vehicle(i)
- say(i, get_var(i, "$name") .. ": " .. EJECT_MESSAGE)
- players_in_vehicle[i] = nil
- end
- -- non-race passengers, driver required
- elseif (game_type ~= "race" and DRIVER_REQUIRED == true) then
- if (read_byte(player_object + 0x2A3) ~= 27) then
- exit_vehicle(i)
- say(i, get_var(i, "$name") .. ": " .. EJECT_MESSAGE)
- players_in_vehicle[i] = nil
- end
- end
- end
- else
- players_in_vehicle[i] = nil
- end
- end
- end
- end
- end
- function OnCommand(PlayerIndex,Command,Environment,Password)
- local response = true
- Command = string.lower(Command)
- -- if chat command, i.e. chat: /reset
- if (Environment == 2) then
- if (Command == RESET_COMMAND) or (Command == "/reset") or (Command == "reset") then
- if (tonumber(get_var(PlayerIndex, "$lvl")) >= 1) then
- response = true
- OnScriptUnload()
- OnScriptLoad()
- execute_command("sv_map_reset")
- else
- response = false
- end
- end
- -- if console or rcon
- elseif (Environment == 0) or (Environment == 1) then
- if (Command == "sv_map_reset") or (Command == RESET_COMMAND) then
- response = true
- OnScriptUnload()
- OnScriptLoad()
- execute_command("sv_map_reset")
- end
- end
- return response
- end
- function SetDefaults()
- players_in_vehicle = {}
- team_play = getteamplay()
- game_type = get_var(0,"$gt")
- game_started = true
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- else
- game_started = false
- end
- -- FFA RACE: IF you use my Multi-Team-Vehicles/MTV Script, - AND = you are using this script 'with' EITHER 'TAXI' or 'DYNAMIC VEHICLE ENTRY' SCRIPTS,
- -- ALLOW_GUNNER_SEAT and/or ALLLOW_PASSENGER_SEAT (your choice) must be set to true, or this script will block player vehicle entry
- -- set seat preferences
- if (game_type == "race") then
- ALLOW_DRIVER_SEAT = true
- ALLOW_GUNNER_SEAT = true
- ALLOW_PASSENGER_SEAT = true
- UPGRADE_PASSENGER = true
- DRIVER_REQUIRED = false
- elseif (game_type ~= "race") then
- ALLOW_DRIVER_SEAT = ALLOW_DRIVER_SEAT or true
- ALLOW_GUNNER_SEAT = ALLOW_GUNNER_SEAT or true
- ALLOW_PASSENGER_SEAT = ALLOW_PASSENGER_SEAT or true
- UPGRADE_PASSENGER = UPGRADE_PASSENGER or true
- DRIVER_REQUIRED = DRIVER_REQUIRED or true
- end
- --enable/disable seating according to configuration: -- created by Giraffe (Excellent work!)
- for i=0,1 do
- local vehicles_count = nil
- local vehicles_data = nil
- local size = nil
- if (i == 0) then
- local globals_tag = lookup_tag("matg", "globals\\globals")
- local globals_data = read_dword(globals_tag + 0x14)
- local mp_info_data = read_dword(globals_data + 0x168)
- vehicles_count = read_dword(mp_info_data + 0x20)
- vehicles_data = read_dword(mp_info_data + 0x24)
- size = 16
- else
- local scenario_tag = read_dword(0x40440000)
- local scenario_data = read_dword(scenario_tag + 0x14)
- vehicles_count = read_dword(scenario_data + 0x24C)
- vehicles_data = read_dword(scenario_data + 0x250)
- size = 48
- end
- for j=0,vehicles_count-1 do
- local vehicle_metaid = read_dword(vehicles_data + j*size + 0xC)
- if(vehicle_metaid ~= 0xFFFFFFFF) then
- local vehicle_tag = lookup_tag(vehicle_metaid)
- local vehicle_data = read_dword(vehicle_tag + 0x14)
- local seats_count = read_dword(vehicle_data + 0x2E4)
- local seats_data = read_dword(vehicle_data + 0x2E8)
- for k=0,seats_count-1 do
- if (read_bit(seats_data + k*284, 2) == 1) then -- if driver seat
- if (not ALLOW_DRIVER_SEAT) then
- write_string(seats_data + k*284 + 0x4, "Driver")
- end
- elseif (read_bit(seats_data + k*284, 3) == 1) then -- if gunner seat
- if (not ALLOW_GUNNER_SEAT) then
- write_string(seats_data + k*284 + 0x4, "Gunner")
- end
- if (DRIVER_REQUIRED) then
- write_bit(seats_data + k*284 + 0x1, 1, 1) -- enables 'not valid without driver' flag
- end
- else -- if not driver and/or gunner seat assumed to be passenger seat
- if (not ALLOW_PASSENGER_SEAT) then
- write_string(seats_data + k*284 + 0x4, "Bitch seat")
- end
- if (DRIVER_REQUIRED) then
- write_bit(seats_data + k*284 + 0x1, 1, 1) -- enables 'not valid without driver' flag
- end
- end
- end
- end
- end
- end
- end
- function getteamplay()
- if (get_var(0,"$ffa") == "0") then
- return true
- elseif (get_var(0,"$ffa") == "1") then
- return false
- end
- end
- function VehicleHasDriver(VehicleID)
- local vehicle_object = get_object_memory(VehicleID)
- if (vehicle_object == 0) then return false end
- return read_dword(vehicle_object + 0x324) ~= 0xFFFFFFFF
- end
- function PlayerIsGunner(PlayerIndex)
- if (player_present(PlayerIndex) == false) then return false end
- local player_object = get_dynamic_player(PlayerIndex)
- local pid = 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 + 0x328) == pid
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- includes code from Giraffe, 002 and Skylace re-written to add RACE server configurations/preferences, thank you!
- -- Visit http://halorace.org
- -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
- -- -db- is: "diverging from the believable" - How ironic. A race clan where admins use rcon to favor themselves to win.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement