Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- -- Assuming driver is first seat in vehicle tag then leave at 0
- SEAT_INDEX = 0
- -- In seconds, the amount of time to keep a destroyed vehicle spawned
- DESTROY_TIME = 60
- -- True or false, whether you want SAPP to respawn starting vehicles after DESTROY_TIME has elapsed
- RESPAWN_STARTING_VEHICLES = true
- -- First vehicle is the destroyable vehicle, second vehicle is the destroyed variant
- VEHICLES = {
- { "vehicles\\warthog\\mp_warthog", "vehicles\\ghost\\ghost_mp" },
- { "vehicles\\rwarthog\\rwarthog", "vehicles\\banshee\\banshee_mp" },
- }
- -- End of config
- TAG_DATA = {}
- STARTING_VEHICLES = {}
- STARTING_OBJECT_IDS = {}
- GAME_STARTED = false
- GAME_COUNT = 1
- api_version = "1.7.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
- register_callback(cb['EVENT_GAME_START'], "OnGameStart")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_OBJECT_SPAWN'], "OnObjectSpawn")
- end
- function OnPlayerDeath(PlayerIndex)
- local player = get_dynamic_player(PlayerIndex)
- local vehicle = read_dword(player + 0x11C)
- local seatIndex = read_byte(player + 0x2F0)
- local vehicleObject = get_object_memory(vehicle)
- if(vehicleObject ~= 0 and seatIndex == SEAT_INDEX) then
- local destroyedVehicle = nil
- local vehicleName = nil
- local tagDataAddress = read_dword(0x40440000) + read_word(vehicleObject) * 0x20 + 0x14
- local count = 0
- for _,v in pairs(TAG_DATA) do
- count = count + 1
- if(tagDataAddress == v[2]) then
- vehicleName = v[1]
- destroyedVehicle = count
- end
- end
- local startingVehicleIndex = nil
- count = 0
- for _,v in pairs(STARTING_VEHICLES) do
- count = count + 1
- if(vehicle == v[1]) then startingVehicleIndex = count end
- end
- if(destroyedVehicle ~= nil) then
- for i=1,16 do
- if(i ~= PlayerIndex and player_present(i) and player_alive(i)) then
- local tempVehicleID = read_dword(get_dynamic_player(i) + 0x11C)
- if(tempVehicle == vehicle) then kill(i) end
- end
- end
- timer(34, "create_destroyed_vehicle", vehicle, destroyedVehicle)
- if(startingVehicleIndex ~= nil) then
- timer(67 + (1000 * DESTROY_TIME), "respawn_vehicle", startingVehicleIndex, vehicleName, GAME_COUNT)
- end
- end
- end
- end
- function create_destroyed_vehicle(vehicle, destroyedVehicle)
- local vehicleObject = get_object_memory(vehicle)
- if(vehicleObject == 0) then return false end
- local x, y, z = read_vector3d(vehicleObject + 0x5c)
- local a = read_float(vehicleObject + 0x76)
- local b = read_float(vehicleObject + 0x7A)
- local c = read_float(vehicleObject + 0x7E)
- local d = read_float(vehicleObject + 0x82)
- destroy_object(vehicle)
- newVehicleID = spawn_object("vehi", VEHICLES[tonumber(destroyedVehicle)][2], x, y, z, 0)
- newVehicle = get_object_memory(newVehicleID)
- if(newVehicle ~= nil) then
- write_float(newVehicle + 0x76, a)
- write_float(newVehicle + 0x7A, b)
- write_float(newVehicle + 0x7E, c)
- write_float(newVehicle + 0x82, d)
- end
- timer(1000 * DESTROY_TIME, "destroy_vehicle", newVehicleID, GAME_COUNT)
- return false
- end
- function destroy_vehicle(ObjectID, gameCount)
- if(tonumber(gameCount) ~= GAME_COUNT) then return false end
- destroy_object(ObjectID)
- return false
- end
- function respawn_vehicle(startingVehicleIndex, vehicleName, gameCount)
- if(not RESPAWN_STARTING_VEHICLES or tonumber(gameCount) ~= GAME_COUNT) then return false end
- local a = STARTING_VEHICLES[tonumber(startingVehicleIndex)]
- respawnedVehicleID = spawn_object("vehi", vehicleName, a[2], a[3], a[4], 0)
- respawnedVehicle = get_object_memory(respawnedVehicleID)
- if(respawnedVehicle ~= nil) then
- write_float(respawnedVehicle + 0x76, a[5])
- write_float(respawnedVehicle + 0x7A, a[6])
- write_float(respawnedVehicle + 0x7E, a[7])
- write_float(respawnedVehicle + 0x82, a[8])
- STARTING_VEHICLES[tonumber(startingVehicleIndex)][1] = respawnedVehicleID
- end
- return false
- end
- function FindVehicleTag(TagName)
- local tag_array = read_dword(0x40440000)
- for i=0,read_word(0x4044000C)-1 do
- local tag = tag_array + i * 0x20
- if(read_dword(tag) == 1986357353 and read_string(read_dword(tag + 0x10)) == TagName) then
- return tag + 0x14
- end
- end
- end
- function OnGameStart()
- local count = 0
- for _,v in pairs(VEHICLES) do
- count = count + 1
- TAG_DATA[count] = { VEHICLES[count][1], FindVehicleTag(VEHICLES[count][1]) }
- end
- start_vehicle_check()
- end
- function OnGameEnd()
- TAG_DATA = {}
- STARTING_VEHICLES = {}
- STARTING_OBJECT_IDS = {}
- GAME_COUNT = GAME_COUNT + 1
- timer(15000, "reset_game")
- end
- function reset_game()
- GAME_STARTED = false
- return false
- end
- function start_vehicle_check()
- for _,id in pairs(STARTING_OBJECT_IDS) do
- local object = get_object_memory(id)
- if(object ~= 0) then
- if(read_byte(object + 0xB4) == 0x01) then
- local tagDataAddress = read_dword(0x40440000) + read_word(object) * 0x20 + 0x14
- local count = 0
- for _,v in pairs(TAG_DATA) do
- count = count + 1
- if(tagDataAddress == v[2]) then
- local x, y, z = read_vector3d(object + 0x5c)
- local a = read_float(object + 0x76)
- local b = read_float(object + 0x7A)
- local c = read_float(object + 0x7E)
- local d = read_float(object + 0x82)
- table.insert(STARTING_VEHICLES, {id, x, y, z, a, b, c, d})
- end
- end
- end
- end
- end
- STARTING_OBJECT_IDS = {}
- end
- function OnObjectSpawn(PlayerIndex, MapID, ParentID, ObjectID)
- if(RESPAWN_STARTING_VEHICLES and not GAME_STARTED) then
- table.insert(STARTING_OBJECT_IDS, ObjectID)
- end
- return true
- end
- function OnScriptUnload() end
Advertisement
Add Comment
Please, Sign In to add comment