Hi i have problem with this script:
function PlayerSpawn(ply)
ply:SetNWInt(“glod”, 100)
end
function hungry()
ply:SetNWInt(“glod”, math.Clamp(ply:GetNWInt(“glod”) - 1))
end
timer.Create( “Atimer”, 5, 0, hungry )
hook.Add(“PlayerSpawn”, “PlayerSpawn”, PlayerSpawn)
This is console:
Timer Error: …he_Middle_Ages\gamemode\modules/HungerMod/player.lua:7: attempt to index global ‘ply’ (a nil value)
Please help me i must do it…
Sorry because its my first script…
“Glod”? Well…
[lua]
local function HungerPlayerSpawn(ply)
ply:SetNWInt(“glod”, 100)
timer.Simple( 5, SubtractHunger, ply )
end
hook.Add(“PlayerSpawn”, “PlayerSpawn”, HungerPlayerSpawn)
function SubtractHunger(ply)
ply:SetNWInt(“glod”, math.Clamp(ply:GetNWInt(“glod”) - 1,0,100))
timer.Simple( 5, SubtractHunger, ply )
end
[/lua]
Is what you want.
Thx but what is wrong im my script? Plz tell me…
I fixed it for you, isn’t that what you want? :sigh:
Because i must know what i doing wrong…
You’re not defining ‘ply’ on your hunger function.
Thx because i have new problem in this script is timer.Simple and when i dead its create next and i have 2x speed hunger…
[lua]
local function HungerPlayerSpawn(ply)
ply:SetNWInt(“glod”, 100)
timer.Simple( 5, SubtractHunger, ply )
end
hook.Add(“PlayerInitalSpawn”, “PlayerSpawn”, HungerPlayerSpawn)
function SubtractHunger(ply)
if ply:Alive() == true then
ply:SetNWInt(“glod”, math.Clamp(ply:GetNWInt(“glod”) - 1,0,100))
end
timer.Simple( 5, SubtractHunger, ply )
end
[/lua]
local function HungerPlayerSpawn(ply)
ply:SetNWInt(“glod”, 100)
timer.Create( “hung_timer” , 10, 0, SubtractHunger, ply )
end
hook.Add(“PlayerSpawn”, “PlayerSpawn”, HungerPlayerSpawn)
function SubtractHunger(ply)
ply:SetNWInt(“glod”, math.Clamp(ply:GetNWInt(“glod”) - 1,0,100))
end
Meybe this?