[HELP]FiveM BaseEvents onPlayerKilled

Hi firsty i didnt open the resources and i find this (Problem with creating topics on fivem forum) so please change the category thanks. I want to who kills the player i’ll give the xp but the opposite is happening :frowning: so im dropping the code if you can help me I would be grateful <3
Code (Server)
RegisterNetEvent(“baseevents:onPlayerKilled”)
AddEventHandler(“baseevents:onPlayerKilled”, function(killer, reason)
TriggerClientEvent(‘esx_xp:Add’, source, 1)
end)
Edit : im using onesync legacy

1 Like

Hello, this is a friendly reminder because this is your first time creating a topic (or it has been a while since your last topic) in this category.

Please note that most of the support is provided by the Cfx.re community on a voluntary basis. We ask you to be patient; there is no guarantee we have a solution to your problem(s). To avoid unnecessary/duplicate topics, please browse the forums before creating a topic.

To improve your chances of your issue(s) being solved, please provide as much information as possible about the issue(s) you are having. Also —whenever possible— please use the template given to you when creating a topic.

Thanks for keeping these forums tidy!
:mascot:

When you say “but the opposite is happening”, I’m assuming you mean the victim is getting the XP, not the killer.

If my assumption is correct, your fix is very simple. You are giving XP to “source” and not “killer”. So just replace source with killer and the correct player will receive the XP.

RegisterNetEvent("baseevents:onPlayerKilled")
AddEventHandler("baseevents:onPlayerKilled", function(killer, reason)
TriggerClientEvent('esx_xp:Add', killer, 1)
end)

Thanks for replying but doesnt works the killer. OneSYNC doesnt compitable i think

You could use a event listener on the client side and trigger a server event under certain conditions, Here is the game event for damaging a entity, All you need to do is make sure the victim is a player, that it is actually dead and make sure the culprit is the client, then trigger a server event to add exp, Its a bit of a roundabout system but should work fine with one-sync.

AddEventHandler('gameEventTriggered', function(eventName, args)
    if eventName == 'CEventNetworkEntityDamage' then
        local victim = args[1]
        local culprit = args[2]
        local isDead = args[4] == 1

        if isDead and culprit == PlayerPedId() then
            if NetworkGetPlayerIndexFromPed(victim) ~= -1 then
                --Trigger a server event here to add exp.
            end
        end
    end
end)
1 Like

Okay problem is solved im using esx base and i using esx:onPlayerDeath event. Thanks for replies

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.