Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dynamic Vehicle Entry for SAPP
- -- by H® Shaft and Giraffe
- -- Players only need to aim at a vehicle then press Action Key (E) to enter it.
- -- if they are in range and on the same team (if it is occupied), and if it is upright
- -- they will be inserted into an available seat: 1) driver, 2) gunner, or 3) passenger
- -- Compatible with all halo PC/CE maps, stock and custom, protected or not, any vehicle in range
- -- Compatible with Multi-Team-Vehicles script for non-team games! http://pastebin.com/vq6HXEpA
- -- max distance from a vehicle player can be to enter a vehicle (in world units)
- -- recommended: 30 for most stock maps, 50-100 for extremely large custom maps (hugeass, extinction, etc)
- MAX_DISTANCE = 30
- -- if set to true, players will be shown the JOIN_MESSAGE below (how to use Dynamic Vehicle Entry)
- ENABLE_MESSAGE = true
- -- message given to joining players if ENABLE_MESSAGE (above) is set to true
- -- should not be more than 3 entries, ensure the messages are within quotes,
- -- and separated by a comma between each message
- JOIN_MESSAGE = {
- "Dynamic Vehicle Entry is Enabled!",
- "Aim at a vehicle then press Action Key (E) to enter it.",
- }
- -- sapp api version
- api_version = '1.10.0.0'
- -- don't edit below here unless you know what you are doing --
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_TICK'], "OnTick")
- register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
- register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
- register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
- if get_var(0, "$gt") ~= "n/a" then
- OnNewGame()
- end
- end
- function OnNewGame()
- game_started = true
- LoadDefaults()
- end
- function OnGameEnd()
- game_started = false
- end
- function OnPlayerJoin(PlayerIndex)
- delay[PlayerIndex] = 0
- if ENABLE_MESSAGE then
- timer(12000, "Timed_Message", PlayerIndex)
- end
- end
- function Timed_Message(PlayerIndex)
- if game_started then
- if player_present(PlayerIndex) then
- for l,message in pairs(JOIN_MESSAGE) do
- say(PlayerIndex,message)
- end
- end
- end
- return false
- end
- function OnPlayerLeave(PlayerIndex)
- delay[PlayerIndex] = 0
- end
- function OnPlayerDeath(PlayerIndex, KillerIndex)
- if player_present(PlayerIndex) then
- delay[PlayerIndex] = 0
- end
- end
- function OnTick()
- if game_started then
- for i=1,16 do
- if player_alive(i) then
- local player_object = get_dynamic_player(i)
- -- entry delay default and decrement
- if (delay[i] == nil) then delay[i] = 0 end
- if (delay[i] > 0) then delay[i] = delay[i] - 1 end
- -- detect action key press - activate if no delay, and if player is not in a vehicle, check for vehicle intersect
- if not isinvehicle(i) and (read_bit(player_object + 0x208, 6) == 1) then
- if (delay[i] == 0) then
- delay[i] = math.floor(2*30)
- Intersect_Vehicle(i)
- end
- end
- end
- end
- end
- end
- function Intersect_Vehicle(PlayerIndex)
- if not game_started then return end
- local vehicle_id = 0
- local player_object = get_dynamic_player(PlayerIndex)
- local px, py, pz = read_vector3d(player_object + 0x5c)
- local cx, cy, cz = read_vector3d(player_object + 0x230)
- local ignore_this_pid = read_dword(get_player(PlayerIndex) + 0x34)
- local crouch_state = read_float(player_object + 0x50C)
- pz = pz + stand_height - (crouch_state * (stand_height - crouch_height))
- local success, x, y, z, target = intersect(px, py, pz, cx*1000, cy*1000, cz*1000, ignore_this_pid)
- if (success == true and target ~= 0xFFFFFFFF) then
- local target_object = get_object_memory(target)
- if (target_object ~= 0) then
- local obj_type = read_word(target_object + 0xB4)
- if (obj_type == 1) then -- target is a vehicle
- vehicle_id = target
- local distance = tonumber(math.sqrt(((x-px)*(x-px)) + ((y-py)*(y-py)) + ((z-pz)*(z-pz))))
- if (distance <= MAX_DISTANCE and vehicle_id ~= 0) then
- enter_vehicle_empty_seat(vehicle_id, PlayerIndex)
- end
- end
- end
- end
- end
- function enter_vehicle_empty_seat(ObjectID, PlayerIndex)
- if not game_started then return end
- local vehicle = get_object_memory(ObjectID)
- local vehicle_metaid = read_dword(vehicle)
- local vehicle_tag = lookup_tag(vehicle_metaid)
- local vehicle_data = read_dword(vehicle_tag + 0x14)
- if (read_bit(vehicle + 0x8B, 7) == 1) then return false end -- do nothing if vehicle is flipped
- local seats = {}
- for i=1,16 do
- if (player_alive(i)) then
- local player = get_dynamic_player(i)
- if (ObjectID == read_dword(player + 0x11C)) then
- -- using this method of reading team to enable use with multi-team vehicles
- if (read_word(get_player(PlayerIndex) + 0x20) ~= read_word(get_player(i) + 0x20)) then
- return false
- end
- seats[read_word(player + 0x2F0)] = i
- end
- end
- end
- local driver_seat = nil
- local gunner_seat = nil
- local seat_count = read_dword(vehicle_data + 0x2E4)
- local seat_data = read_dword(vehicle_data + 0x2E8)
- for i=0,seat_count-1 do
- local label = read_string32(seat_data + i*284 + 0x4)
- if (biped_seat_labels[label] == true) then
- if (read_bit(seat_data + i*284, 2) == 1) then -- check if driver
- driver_seat = i
- elseif (read_bit(seat_data + i*284, 3) == 1) then -- check if gunner
- gunner_seat = i
- end
- else
- cprint(label)
- seats[i] = 0
- end
- end
- if (driver_seat ~= nil and seats[driver_seat] == nil) then
- enter_vehicle(ObjectID, PlayerIndex, driver_seat)
- return true
- end
- if (gunner_seat ~= nil and seats[gunner_seat] == nil) then
- enter_vehicle(ObjectID, PlayerIndex, gunner_seat)
- return true
- end
- for i=0,seat_count-1 do
- if (seats[i] == nil) then
- enter_vehicle(ObjectID, PlayerIndex, i)
- return true
- end
- end
- return false
- end
- function LoadDefaults()
- -- tables
- delay = {}
- biped_seat_labels = {}
- -- default globals
- stand_height = nil
- crouch_height = nil
- -- player values
- for i = 1,16 do
- if player_present(i) then
- delay[i] = 0
- end
- end
- if get_var(0, "$gt") ~= "n/a" then
- -- biped data - don't edit anything here
- -- checks if unit type is biped, and sets stand & crouch heights
- -- crosschecks biped_animation data against vehicle seat labels
- 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)
- local player_unit_type = read_dword(mp_info_data + 0x10)
- if (player_unit_type == 0x62697064) then
- local biped_metaid = read_dword(mp_info_data + 0x1C)
- if (biped_metaid ~= 0xFFFFFFFF) then
- local biped_tag = lookup_tag(biped_metaid)
- local biped_data = read_dword(biped_tag + 0x14)
- stand_height = read_float(biped_data + 0x400)
- crouch_height = read_float(biped_data + 0x404)
- local biped_animation_metaid = read_dword(biped_data + 0x44)
- if (biped_animation_metaid ~= 0xFFFFFFFF) then
- local animation_tag = lookup_tag(biped_animation_metaid)
- local animation_data = read_dword(animation_tag + 0x14)
- local unit_seat_count = read_dword(animation_data + 0xC)
- local unit_seat_data = read_dword(animation_data + 0x10)
- for i=0,unit_seat_count-1 do
- local label = read_string32(unit_seat_data + i*100)
- biped_seat_labels[label] = true
- end
- end
- end
- 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
- function read_string32(ReadAddress)
- local str = read_string(ReadAddress)
- if (str:len() > 32) then
- str = str:sub(1, 32)
- end
- return str
- end
- function OnScriptUnload() end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft and Giraffe
- -- 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