Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Taxi 1.1 for SAPP by H® Shaft 1/4/2016, updated 7/20/2016, edited 8/6/2016 corrected line 296
- -- Allows walking players to hitch a ride in a teammates vehicle.
- -- To activate, just crouch! Or, type "Taxi" in the chat.
- -- Best used with team race gametypes.
- -- do not touch --
- api_version = "1.9.0.0"
- taxi, hails, set_seat, enable_taxi, enable_passenger = {}, {}, {}, {}, {}
- taxi_delay = 2
- 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")
- LoadDefaults()
- if get_var(0, "$gt") ~= "n/a" then
- game_started = true
- for i=1,16 do
- if player_present(i) then
- hails[i], set_seat[i] = 0, {}
- local player_object = get_dynamic_player(i)
- if (player_object ~= 0) then
- if isinvehicle(i) then
- if read_byte(player_object + 0x2A0) == 0 then -- << driver
- set_seat[i].seat = 0
- set_seat[i].vehicle = read_dword(player_object + 0x11C)
- elseif read_byte(player_object + 0x2A0) == 1 then -- << passenger
- set_seat[i].seat = 1
- set_seat[i].vehicle = read_dword(player_object + 0x11C)
- elseif read_byte(player_object + 0x2A0) == 2 then -- << gunner
- set_seat[i].seat = 2
- set_seat[i].vehicle = read_dword(player_object + 0x11C)
- end
- end
- end
- end
- end
- map_name = get_var(1,"$map")
- enable_taxi[map_name] = enable_taxi[map_name] or false
- enable_passenger[map_name] = enable_passenger[map_name] or false
- end
- end
- function OnScriptUnload()
- taxi, hails, set_seat, enable_taxi = {}, {}, {}, {}
- end
- function OnPlayerJoin(PlayerIndex)
- if player_present(PlayerIndex) then
- hails[PlayerIndex], set_seat[PlayerIndex] = 0, {}
- end
- end
- function OnPlayerLeave(PlayerIndex)
- if player_present(PlayerIndex) then
- if set_seat[PlayerIndex].vehicle then
- if set_seat[PlayerIndex].seat == 1 then write_dword(set_seat[PlayerIndex].vehicle + 0x32C, 0xFFFFFFFF) end
- end
- set_seat[PlayerIndex] = {}
- set_seat[PlayerIndex] = nil
- end
- end
- function OnPlayerDeath(PlayerIndex, KillerIndex)
- if player_present(PlayerIndex) then
- if (game_started == true) then
- if set_seat[PlayerIndex].seat == 1 then
- write_dword(set_seat[PlayerIndex].vehicle + 0x32C, 0xFFFFFFFF)
- end
- set_seat[PlayerIndex] = {}
- set_seat[PlayerIndex].seat = nil
- end
- end
- end
- function OnVehicleEnter(PlayerIndex, Seat)
- if (game_started == true) then
- if player_present(PlayerIndex) then
- local player_object = get_dynamic_player(PlayerIndex)
- if (player_object ~= 0) then
- local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
- local vehicleId = read_dword(player_object + 0x11C)
- local veh_obj = get_object_memory(vehicleId)
- set_seat[PlayerIndex].seat = Seat
- set_seat[PlayerIndex].vehicle = read_dword(player_object + 0x11C)
- if Seat == "1" then
- timer(0, "assignpassenger", {player_obj_id, veh_obj})
- end
- end
- end
- end
- end
- function OnVehicleEject(PlayerIndex)
- if (game_started == true) then
- if player_present(PlayerIndex) then
- local player_object = get_dynamic_player(PlayerIndex)
- local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
- if (player_object ~= 0) then
- if set_seat[PlayerIndex].seat == 1 then resetpassenger(PlayerIndex) end
- set_seat[PlayerIndex] = {}
- set_seat[PlayerIndex].seat = nil
- end
- end
- end
- end
- function OnNewGame()
- map_name = get_var(1,"$map")
- LoadDefaults()
- game_started = true
- enable_taxi[map_name] = enable_taxi[map_name] or false
- enable_passenger[map_name] = enable_passenger[map_name] or false
- end
- function OnGameEnd()
- game_started = false
- end
- -- associated with a key press, not a player animation state
- 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
- function OnPlayerCrouch(PlayerIndex)
- if (game_started == true) then
- if hails[PlayerIndex] == 0 then
- getTaxi(PlayerIndex)
- hails[PlayerIndex] = (taxi_delay*30)
- end
- return true
- else
- return false
- end
- end
- 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") then
- response = false
- if player_present(PlayerIndex) then
- if (game_started == true) then
- if player_alive(PlayerIndex) then
- if (enable_taxi[map_name] == true) then
- if isinvehicle(PlayerIndex) then
- say(PlayerIndex, "**Taxi** You are already in a vehicle.")
- else
- getTaxi(PlayerIndex)
- end
- else
- say(PlayerIndex, "**Taxi** Is not enabled for this map.")
- end
- else
- say(PlayerIndex, "**Taxi** You are dead. Try again after you respawn.")
- end
- else
- say(PlayerIndex, "**Taxi** Please wait until the next map begins.")
- end
- end
- end
- return response
- end
- function getTaxi(PlayerIndex)
- local player2
- local team = get_var(PlayerIndex,"$team")
- for i=0,15 do
- if PlayerIndex ~= i and get_var(i,"$team") == team and isinvehicle(i) and checkSpaces(i, get_var(i,"$team"), GetplayerVehicleId(i)) > 0 then
- player2 = i
- break
- end
- end
- if player2 then
- InjectPlayer(PlayerIndex, GetplayerVehicleId(player2), true)
- else
- if (enable_taxi[map_name] == true) then
- say(PlayerIndex, "**Taxi** Sorry no taxi available. Please try again later.")
- end
- end
- end
- -- inserts selected player into selected vehicle
- function InjectPlayer(PlayerIndex, m_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 m_vehicleId ~= false then
- local veh_obj = get_object_memory(m_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(m_vehicleId, PlayerIndex, 0)
- bool = true
- elseif gunner == 0xFFFFFFFF then
- enter_vehicle(m_vehicleId, PlayerIndex, 2)
- bool = true
- elseif enable_passenger and (passenger == 0xFFFFFFFF or passenger == 0) then
- enter_vehicle(m_vehicleId, PlayerIndex, 1)
- bool = true
- end
- if bool and count then
- say(PlayerIndex, "**Taxi** Did you call a taxi? Welcome aboard!")
- end
- end
- end
- end
- -- returns the number of available seats in players vehicle, requires GetVehicleSeats function
- function checkSpaces(PlayerIndex, m_vehicleId)
- if (player_alive(PlayerIndex) == false) then return 0 end
- local seats = GetVehicleSeats(PlayerIndex, m_vehicleId)
- local team = get_var(PlayerIndex,"$team")
- if (m_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) == m_vehicleId then
- seats = seats - 1
- end
- end
- end
- end
- return seats
- 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
- 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
- function resetpassenger(PlayerIndex)
- if set_seat[PlayerIndex].seat == nil then return end
- if set_seat[PlayerIndex].vehicle then
- write_dword(set_seat[PlayerIndex].vehicle + 0x32C, 0xFFFFFFFF)
- set_seat[PlayerIndex].seat = nil
- end
- end
- function getplayerobjectid(PlayerIndex)
- local playerindex = to_player_index(PlayerIndex)
- return read_dword(get_player(playerindex) + 0x34) or nil
- end
- -- assign passenger seat player to vehicle
- -- overcomes defect in reliability of passenger seat reading for scripts
- function assignpassenger(arg)
- if (game_started == true) then
- set_seat[objectidtoplayer(arg[1])].vehicle = arg[2]
- writedword(arg[2] + 0x32C, arg[1])
- end
- return false
- end
- -- returns PlayerIndex from an ObjectID
- function objectidtoplayer(ObjectID)
- local object = get_object_memory(ObjectID)
- if object ~= 0 then
- local playerId = read_word(object + 0xC0)
- return to_player_index(playerId) ~= 0 or nil 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
- function isinvehicle(PlayerIndex) -- edited 7/20/2016
- 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
- -- 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