Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gun Me for SAPP
- -- by H® Shaft
- -- allows vehicle drivers to press their melee/f key to insert a walking teammate into their gunner or passenger seat
- -- any vehicle occupant can type "gun me" to insert a walking teammate into their driver, gunner or passenger seat
- -- will not pickup any player who has flag or oddball
- api_version = "1.9.0.0"
- -- do not touch --
- gunme = {}
- game_started = false
- function OnScriptLoad()
- register_callback(cb['EVENT_TICK'],"OnTick")
- 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
- gunme[i] = 0
- end
- end
- end
- end
- function OnScriptUnload()
- gunme = {}
- end
- function OnPlayerJoin(PlayerIndex)
- if player_present(PlayerIndex) then
- gunme[PlayerIndex] = 0
- end
- end
- function OnPlayerLeave(PlayerIndex)
- if player_present(PlayerIndex) then
- gunme[PlayerIndex] = {}
- end
- end
- function OnNewGame()
- game_started = true
- end
- function OnGameEnd()
- game_started = false
- gunme = {}
- end
- function OnTick()
- for i=1,16 do
- if player_present(i) then
- if player_alive(i) then
- local player_dyn = get_dynamic_player(i)
- if (player_dyn ~= 0) then
- if PlayerIsDriver(i) then
- if gunme[i] == nil then gunme[i] = 0 end
- if gunme[i] > 0 then gunme[i] = gunme[i] - 1 end
- if (gunme[i] == 0) and (read_bit(player_dyn + 0x208, 7) == 1) then
- getWalker(tonumber(i))
- gunme[i] = math.floor(1.5*30)
- end
- end
- end
- end
- end
- end
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local name = get_var(PlayerIndex,"$name")
- local Message = string.lower(Message)
- if (Message == "gunme") or (Message == "/gunme") or (Message == "gun me") or (Message == "/gun me") then
- response = false
- if player_present(PlayerIndex) then
- if (game_started == true) then
- if player_alive(PlayerIndex) then
- if isinvehicle(PlayerIndex) == true then
- getWalker(tonumber(PlayerIndex))
- else
- say(PlayerIndex, "**Gun Me** You must be in a vehicle to use this feature.")
- end
- else
- say(PlayerIndex, "**Gun Me** Derp! You are dead!")
- end
- else
- say(PlayerIndex, "**Gun Me** Please wait until the next map begins.")
- end
- end
- end
- return response
- end
- -- checks available seats of players vehicle, looks for teammates not in vehicles, then injects them into an availble seat
- function getWalker(PlayerIndex)
- if (player_alive(PlayerIndex) ~= true) then return false end
- local team = get_var(PlayerIndex,"$team")
- local m_vehicleId = GetplayerVehicleId(PlayerIndex)
- if m_vehicleId ~= false then
- if isinvehicle(PlayerIndex) then
- if game_started == true then
- if tonumber(checkSpaces(PlayerIndex, m_vehicleId)) > 0 then
- local player2
- for i = 1,16 do
- if PlayerIndex ~= i and player_alive(i) and get_var(i,"$team") == team and not isinvehicle(i) then
- player2 = i
- break
- end
- end
- if player2 then
- if not Has_Objective(player2) then
- InjectPlayer(player2, tonumber(m_vehicleId), false)
- else
- say(PlayerIndex, "**Gun Me** No available teammates, or teammate has flag or oddball.")
- end
- else
- say(PlayerIndex, "**Gun Me** No available teammates.")
- end
- else
- say(PlayerIndex, "**Gun Me** No empty seats in your vehicle.")
- end
- elseif game_started == false then
- say(PlayerIndex, "**Gun Me** Please wait until the next map begins.")
- end
- else
- say(PlayerIndex, "**Gun Me** You must be in a vehicle to use this feature.")
- 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
- 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 (passenger == 0xFFFFFFFF or passenger == 0) then
- enter_vehicle(m_vehicleId, PlayerIndex, 1)
- bool = true
- end
- if bool and not count then
- say(PlayerIndex, "**Gun Me** You have been put into the vehicle by a teammate.")
- end
- end
- end
- end
- function PlayerIsDriver(PlayerIndex)
- if (player_alive(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
- -- 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
- -- 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 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 = 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
- -- 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