From f48f9341027858043e74cb71affb40256c5c8a45 Mon Sep 17 00:00:00 2001 From: nearbyplayer Date: Mon, 21 Aug 2017 09:26:32 -0400 Subject: [PATCH] Adds new timer --- client/main.lua | 132 ++++++++++++++++++++++++++++++++++++++++++++++-- config.lua | 4 ++ locales/br.lua | 8 +++ locales/en.lua | 8 +++ locales/fr.lua | 8 +++ server/main.lua | 47 +++++++++++++++-- 6 files changed, 198 insertions(+), 9 deletions(-) diff --git a/client/main.lua b/client/main.lua index cc574eb7..4347ba4e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -118,12 +118,117 @@ function StartRespawnTimer() StopScreenEffect('DeathFailOut') DoScreenFadeIn(800) end) - end) end - end) +end +function RespawnTimer() + +local timer = Config.RespawnDelayAfterRPDeath +local allowRespawn = Config.RespawnDelayAfterRPDeath/2 +local enoughMoney = false +local money = 0 + + if IsDead and Config.ShowDeathTimer then + ESX.TriggerServerCallback('esx_ambulancejob:getBankMoney', function(money) + if money >= Config.EarlyRespawnFineAmount then + enoughMoney = true + else + enoughMoney = false + end + end) + Citizen.CreateThread(function() + + while timer > 0 and IsDead do + raw_seconds = timer/1000 + raw_minutes = raw_seconds/60 + minutes = stringsplit(raw_minutes, ".")[1] + seconds = stringsplit(raw_seconds-(minutes*60), ".")[1] + + if Config.EarlyRespawn and Config.EarlyRespawnFine and enoughMoney then + SetTextFont(4) + SetTextProportional(0) + SetTextScale(0.0, 0.5) + SetTextColour(255, 255, 255, 255) + SetTextDropshadow(0, 0, 0, 0, 255) + SetTextEdge(1, 0, 0, 0, 255) + SetTextDropShadow() + SetTextOutline() + SetTextEntry("STRING") + AddTextComponentString(_U('please_wait') .. minutes .. _U('minutes') .. seconds .. _U('seconds_fine') .. Config.EarlyRespawnFineAmount .. _U('press_respawn_fine')) + SetTextCentre(true) + DrawText(0.5, 0.8) + timer = timer - 15 + Citizen.Wait(0) + if IsControlPressed(0, Keys['E']) then + DoScreenFadeOut(800) + + while not IsScreenFadedOut() do + Citizen.Wait(0) + end + + ESX.TriggerServerCallback('esx_ambulancejob:removeItemsAfterRPDeathRemoveMoney', function() + + TriggerServerEvent('esx_ambulancejob:removeAccountMoney', source) + TriggerServerEvent('esx:updateLastPosition', Config.Zones.HospitalInteriorInside1.Pos) + + RespawnPed(GetPlayerPed(-1), Config.Zones.HospitalInteriorInside1.Pos) + StopScreenEffect('DeathFailOut') + DoScreenFadeIn(800) + end) + end + else + SetTextFont(4) + SetTextProportional(0) + SetTextScale(0.0, 0.5) + SetTextColour(255, 255, 255, 255) + SetTextDropshadow(0, 0, 0, 0, 255) + SetTextEdge(1, 0, 0, 0, 255) + SetTextDropShadow() + SetTextOutline() + SetTextEntry("STRING") + AddTextComponentString(_U('please_wait') .. minutes .. _U('minutes') .. seconds .. _U('seconds')) + SetTextCentre(true) + DrawText(0.5, 0.8) + timer = timer - 15 + Citizen.Wait(0) + end + end + + while timer <= 0 and IsDead do + SetTextFont(4) + SetTextProportional(0) + SetTextScale(0.0, 0.5) + SetTextColour(255, 255, 255, 255) + SetTextDropshadow(0, 0, 0, 0, 255) + SetTextEdge(1, 0, 0, 0, 255) + SetTextDropShadow() + SetTextOutline() + SetTextEntry("STRING") + AddTextComponentString(_U('press_respawn')) + SetTextCentre(true) + DrawText(0.5, 0.8) + Citizen.Wait(0) + if IsControlPressed(0, Keys['E']) then + DoScreenFadeOut(800) + + while not IsScreenFadedOut() do + Citizen.Wait(0) + end + + ESX.TriggerServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function() + + TriggerServerEvent('esx:updateLastPosition', Config.Zones.HospitalInteriorInside1.Pos) + + RespawnPed(GetPlayerPed(-1), Config.Zones.HospitalInteriorInside1.Pos) + --StopScreenEffect('DeathFailOut') + DoScreenFadeIn(800) + end) + end + end + end) + end end function TeleportFadeEffect(entity, coords) @@ -531,10 +636,14 @@ AddEventHandler('esx_ambulancejob:onPlayerDeath', function() IsDead = true - StartRespawnTimer() - StartRespawnToHospitalMenuTimer() + if Config.ShowDeathTimer == true then + RespawnTimer() + else + StartRespawnTimer() + StartRespawnToHospitalMenuTimer() + StartScreenEffect('DeathFailOut', 0, false) + end - StartScreenEffect('DeathFailOut', 0, false) end) RegisterNetEvent('esx_ambulancejob:revive') @@ -745,3 +854,16 @@ Citizen.CreateThread(function() EnableMpDlcMaps(true) RequestIpl('Coroner_Int_on') -- Morgue end) + +-- String string +function stringsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + t[i] = str + i = i + 1 + end + return t +end diff --git a/config.lua b/config.lua index 8e1b8a90..f795fc7c 100644 --- a/config.lua +++ b/config.lua @@ -7,6 +7,10 @@ Config.RemoveWeaponsAfterRPDeath = true Config.RemoveCashAfterRPDeath = true Config.RemoveItemsAfterRPDeath = true Config.EnablePlayerManagement = false +Config.ShowDeathTimer = true +Config.EarlyRespawn = true +Config.EarlyRespawnFine = true +Config.EarlyRespawnFineAmount = 500 Config.Locale = 'fr' Config.Zones = { diff --git a/locales/br.lua b/locales/br.lua index a56396c1..494baed3 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -35,4 +35,12 @@ Locales['br'] = { -- Death ['respawn_at_hospital'] = 'você quer ser transportado para o hospital?', ['yes'] = 'sim', + ['please_wait'] = 'por favor, espere ~b~', + ['minutes'] = ' minutos ', + ['seconds_fine'] = ' segundos ~w~para respawn | Respawn agora para ~g~$', + ['seconds'] = ' segundos ~w~para respawn.', + ['press_respawn_fine'] = '~w~ [Pressione ~b~E~w~]', + ['press_respawn'] = 'pressione [~b~E~w~] para respawn.', + -- Revive + ['revive_help'] = 'reviver um jogador', } diff --git a/locales/en.lua b/locales/en.lua index fa8ddfce..4c86edfc 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -35,4 +35,12 @@ Locales['en'] = { -- Death ['respawn_at_hospital'] = 'do you want to be transported to the hospital?', ['yes'] = 'yes', + ['please_wait'] = 'please wait ~b~', + ['minutes'] = ' minutes ', + ['seconds_fine'] = ' seconds ~w~to respawn | Respawn now for ~g~$', + ['seconds'] = ' seconds ~w~to respawn.', + ['press_respawn_fine'] = '~w~ [Press ~b~E~w~]', + ['press_respawn'] = 'press [~b~E~w~] to respawn.', + -- Revive + ['revive_help'] = 'revive a player', } diff --git a/locales/fr.lua b/locales/fr.lua index c276c069..877b06e2 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -35,4 +35,12 @@ Locales['fr'] = { -- Death ['respawn_at_hospital'] = 'voulez-vous être transporté à l\'hôpital ?', ['yes'] = 'oui', + ['please_wait'] = 's\'il vous plaît, attendez ~b~', + ['minutes'] = ' minutes ', + ['seconds_fine'] = ' secondes ~w~to réapparaître | Réapparaître maintenant pour ~g~$', + ['seconds'] = ' secondes ~w~pour réapparaître.', + ['press_respawn_fine'] = '~w~ [Presse ~b~E~w~]', + ['press_respawn'] = 'appuyez [~b~E~w~] sur pour réapparaître.', + -- Revive + ['revive_help'] = 'relancer un joueur', } diff --git a/server/main.lua b/server/main.lua index 7b9b4870..296d8bd7 100644 --- a/server/main.lua +++ b/server/main.lua @@ -34,6 +34,45 @@ ESX.RegisterServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function( end) +ESX.RegisterServerCallback('esx_ambulancejob:removeItemsAfterRPDeathRemoveMoney', function(source, cb) + + local xPlayer = ESX.GetPlayerFromId(source) + + if Config.RemoveCashAfterRPDeath then + xPlayer.set('money', 0) + xPlayer.setAccountMoney('black_money', 0) + end + + if Config.EarlyRespawn and Config.EarlyRespawnFine then + xPlayer.removeAccountMoney('bank', Config.EarlyRespawnFineAmount) + end + + if Config.RemoveItemsAfterRPDeath then + for i=1, #xPlayer.inventory, 1 do + if xPlayer.inventory[i].count > 0 then + xPlayer.setInventoryItem(xPlayer.inventory[i].name, 0) + end + end + end + + if Config.RemoveWeaponsAfterRPDeath then + for i=1, #xPlayer.loadout, 1 do + xPlayer.removeWeapon(xPlayer.loadout[i].name) + end + end + + cb() + +end) + +ESX.RegisterServerCallback('esx_ambulancejob:getBankMoney', function(source, cb) + + local xPlayer = ESX.GetPlayerFromId(source) + local money = xPlayer.getAccount('bank').money + + cb(money) +end) + TriggerEvent('esx_phone:registerCallback', function(source, phoneNumber, message, anon) local xPlayer = ESX.GetPlayerFromId(source) @@ -48,11 +87,11 @@ TriggerEvent('esx_phone:registerCallback', function(source, phoneNumber, message end end end - + end) -TriggerEvent('es:addGroupCommand', 'respawn', 'admin', function(source, args, user) - +TriggerEvent('es:addGroupCommand', 'revive', 'admin', function(source, args, user) + if args[2] ~= nil then TriggerClientEvent('esx_ambulancejob:revive', tonumber(args[2])) else @@ -61,4 +100,4 @@ TriggerEvent('es:addGroupCommand', 'respawn', 'admin', function(source, args, us end, function(source, args, user) TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.") -end, {help = 'Respawn', params = {{name = 'id'}}}) \ No newline at end of file +end, {help = _U('revive_help'), params = {{name = 'id'}}})