Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Taxi v2 for SAPP by H® Shaft 8/7/2016
- -- Allows walking players to hitch a ride/teleported into a teammates vehicle.
- -- To hail a taxi, just press crouch key - Or, type "Taxi" in the chat.
- -- Can be used with all gametypes. Best used with "team" gametypes in Stock PC/CE maps and unprotected CE maps, which use stock vehicles/flags
- -- Flag holders in CTF cannot hail a taxi
- -- When a player dies, a player must wait until hail_delay (below) is expired
- -- Enable or disable taxi, and passenger seat on a per-map basis, see line 374, function LoadDefaults
- -- How often (in seconds) to remind walking players if taxi is enabled, default 120 seconds = 2 min (too often will be annoying)
- taxi_reminder = 120
- -- what message will be shown to players on joining (only shown if taxi is enabled for the map, see line 374, function LoadDefaults)
- reminder_message = "Taxi is ENABLED: Press your crouch key, or type TAXI to hail a taxi (be put into a teammates vehicle)."
- -- Taxi Hailing Delay: amount of time, in seconds a player must wait after dying before they can hail a taxi
- -- This addresses the complaint that in race, a driver/gunner team is sometimes hard to eliminate, if only one is killed
- hail_delay = 10
- -- do not touch --
- api_version = "1.9.0.0"
- taxi, hails, enable_taxi, enable_passenger, has_flag = {}, {}, {}, {}, {}
- taxi_delay = 2 -- do not edit this
- game_started = false
- function OnScriptLoad()
- register_callback(cb['EVENT_TICK'], "OnTaxiCall")
- register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
- register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
- register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- -- retrieve meta-ids if game is running
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- game_type = get_var(0, "$gt")
- if game_type == "ctf" then
- GetMetaID()
- end
- end
- -- set default values on load, or if script is reloaded
- if game_started then
- game_started = true
- map_name = get_var(0,"$map")
- game_type = get_var(0, "$gt")
- LoadDefaults()
- for i=1,16 do
- if player_present(i) then
- hails[i] = 0
- if game_type == "ctf" then
- local player_object = get_dynamic_player(i)
- if (player_object ~= 0) then
- if PlayerHasFlag(i) then has_flag[i] = true else has_flag[i] = false end
- end
- end
- end
- end
- end
- end
- function OnScriptUnload()
- taxi, hails, enable_taxi, enable_passenger, has_flag = {}, {}, {}, {}, {}
- end
- -- on new game, set values
- function OnNewGame()
- game_started = true
- map_name = get_var(0,"$map")
- game_type = get_var(0, "$gt")
- if game_type == "ctf" then
- GetMetaID()
- end
- LoadDefaults()
- reminder = timer(taxi_reminder * 1000, "TimedReminder")
- for i=1,16 do
- if player_present(i) then
- hails[i] = 0
- has_flag[i] = false
- end
- end
- end
- -- on game end, set values
- function OnGameEnd()
- game_started = false
- end
- -- on new game, set recurring reminder if taxi is enabled, show to all players
- function TimedReminder()
- if game_started then
- for i=1,16 do
- if player_present(i) then
- if (enable_taxi[map_name] == true) then
- say(i, reminder_message)
- end
- end
- end
- return true
- else
- return false
- end
- end
- -- when player joins, set their values, set timer to notify if taxi is enabled, after welcome messages scroll
- function OnPlayerJoin(PlayerIndex)
- if player_present(PlayerIndex) then
- hails[PlayerIndex] = 0
- has_flag[PlayerIndex] = false
- notice = timer(12000, "TimedJoinNotice", PlayerIndex)
- end
- end
- -- when player joins, notify if taxi is enabled, after welcome messages scroll
- function TimedJoinNotice(PlayerIndex)
- if game_started and player_present(PlayerIndex) then
- if (enable_taxi[map_name] == true) then
- say(PlayerIndex, reminder_message)
- end
- end
- return false
- end
- -- when player leaves, nil their values
- function OnPlayerLeave(PlayerIndex)
- if player_present(PlayerIndex) then
- hails[PlayerIndex] = nil
- has_flag[PlayerIndex] = nil
- end
- end
- -- when player dies, set hail delay, set flag status
- function OnPlayerDeath(PlayerIndex, KillerIndex)
- if player_present(PlayerIndex) then
- if game_started then
- has_flag[PlayerIndex] = false
- hails[PlayerIndex] = (taxi_delay + hail_delay *30)
- end
- end
- end
- -- monitor player crouch key press, and flag possession
- function OnTaxiCall()
- for i=1,16 do
- if player_present(i) then
- local player_object = get_dynamic_player(i)
- if (player_object ~= 0) then
- if hails[i] > 0 then hails[i] = hails[i] - 1 end
- if game_type == "ctf" then
- if PlayerHasFlag(i) then has_flag[i] = true else has_flag[i] = false end
- end
- if not isinvehicle(i) then
- local player_crouch = bit.band(read_dword(player_object + 0x208),7)
- local id = i
- if (player_crouch == 1) and (taxi[id] == nil) then
- taxi[id] = OnPlayerCrouch(id)
- elseif player_crouch ~= 1 and taxi[id] ~= nil then
- taxi[id] = nil
- end
- end
- end
- end
- end
- end
- -- called from OnTaxiCall, sets a delay between crouch activations of taxi
- function OnPlayerCrouch(PlayerIndex)
- if game_started then
- if hails[PlayerIndex] == 0 then
- getTaxi(PlayerIndex)
- hails[PlayerIndex] = (taxi_delay*30)
- end
- end
- return false
- end
- -- players can hail a taxi by typing "taxI" and - includes common typo's
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local name = get_var(PlayerIndex,"$name")
- local Message = string.lower(Message)
- if (Message == "taxi") or (Message == "/taxi") or (Message == "taxo") or (Message == "taxci") or (Message == "taci") then
- response = false
- if player_present(PlayerIndex) then
- if game_started then
- if player_alive(PlayerIndex) then
- if isinvehicle(PlayerIndex) then
- say(PlayerIndex, "**Taxi** You are already in a vehicle.")
- else
- getTaxi(PlayerIndex)
- end
- else
- say(PlayerIndex, "**Taxi** You are dead. Try again after you respawn.")
- end
- else
- say(PlayerIndex, "**Taxi** Game has ended. Please wait until a new game begins.")
- end
- end
- end
- return response
- end
- -- seek for an available taxi
- function getTaxi(PlayerIndex)
- if (enable_taxi[map_name] == true) then
- if (has_flag[PlayerIndex] == false) then
- local player2
- local team = get_var(PlayerIndex,"$team")
- for i = 1,16 do
- if PlayerIndex ~= i and get_var(i,"$team") == team and isinvehicle(i) and CheckSeats(i, GetplayerVehicleId(i)) > 0 then
- player2 = i
- break
- end
- end
- if player2 then
- if CheckSeats(player2, GetplayerVehicleId(player2)) > 0 then
- InjectPlayer(PlayerIndex, GetplayerVehicleId(player2), true)
- end
- elseif not player2 then
- say(PlayerIndex, "**Taxi** Sorry no taxi available. Please try again later.")
- end
- else
- say(PlayerIndex, "**Taxi** You cannot hail a taxi while you have the flag.")
- end
- else
- say(PlayerIndex, "**Taxi** Is not enabled for this map.")
- end
- end
- -- inserts selected player into selected vehicle, first to driver, then to gunner, then to passenger seats
- function InjectPlayer(PlayerIndex, vehicleId, count)
- if (player_alive(PlayerIndex) ~= true) then return false end
- local bool = false
- if player_alive(PlayerIndex) then
- local name = get_var(PlayerIndex,"$name")
- if vehicleId ~= false then
- local veh_obj = get_object_memory(vehicleId)
- local driver = read_dword(veh_obj + 0x324)
- local gunner = read_dword(veh_obj + 0x328)
- local passenger = read_dword(veh_obj + 0x32C)
- if driver == 0xFFFFFFFF then
- enter_vehicle(vehicleId, PlayerIndex, 0)
- bool = true
- elseif gunner == 0xFFFFFFFF then
- enter_vehicle(vehicleId, PlayerIndex, 2)
- bool = true
- elseif enable_passenger and (passenger == 0xFFFFFFFF or passenger == 0) then
- enter_vehicle(vehicleId, PlayerIndex, 1)
- bool = true
- end
- if bool and count then
- say(PlayerIndex, "**Taxi** You called a taxi, welcome aboard!")
- end
- end
- end
- end
- -- returns the number of available seats in players vehicle, requires GetVehicleSeats function
- function CheckSeats(PlayerIndex, vehicleId)
- if player_alive(PlayerIndex) then
- local seats = GetVehicleSeats(PlayerIndex, vehicleId)
- local team = get_var(PlayerIndex,"$team")
- if (vehicleId ~= nil) then
- if seats > 0 then
- for i = 1,16 do
- if PlayerIndex ~= i and player_alive(i) and get_var(i,"$team") == team and isinvehicle(i) then
- if GetplayerVehicleId(i) == vehicleId then
- seats = seats - 1
- end
- end
- end
- end
- return seats
- end
- end
- end
- -- returns number of seats in selected vehicle, sets the number of seats (some vehicles have seats not correctly setup)
- -- return the number of vehicle seats not including the driver
- function GetVehicleSeats(PlayerIndex, m_vehicleId)
- if (player_alive(PlayerIndex) == false) then return false end
- if m_vehicleId ~= false then
- local avail_seats = 0
- local veh_name = GetPlayerVehicleTagName(PlayerIndex)
- if veh_name ~= nil then
- if string.find(veh_name, "ghost") or string.find(veh_name, "banshee") or string.find(veh_name, "turret") then
- avail_seats = 0
- elseif string.find(veh_name, "hog") then
- avail_seats = 2
- elseif string.find(veh_name, "scorpion") then
- avail_seats = 1
- else
- avail_seats = 0
- end
- local seats = avail_seats
- return tonumber(seats)
- end
- else
- return 0
- end
- end
- -- returns vehicle tag name of players vehicle for function GetVehicleSeats, which sets number of available seats in the vehicle
- function GetPlayerVehicleTagName(PlayerIndex)
- if isinvehicle(PlayerIndex) then
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- local vehicle_obj = get_object_memory(vehicleId)
- local veh_name = read_string(read_dword(read_word(vehicle_obj) * 32 + 0x40440038))
- if veh_name ~= nil then
- return veh_name
- else
- return nil
- end
- end
- end
- -- returns vehicle object id player is in, or false
- 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
- -- returns true if player is in a vehicle, or false if not -- edited 7/20/2016
- function isinvehicle(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- if player_object ~= 0 then
- local vehicleId = read_dword(player_object + 0x11C)
- if vehicleId == 0xFFFFFFFF then
- return false
- else
- return true
- end
- else
- return false
- end
- end
- -- returns true if player has the flag during ctf games, false if not, requires function GetMetaID()
- function PlayerHasFlag(PlayerIndex)
- if game_started then
- local player_object = get_dynamic_player(PlayerIndex)
- if player_object ~= 0 then
- local weaponId = read_dword(player_object + 0x118)
- local weap_obj = get_object_memory(weaponId)
- if weap_obj ~= 0 then
- local weapon_metaid = read_dword(weap_obj)
- if (weapon_metaid == flag_metaid) then
- return true
- else
- return false
- end
- end
- else
- return false
- end
- else
- return false
- end
- end
- -- retrieves flag metaid, sets players flag value to false
- function GetMetaID()
- flag_metaid = read_dword(lookup_tag("weap", "weapons\\flag\\flag") + 12)
- for i = 1, 16 do
- has_flag[i] = false
- end
- end
- -- set defaults on a per map basis, entire map name should be within quotes, even when map name has
- -- square brackets, parenthesis, periods; example: ["[h3] core"]
- function LoadDefaults()
- -- default enable/disable TAXI for the specified map: true = enable, false = disable
- enable_taxi = {
- ["beavercreek"] = false,
- ["bloodgulch"] = true,
- ["boardingaction"] = true,
- ["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
- }
- -- default enable/disable taxi to PASSENGER seat for the specified map: true = enable, false = disable
- -- ignored if taxi is disabled for the map
- enable_passenger = {
- ["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
- }
- 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