It was working fine before, but now it just stopped working.
The error I get is:
[B]Hook 'statThink' Failed: [gamemodes\herbrp\gamemode\player.lua:115] attempt to index global 'player' (a nil value)[/B]
serverside:
[lua]
function statThink()
for k, ply in pairs( player.GetAll() ) do
if ply:KeyDown(IN_SPEED) && ply:GetNWInt( "plyStamina" ) >= 0 && ply:GetNWBool("plyTired") == false then
local newStamina = ply:GetNWInt( "plyStamina" ) - 0.1
ply:SetNWInt( "plyStamina", newStamina )
elseif ply:GetNWInt( "plyStamina" ) < 100 && ply:Health() > 0 then
local newStaminaRegen = ply:GetNWInt( "plyStamina" ) + 0.05
ply:SetNWInt( "plyStamina", newStaminaRegen )
if newStaminaRegen >= 48 then
if newStaminaRegen <= 52 then
ply:SetNWBool("plyTired", false)
end
end
end
if( ply:Health() <= 0 ) then
ply:SetNWInt( "plyStamina", 0 )
end
if ply:KeyDown(IN_JUMP) && ply:GetNWInt( "plyStamina" ) >= 10 && ply:GetNWBool("plyTired") == false && !ply:KeyDownLast( IN_JUMP ) then
local newStaminaJump = ply:GetNWInt( "plyStamina" ) - 10
ply:SetNWInt( "plyStamina", newStaminaJump )
end
if ply:GetNWInt( "plyStamina" ) <= 1 then
ply:SetNWBool("plyTired", true)
end
if ply:GetNWBool("plyTired") == false then
ply:SetWalkSpeed( walkSpeed )
ply:SetRunSpeed( runSpeed )
ply:SetJumpPower( jumpSpeed )
end
if ply:GetNWBool("plyTired") == true then
ply:SetWalkSpeed( walkSpeed )
ply:SetRunSpeed( walkSpeed )
ply:SetJumpPower( 0 )
end
if ply:GetNWInt("plyHunger") <= 0 then
if ply:Health() > 0 then
ply:Kill()
end
end
end
end
hook.Add( "Think", "statThink", statThink )
[/lua]
We don't know what line 115 is, nobody can help.
Is this file shared, client or server?
Have you accidentally overrode the the player library somehow, although I'm pretty sure if you did, it would break like.. everything.
Sorry, line 115 is:
[lua]
for k, ply in pairs( player.GetAll() ) do
[/lua]
[editline]17th March 2012[/editline]
This error is happening everywhere where I have a for statement like this. It was all working perfect before but now it just says that player is nil.
The way you're explaining this makes me think you accidentally overrode the player library somehow.
go ingame, create multiplayer and execute this:
[lua]lua_run print( player.GetByID(1):Nick() )[/lua]
tell me results.
[QUOTE=LauScript;35171936]The way you're explaining this makes me think you accidentally overrode the player library somehow.
go ingame, create multiplayer and execute this:
[lua]lua_run print( player.GetByID(1):Nick() )[/lua]
tell me results.[/QUOTE]
[B][lua_run:1] attempt to index global 'player' (a nil value)[/B]
If I did somehow override the player library, what kind of code would do that so that I can try and find any existence of such code in my project?
yeah what the fuck i have no idea what you did. You need to see if you made a variable under the name player, such as like
player = {};
player = bla;
something that would fuck it up like that, there is no other explanation.
[editline]17th March 2012[/editline]
after looking at your other help thread, i noticed you set the global variable player to a activator entity, you clearly have no idea how variable scoping works and you need to research it and understand it before you go any further into scripting this gamemode.
I did find out where I did that, I actually set player to nil because I planned on using player for something else. I changed the name to currentPlayer.
Thank you very much for the help.
well that's another instance of it breaking, your "item dragging" thing will break it again, believe me, you
[b]NEED[/b]
to look up what scopes are, you absolutely have to know how they work in order to script properly. Ask any coder anywhere, for any language.
Alright, I will look them up. Thanks for the help!
Sorry, you need to Log In to post a reply to this thread.