Darkrp Code Is this correct?

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



Just curious?

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

  1. I don’t know what you were trying to accomplish with TEAM_COOK.NumPlayers return, but it would have caused an error.
  2. Although it will still work, ‘then’ is generally located on the same line as the if statement.
  3. All relational operators go before = in an if statement (>=, <=, ==).
  4. elseif is one word in Lua.
  5. You can just have else there since if it’s not 0, it must be 1 or more.
  6. end spacing was backwards.
  7. 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]

thanks for that guess i was some where near it :smiley:


 TEAM_COOK.NumPlayers return 

can’t even remember myself what was going through my head doing that. Think i misinterpreted return for something else