Skip to content

Commit

Permalink
Merge pull request #905 from bitpredator/dev
Browse files Browse the repository at this point in the history
chore: minor change in es_extended
  • Loading branch information
bitpredator authored Dec 1, 2024
2 parents f74b8c1 + fd53706 commit 88194b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,44 +171,6 @@ local placeHolders = {
end,
}

function Adjustments:PresencePlaceholders()
local presence = Config.DiscordActivity.presence

for placeholder, cb in pairs(placeHolders) do
local success, result = pcall(cb)

if not success then
error(("Failed to execute presence placeholder: ^5%s^7"):format(placeholder))
error(result)
return "Unknown"
end

presence = presence:gsub(("{%s}"):format(placeholder), result)
end

return presence
end

function Adjustments:DiscordPresence()
if Config.DiscordActivity.appId ~= 0 then
CreateThread(function()
while true do
SetDiscordAppId(Config.DiscordActivity.appId)
SetDiscordRichPresenceAsset(Config.DiscordActivity.assetName)
SetDiscordRichPresenceAssetText(Config.DiscordActivity.assetText)

for i = 1, #Config.DiscordActivity.buttons do
local button = Config.DiscordActivity.buttons[i]
SetDiscordRichPresenceAction(i - 1, button.label, button.url)
end

SetRichPresence(self:PresencePlaceholders())
Wait(Config.DiscordActivity.refresh)
end
end)
end
end

function Adjustments:WantedLevel()
if not Config.EnableWantedLevel then
ClearPlayerWantedLevel(ESX.playerId)
Expand Down Expand Up @@ -236,7 +198,6 @@ function Adjustments:Load()
self:DispatchServices()
self:NPCScenarios()
self:LicensePlates()
self:DiscordPresence()
self:WantedLevel()
self:DisableRadio()
end
39 changes: 13 additions & 26 deletions server-data/resources/[esx]/es_extended/client/modules/death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Death:ByPlayer()
TriggerServerEvent("esx:onPlayerDeath", data)
end

function Death:Natual()
function Death:Natural()
local coords = GetEntityCoords(ESX.PlayerData.ped)

local data = {
Expand All @@ -43,25 +43,7 @@ function Death:Natual()
TriggerServerEvent("esx:onPlayerDeath", data)
end

function Death:Damaged(victim, victimDied)
if not victimDied then
return
end

if not IsEntityAPed(victim) then
return
end

if not IsPedAPlayer(victim) then
return
end

local victimId = NetworkGetPlayerIndexFromPed(victim)
local isDead = IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)
if victimId ~= ESX.playerId or not isDead then
return
end

function Death:Died()
self.killerEntity = GetPedSourceOfDeath(ESX.PlayerData.ped)
self.deathCause = GetPedCauseOfDeath(ESX.PlayerData.ped)
self.killerId = NetworkGetPlayerIndexFromPed(self.killerEntity)
Expand All @@ -72,15 +54,20 @@ function Death:Damaged(victim, victimDied)
if self.killerEntity ~= ESX.PlayerData.ped and self.killerId and isActive then
self:ByPlayer()
else
self:Natual()
self:Natural()
end

self:ResetValues()
end

AddEventHandler("gameEventTriggered", function(event, data)
if event ~= "CEventNetworkEntityDamage" then
return
end
Death:Damaged(data[1], data[4])
AddEventHandler("esx:onPlayerSpawn", function()
Citizen.CreateThreadNow(function()
while not ESX.PlayerData.dead do
if IsPedDeadOrDying(ESX.PlayerData.ped, true) or IsPedFatallyInjured(ESX.PlayerData.ped) then
Death:Died()
break
end
Citizen.Wait(250)
end
end)
end)
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,3 @@ Config.RemoveHudComponents = {
--Any other character will lead to said character being emitted.
-- A string shorter than 8 characters will be padded on the right.
Config.CustomAIPlates = "........" -- Custom plates for AI vehicles

--[[
PlaceHolders:
{server_name} - Server Display Name
{server_endpoint} - Server IP:Server Port
{server_players} - Current Player Count
{server_maxplayers} - Max Player Count
{player_name} - Player Name
{player_rp_name} - Player RP Name
{player_id} - Player ID
{player_street} - Player Street Name
]]

Config.DiscordActivity = {
appId = 0, -- Discord Application ID,
assetName = "LargeIcon", --image name for the "large" icon.
assetText = "{server_name}", -- Text to display on the asset
buttons = {
{ label = "Join Server", url = "fivem://connect/{server_endpoint}" },
{ label = "Discord", url = "https://discord.esx-framework.org" },
},
presence = "{player_name} [{player_id}] | {server_players}/{server_maxplayers}",
refresh = 1 * 60 * 1000, -- 1 minute
}

0 comments on commit 88194b7

Please sign in to comment.