You’re using a global variable for fuel, so anyone using this item will use the global amount of fuel available.
Suggest you do ply.JumpPackFuel = 100 in the OnEquip or OnBuy function and then replace all instances of the fuel variable in the Think function with ply.JumpPackFuel, and remove the fuel variable.
fuel it’s not initialized yet
Before of working on fuel property, you must initialize it like (ply.fuel or 0) because when fuel it’s nil, this will add x to 0 due fuel it’s not initialized, anyway, you can
[lua]if ply.fuel == nil then ply.fuel = 100 end[/lua]
or
[lua]ply.fuel = (ply.fuel or 100) - x[/lua]
Remember that think it’s called 66 times (By default) on server, 10 it’s too much, use 0.125 or something like that
I’d check if the player is alive before running code in the think function.
The ITEM:Think function and the ITEM:OnEquip function are not in the same realm. ITEM:OnEquip is serverside and ITEM:Think is clientside.
You cannot set a ply.fuel serverside and expect the client can read it clientside. You could use network variables, but that would be stupid to use in a think function. So you would probably want to make your own think hook serverside.
Also the way your think function is set up, you will be out of fuel in less than a second.
So the Think function is SHARED? If so he should probably create a boolean variable in the ITEM:OnEquip to set it to true and if the player leaves or unequips it then set it to true, and it should be a self variable like self.IsEquipped
function ITEM:Think(ply, modifications)
if not ply.JumpPackFuel then
ply.JumpPackFuel = 100
ply.JumpPackMaxFuel = 100
end
if ply:KeyDown(IN_FORWARD) and ply.JumpPackFuel > 10 and ply:KeyDown(IN_JUMP) then
if SERVER then ply:SetVelocity(ply:GetAimVector() * 50 ) end
ply.JumpPackFuel = ply.JumpPackFuel - 5
end
if ply:KeyDown(IN_BACK) and ply.JumpPackFuel > 10 and ply:KeyDown(IN_JUMP) then
if SERVER then ply:SetVelocity(ply:GetAimVector() * -1 * 50) end
ply.JumpPackFuel = ply.JumpPackFuel - 5
end
if ply:KeyDown(IN_MOVELEFT) and ply.JumpPackFuel > 10 and ply:KeyDown(IN_JUMP) then
if SERVER then ply:SetVelocity((ply:EyeAngles():Right() * -1) * 50) end
ply.JumpPackFuel = ply.JumpPackFuel - 5
end
if ply:KeyDown(IN_MOVERIGHT) and ply.JumpPackFuel > 10 and ply:KeyDown(IN_JUMP) then
if SERVER then ply:SetVelocity(ply:EyeAngles():Right() * 50) end
ply.JumpPackFuel = ply.JumpPackFuel - 5
end
if ply.JumpPackFuel < ply.JumpPackMaxFuel and not ply:KeyDown(IN_JUMP) then
ply.JumpPackFuel = ply.JumpPackFuel + 0.5
end
end
function ITEM:HUDPaint(ply, modifications)
if ply.JumpPackFuel then
draw.DrawText(ply.JumpPackFuel, “TargetID”, ScrW() * 0.5, ScrH() * 0.25, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
end
end
[/lua]
This works. And I added a counter for the fuel left, you can tidy it up yourself if you want to keep it.