Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lfuelling committed May 9, 2020
0 parents commit e70fd53
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea
*.iml
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# esx_nicedeath

ESX plugin that makes death a little bit more configurable.

This plugin has the following features:

- Enables the death screen and let's you see the ragdolling
- Configurable respawn cooldown
- Weapons, Items, Cash can be removed on death (but also kept)
- Configurable respawn location (mt. zonah by default)

## Installation

1. Download this repo into your `resources/[esx/]` folder
2. Add `start esx_nicedeath` to your `server.cfg`
3. Modify `spawnmanager` to disable death spawn:
1. find `resources/[managers]/spawnmanager/spawnmanager.lua`
2. replace line 345
- Old: `if (diedAt and (math.abs(GetTimeDifference(GetGameTimer(), diedAt)) > 2000)) or respawnForced then`
- New: `if respawnForced then`
3. Remember to redo this once you update the `server-data` repo!



119 changes: 119 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
ESX = nil
local isDead = false

--- Thread to get the ESX object
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)
Citizen.Wait(0)
end
end)

--- Utility function that starts the respawn timer
function StartRespawnTimer()
local respawnTimer = ESX.Math.Round(Config.RespawnTimer / 1000)
Citizen.CreateThread(function()
-- respawn timer
while respawnTimer > 0 and isDead do
Citizen.Wait(1000)

if respawnTimer > 0 then
respawnTimer = respawnTimer - 1
end
end
end)
Citizen.CreateThread(function()
local text, timeHeld
while isDead do
Citizen.Wait(0)
if respawnTimer > 0 then
text = _U('respawn_available_in', formatTimer(respawnTimer))
drawText(text)
else
text = _U('respawn_prompt')
if IsControlPressed(0, 38) and timeHeld > 60 then
doRespawn()
break
end
if IsControlPressed(0, 38) then
timeHeld = timeHeld + 1
else
timeHeld = 0
end
drawText(text)
end
end
end)
end

--- Utility function that does the respawn logic
function doRespawn()
Citizen.CreateThread(function()
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
Citizen.Wait(10)
end
ESX.TriggerServerCallback('esx_nicedeath:onDeath', function()
ESX.SetPlayerData('loadout', {})
RespawnPed(PlayerPedId(), Config.RespawnPoint.coords, Config.RespawnPoint.heading)
StopScreenEffect('DeathFailOut')
DoScreenFadeIn(800)
end)
end)
end

--- Utility function to respawn a ped
function RespawnPed(ped, coords, heading)
SetEntityCoordsNoOffset(ped, coords.x, coords.y, coords.z, false, false, false, true)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, heading, true, false)
SetPlayerInvincible(ped, false)
ClearPedBloodDamage(ped)

TriggerServerEvent('esx:onPlayerSpawn')
TriggerEvent('esx:onPlayerSpawn')
TriggerEvent('playerSpawned') -- compatibility with old scripts, should be removed soon
end

--- Utility function to draw text on the screen
function drawText(text)
SetTextFont(4)
SetTextScale(0.0, 0.5)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextCentre(true)
SetTextEntry('STRING')
AddTextComponentString(text)
DrawText(0.5, 0.8)
end

--- Utility function to format the countdown to mm:ss
function formatTimer(seconds)
local seconds = tonumber(seconds)

if seconds <= 0 then
return 0, 0
else
local hours = string.format('%02.f', math.floor(seconds / 3600))
local mins = string.format('%02.f', math.floor(seconds / 60 - (hours * 60)))
local secs = string.format('%02.f', math.floor(seconds - hours * 3600 - mins * 60))

return mins, secs
end
end

--- Respawn event handler
AddEventHandler('esx:onPlayerSpawn', function()
isDead = false
end)

--- Death event handler
AddEventHandler('esx:onPlayerDeath', function(data)
isDead = true
ESX.UI.Menu.CloseAll()
StartRespawnTimer()
StartScreenEffect('DeathFailOut', 0, false)
end)
10 changes: 10 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Config = {}

Config.Locale = 'en'

Config.RespawnTimer = 10000 -- time in milliseconds (10s by default)
Config.RespawnPoint = {coords = vector3(-498.24, -335.85, 34.5), heading = 260.3}

Config.KeepWeapons = true
Config.RemoveCash = false
Config.RemoveItems = false
24 changes: 24 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fx_version 'adamant'

game 'gta5'

name 'esx_nicedeath'
description 'esx death fx and cooldown'

version '1.0.0'

server_scripts {
'config.lua',
'server/main.lua',
}

client_scripts {
'@es_extended/locale.lua',
'locales/en.lua',
'config.lua',
'client/main.lua',
}

dependencies {
'es_extended',
}
5 changes: 5 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales['en'] = {
['respawn_available_in'] = 'respawn available in ~b~%s minutes %s seconds~s~',
['respawn_prompt'] = 'hold [~b~E~s~] to respawn',
}

50 changes: 50 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ESX = nil

--- Event to get the ESX object
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)

--- Death event listener
ESX.RegisterServerCallback('esx_nicedeath:onDeath', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)

if Config.RemoveCash then
if xPlayer.getMoney() > 0 then
xPlayer.removeMoney(xPlayer.getMoney())
end
end

if Config.RemoveItems 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

local weapons = {}
if Config.KeepWeapons then
-- save weapons & restore 3s later to bypass spawnmanager
for i = 1, #xPlayer.getLoadout(), 1 do
table.insert(weapons, xPlayer.getLoadout()[i])
end
Citizen.CreateThread(function()
Citizen.Wait(3000)
for i = 1, #weapons, 1 do
if weapons[i].label ~= nil then
xPlayer.addWeapon(weapons[i].name, weapons[i].ammo)
for j = 1, #weapons[i].components, 1 do
xPlayer.addWeaponComponent(weapons[i].name, weapons[i].components[j])
end
end
end
end)
else
for i = 1, #xPlayer.loadout, 1 do
xPlayer.removeWeapon(xPlayer.getLoadout()[i].name)
end
end

cb()
end)

0 comments on commit e70fd53

Please sign in to comment.