Its not so much a “is this correct because i can’t be bothered to test it thread” I just see alot of people asking how to disable hunger mod when theres not a cook so I thought I would give it a try and I knwo its not right.
Can someone lead me on the right tracks?
function ActivateMod ()
TEAM_COOK.NumPlayers return //Seems weird and not right
if TEAM_COOK.NumPlayers = 0
then DarkRP.disabledDefaults ["hungermod"] = false
else if TEAM_COOK.NumPlayers => 1
then DarkRP.disabledDefaults ["hungermod"] = true
end
end
end
//INSERT HOOK HERE
Your syntax is a bit messed up; this is how it is supposed to look:
function ActivateMod()
if TEAM_COOK.NumPlayers = 0 then
DarkRP.disabledDefaults ["hungermod"] = false
else
DarkRP.disabledDefaults ["hungermod"] = true
end
end
I don’t know what you were trying to accomplish with TEAM_COOK.NumPlayers return, but it would have caused an error.
Although it will still work, ‘then’ is generally located on the same line as the if statement.
All relational operators go before = in an if statement (>=, <=, ==).
elseif is one word in Lua.
You can just have else there since if it’s not 0, it must be 1 or more.
end spacing was backwards.
You had too many end’s.
That should work syntax wise; not too familiar with DarkRP globals, so I’m not sure if the variables will work or not. Good job for your first time trying to make something like that.
You forgot to edit this part of his code
[lua]if TEAM_COOK.NumPlayers = 0 then[/lua]
As you said it’s ==
[lua]if TEAM_COOK.NumPlayers == 0 then[/lua]
But you can do better (operators can be used after = ):
[lua]
function ActivateMod()
DarkRP.disabledDefaults.hungermod = TEAM_COOK.NumPlayers > 0
end
[/lua]