Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Taxi v3 for SAPP by H® Shaft 1/1/2017
- -- 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.
- -- Flag and Oddball holders cannot hail a taxi
- -- After a player dies, they may not hail a taxi until the hail_delay (below) expires
- -- Changelog:
- -- Works with all Halo PC/CE maps
- -- taxi enabled by default for all maps (no longer need to enable per-map)
- -- added feature: Flag and Oddball holders cannot hail a taxi
- -- When a player dies, a player must wait until hail_delay (below) is expired
- -- may not perform well in non-standard custom vehicles with odd seating
- -- what message will be shown to players on joining
- reminder_message = "Taxi is ENABLED: Press your crouch key, or type TAXI to hail a taxi and ride with a teammate."
- -- 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 = {}, {}
- 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")
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- for i=1,16 do
- if player_present(i) then
- hails[i] = 0
- end
- end
- end
- end
- function OnScriptUnload()
- taxi, hails = {}, {}
- end
- -- on new game, set values
- function OnNewGame()
- game_started = true
- for i=1,16 do
- if player_present(i) then
- hails[i] = 0
- end
- end
- end
- -- on game end, set values
- function OnGameEnd()
- game_started = false
- 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
- 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
- say(PlayerIndex, reminder_message)
- end
- return false
- end
- -- when player leaves, nil their values
- function OnPlayerLeave(PlayerIndex)
- if player_present(PlayerIndex) then
- hails[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
- hails[PlayerIndex] = (taxi_delay + hail_delay *30)
- end
- end
- end
- -- monitor player crouch key press
- 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 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 not Has_Objective(PlayerIndex) then
- if isinvehicle(PlayerIndex) then
- say(PlayerIndex, "**Taxi** You are already in a vehicle.")
- else
- getTaxi(PlayerIndex)
- end
- else
- say(PlayerIndex, "**Taxi** You cannot hail a taxi while you have the flag or oddball.")
- 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 not Has_Objective(PlayerIndex) 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 or oddball.")
- 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 (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 = string.lower(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") or string.find(veh_name, "snowhog") or string.find(veh_name, "hogfoot") or string.find(veh_name, "civi") then
- avail_seats = 0
- elseif string.find(veh_name, "hog") or string.find(veh_name, "hawg") or string.find(veh_name, "puma") then
- avail_seats = 2
- elseif string.find(veh_name, "scorpion") or string.find(veh_name, "falcon") or string.find(veh_name, "car") then
- avail_seats = 1
- else
- avail_seats = 0
- end
- local seats = avail_seats
- return tonumber(seats)
- end
- else
- return false
- 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) and game_started then
- local player_object = get_dynamic_player(PlayerIndex)
- local vehicleId = read_dword(player_object + 0x11C)
- local vehicle_obj = get_object_memory(vehicleId)
- if (vehicle_obj ~= 0) then
- local vehicle_metaid = read_dword(vehicle_obj)
- local veh_name = get_vehicle_name(vehicle_metaid)
- if veh_name ~= nil and veh_name ~= "NULL METAID" then
- return veh_name
- else
- return nil
- end
- 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
- function get_vehicle_name(MetaID) -- Thanks to Giraffe!
- if (MetaID == 0xFFFFFFFF) then
- return "NULL METAID"
- else
- local globals_tag = lookup_tag("matg", "globals\\globals")
- local globals_data = read_dword(globals_tag + 0x14)
- local interface_bitmaps_data = read_dword(globals_data + 0x144)
- local hud_globals_metaid = read_dword(interface_bitmaps_data + 0x6C)
- local hud_globals_tag = lookup_tag(hud_globals_metaid)
- local hud_globals_data = read_dword(hud_globals_tag + 0x14)
- local hud_icon_messages_metaid = read_dword(hud_globals_data + 0xC0)
- local hud_icon_messages_tag = lookup_tag(hud_icon_messages_metaid)
- local hud_icon_messages_data = read_dword(hud_icon_messages_tag + 0x14)
- local string_references_count = read_dword(hud_icon_messages_data)
- local string_references_data = read_dword(hud_icon_messages_data + 0x4)
- local strings = {}
- for i=0,string_references_count-1 do
- local bytes = read_dword(string_references_data + i*20)
- local string_data = read_dword(string_references_data + i*20 + 0xC)
- local string = ''
- for j=0,bytes-3,2 do
- string = string .. string.char(read_char(string_data +j))
- end
- strings[i] = string
- end
- local vehicle_tag = lookup_tag(MetaID)
- local vehicle_data = read_dword(vehicle_tag + 0x14)
- local hud_text_message_index = read_short(vehicle_data + 0x13C)
- if(strings[hud_text_message_index] ~= nil) then
- return strings[hud_text_message_index]
- else
- return strings[0]
- end
- end
- end
- 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
- -- iterates thru all players weapons, returns true if they have flag or oddball, if not, returns false
- -- this is specifically checking the 'must be readied' flag of each of their weapons
- function Has_Objective(PlayerIndex)
- local response = false
- if get_var(0, "$gt") ~= "n/a" then
- if (get_var(0, "$gt") == "ctf") or (get_var(0, "$gt") == "oddball") then
- local player_object = get_dynamic_player(PlayerIndex)
- for w=0,3 do
- local weap_id = read_dword(player_object + 0x2F8 + 0x4 * w)
- if (weap_id ~= 0xFFFFFFFF) then
- local weap_obj = get_object_memory(weap_id)
- if (weap_obj ~= 0) then
- local obj_type = read_byte(weap_obj + 0xB4)
- local tag_address = read_word(weap_obj)
- local tagdata = read_dword(read_dword(0x40440000) + tag_address * 0x20 + 0x14)
- if (read_bit(tagdata + 0x308,3) == 1) then
- response = true
- end
- end
- end
- end
- end
- end
- return response
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- Visit http://halorace.org/forum/index.php
- -- 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