Open elainetan993 opened 4 years ago
I've tried
AddEventHandler("esx_xp:rankUp", function(newRank, previousRank) if newRank == 10 then TriggerClientEvent("esx_vehicleshop:claimCar", source) end end)
But its not working when player level up.
There's a problem with rankUp event not being triggered in the current version.
Fix:
diff --git a/resources/[esx]/esx_xp/client/main.lua b/resources/[esx]/esx_xp/client/main.lua
index 062bbbe..4e631b7 100644
--- a/resources/[esx]/esx_xp/client/main.lua
+++ b/resources/[esx]/esx_xp/client/main.lua
@@ -114,9 +114,15 @@ AddEventHandler("esx_xp:update", function(_xp, _rank)
CurrentXP = newXP
CurrentRank = newRank
+ if newRank > oldRank then
+ TriggerEvent("esx_xp:rankUp", newRank, oldRank)
+ elseif newRank < oldRank then
+ TriggerEvent("esx_xp:rankDown", newRank, oldRank)
+ end
+
-- Set ESX properties
ESX.SetPlayerData("xp", CurrentXP)
- ESX.SetPlayerData("rank", CurrentRank)
+ ESX.SetPlayerData("rank", CurrentRank)
end)
With this fix rankUp is fired properly and your code should work 😉
@Mobius1 : RankUp seemed to be triggered via NUI, but this does not seem to work? Create PR for fix above?
There's a problem with rankUp event not being triggered in the current version.
Fix:
diff --git a/resources/[esx]/esx_xp/client/main.lua b/resources/[esx]/esx_xp/client/main.lua index 062bbbe..4e631b7 100644 --- a/resources/[esx]/esx_xp/client/main.lua +++ b/resources/[esx]/esx_xp/client/main.lua @@ -114,9 +114,15 @@ AddEventHandler("esx_xp:update", function(_xp, _rank) CurrentXP = newXP CurrentRank = newRank + if newRank > oldRank then + TriggerEvent("esx_xp:rankUp", newRank, oldRank) + elseif newRank < oldRank then + TriggerEvent("esx_xp:rankDown", newRank, oldRank) + end + -- Set ESX properties ESX.SetPlayerData("xp", CurrentXP) - ESX.SetPlayerData("rank", CurrentRank) + ESX.SetPlayerData("rank", CurrentRank) end)
With this fix rankUp is fired properly and your code should work 😉
@Mobius1 : RankUp seemed to be triggered via NUI, but this does not seem to work? Create PR for fix above?
Thank you! I'll give it a try!
I've inserted my event handlers in the server.lua. I wonder if im doing it wrong.
AddEventHandler("esx_xp:rankUp", function(newRank, previousRank) if newRank == 10 then TriggerClientEvent("esx_vehicleshop:claimCar", source) end end)
Hi, do you have any example on a leveling reward system? Or a template for me to follow?