New to Fivem

Hi, im new to Fivem server development and im trying to self teach. im going through the fivem documentation and in my attempt to learn im wanted to make a simple script on giving myself infinite stamina. Here is what i have so far, but it is not working. The command is registering but i am not getting max stamina. what am i doing wrong?

RegisterCommand('maxstam', function ()
   local player = PlayerId()
   local stamina = GetPlayerStamina(player)
   if stamina < 100 then stamina = 100 
   end
   print(json.encode(stamina))
end)

ok stamina = 100
but you need to apply the change

local player = PlayerId()
RestorePlayerStamina(player, 10.0)

its if you need make it once

local player = PlayerId()
CreateThread(function()
	while true do
		Wait(1000)
		RestorePlayerStamina(player, 10.0)
	end
end)

restore every 1 second

Your issue is that you’re using the native to Get stamina and trying to assign it stamina = 100 to 100, which obviously won’t work.

Thanks, for the help, i have a long way to go with this

1 Like

With FiveM you will be using a Lua environment, not a C environment. The simplest way I can describe the issue you had is, you expected the value returned from the Get function to be the actual value or a reference directly to the value you want to change, when it is actually just a new value that is equal to the value you want to change. Your “stamina” variable is just a local reading of the memory value, not the acutal memory value, so you can not change it by setting it equal to something else, there is a function you will call to make that memory value change. I hope I explained that well…

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