------ MADE BY AMMAR B.------ ----------------------------- -------------------------------------------------- ----------------STOPS AUTO RESPAWN---------------- -------------------------------------------------- AddEventHandler('onClientMapStart', function() exports.spawnmanager:spawnPlayer() Citizen.Wait(3000) exports.spawnmanager:setAutoSpawn(false) end) -------------------------------------------------- ----------------REGISTERING EVENTS---------------- -------------------------------------------------- RegisterNetEvent("DeathScript:Revive") RegisterNetEvent("DeathScript:Respawn") RegisterNetEvent("DeathScript:AdminRevive") RegisterNetEvent("DeathScript:AdminRespawn") RegisterNetEvent("DeathScript:SetReviveTime") RegisterNetEvent("DeathScript:SetRespawnTime") RegisterNetEvent("DeathScript:Toggle") RegisterNetEvent("DeathScript:ShowNotification") RegisterNetEvent("DeathScript:IsPlayerDead") -------------------------------------------------- ----------------DEFINING VARIABLES---------------- -------------------------------------------------- OriginalReviveTime = 150 OriginalRespawnTime = 60 ReviveTime = 150 RespawnTime = 60 ReviveAllowed = false RespawnAllowed = false DeathTime = nil DeathScriptToggle = true respawnCount = 0 spawnPoints = {} -------------------------------------------------- --------------------Death Loop-------------------- -------------------------------------------------- Citizen.CreateThread(function() function createSpawnPoint(x1,x2,y1,y2,z,heading) local xValue = math.random(x1,x2) + 0.0001 local yValue = math.random(y1,y2) + 0.0001 local newObject = { x = xValue, y = yValue, z = z + 0.0001, heading = heading + 0.0001 } table.insert(spawnPoints,newObject) end createSpawnPoint(-448, -448, -340, -329, 35.5, 0) -- Mount Zonah createSpawnPoint(372, 375, -596, -594, 30.0, 0) -- Pillbox Hill createSpawnPoint(335, 340, -1400, -1390, 34.0, 0) -- Central Los Santos createSpawnPoint(1850, 1854, 3700, 3704, 35.0, 0) -- Sandy Shores createSpawnPoint(-247, -245, 6328, 6332, 33.5, 0) -- Paleto while true do Citizen.Wait(5000) local ped = PlayerPedId() if IsEntityDead( ped ) then if DeathScriptToggle then DeathTime = GetGameTimer() SetPlayerInvincible( ped, true ) SetEntityHealth( ped, 1 ) local reviveMessage = nil local respawnMessage = nil if ReviveTime > 0 then ReviveTime = ReviveTime - 5 --exports['EGRP-Notifications']:CaptionIcon("System", "You can revive in "..ReviveTime.." seconds!", "top", 3000, "dark", "", true, "mdi-medical-bag") reviveMessage = "You can revive in "..ReviveTime.." seconds!" else ReviveAllowed = true --exports['EGRP-Notifications']:CaptionIcon("System", "You can revive now!", "top", 3000, "dark", "", true, "mdi-medical-bag") reviveMessage = "You can /revive now!" end if RespawnTime > 0 then RespawnTime = RespawnTime - 5 --exports['EGRP-Notifications']:CaptionIcon("System", "You can respawn in "..RespawnTime.." seconds!", "top", 3000, "dark", "", true, "mdi-truck-plus") respawnMessage = "You can respawn in "..RespawnTime.." seconds!" else RespawnAllowed = true --exports['EGRP-Notifications']:CaptionIcon("System", "You can respawn now!", "top", 3000, "dark", "", true, "mdi-truck-plus") respawnMessage = "You can /respawn now!" end if ReviveAllowed and RespawnAllowed then exports['EGRP-Notifications']:Info("System", ""..reviveMessage.." "..respawnMessage.."", "top", 3000, true) elseif ReviveAllowed and not RespawnAllowed then exports['EGRP-Notifications']:Info("System", ""..reviveMessage.."", "top", 3000, true) exports['EGRP-Notifications']:CaptionIcon("System", ""..respawnMessage.."", "top", 3000, "dark", "", true, "mdi-medical-bag") elseif not ReviveAllowed and RespawnAllowed then exports['EGRP-Notifications']:Info("System", ""..respawnMessage.."", "top", 3000, true) exports['EGRP-Notifications']:CaptionIcon("System", ""..reviveMessage.."", "top", 3000, "dark", "", true, "mdi-medical-bag") elseif not ReviveAllowed and not RespawnAllowed then exports['EGRP-Notifications']:CaptionIcon("System", ""..reviveMessage.." "..respawnMessage.."", "top", 3000, "dark", "", true, "mdi-medical-bag") end --ShowNotification( respawnMessage .. '\n' .. reviveMessage ) else respawnPed( ped, spawnPoints[math.random(1,#spawnPoints)] ) end end end end) -------------------------------------------------- -----------------EVENT HANDLERS------------------ -------------------------------------------------- AddEventHandler("DeathScript:Revive", function( adrev, admin, all) local ped = PlayerPedId() if adrev then ReviveAllowed = true end if all then revivePed( ped ) resetTimers() exports['EGRP-Notifications']:Success("System", "You have been revived by an admin!", "top", 5000, true) --ShowNotification("~g~You have been revived by an admin!") return; end if GetEntityHealth( ped ) <= 1 then --if you are dead if ReviveAllowed then -- if timer is complete allow revive -- revivePed( ped ) resetTimers() if adrev then exports['EGRP-Notifications']:Success("System", "You have been revived by an admin!", "top", 5000, true) --ShowNotification("~g~You have been revived by an admin!") --TriggerServerEvent('DeathScript:AdminReturn', admin) end else exports['EGRP-Notifications']:CaptionIcon("System", "You can revive in "..ReviveTime.." seconds!", "top", 3000, "dark", "", true, "mdi-medical-bag") --ShowNotification("~r~" .. ReviveTime .. ' seconds remaining until revive!') end else if adrev then --TriggerServerEvent('DeathScript:AdminReturn', admin) exports['EGRP-Notifications']:Negative("System", "You can't revive yourself when you're alive!", "top", 3000, true) --ShowNotification("~g~You're alive!") end end end) AddEventHandler("DeathScript:Respawn", function( adres, admin, all) local ped = PlayerPedId() if adres then RespawnAllowed = true end if all then respawnPed( ped, spawnPoints[math.random(1,#spawnPoints)] ) resetTimers() exports['EGRP-Notifications']:Success("System", "You have been respawned by an admin!", "top", 5000, true) --ShowNotification("~g~You have been respawned by an admin!") return; end if GetEntityHealth( ped ) <= 1 then --if you are dead if RespawnAllowed then -- if timer is complete allow revive -- respawnPed( ped, spawnPoints[math.random(1,#spawnPoints)] ) resetTimers() if adres then exports['EGRP-Notifications']:Success("System", "You have been respawned by an admin!", "top", 5000, true) --ShowNotification("~g~You have been respawned by an admin!") --TriggerServerEvent('DeathScript:AdminReturn', admin) end else exports['EGRP-Notifications']:CaptionIcon("System", "You can respawn in "..RespawnTime.." seconds!", "top", 3000, "dark", "", true, "mdi-medical-bag") --ShowNotification("~r~" .. RespawnTime .. ' seconds remaining until respawn!') end else if adres then --TriggerServerEvent('DeathScript:AdminReturn', admin) else exports['EGRP-Notifications']:Negative("System", "You can't respawn when you're alive!", "top", 3000, true) --ShowNotification("~g~You're alive!") end end end) AddEventHandler('DeathScript:Toggle', function() DeathScriptToggle = not DeathScriptToggle if (DeathScriptToggle) then exports['EGRP-Notifications']:Success("System", "RP-Death has been enabled!", "top", 3000, true) --ShowNotification("~b~DeathScript was enabled") else exports['EGRP-Notifications']:Negative("System", "RP-Death has been disabled!", "top", 3000, true) --ShowNotification("~r~DeathScript was disabled") end end) AddEventHandler('DeathScript:ShowNotification', function( str ) ShowNotification( str ) end) -------------------------------------------------- --------------------FUNCTIONS--------------------- -------------------------------------------------- function resetTimers() ReviveTime = OriginalReviveTime RespawnTime = OriginalRespawnTime ReviveAllowed = false RespawnAllowed = false end