[DarkRP] A Couple Lua Problems

The following code in addons/darkrpmodifications/food.lua doesn’t work. I get no errors:
[lua]
DarkRP.createFood(“Banana”, {
model = “models/props/cs_italy/bananna.mdl”,
energy = 10,
price = 10,
requiresCook = false,
customCheck = function(ply)
local playerAll = player.GetAll()

	for k, v in pairs(playerAll) do
		if v:Team() != TEAM_COOK then
			return false
		end
	end
end

})
[/lua]
If I remove the custom check it works. If I leave it, the food is there, but it is not available for purchase.

Also;

How would I go about editing the spawned_food entity? I do not want to edit core DarkRP files… So how would I go about disabling that entity and entering it into darkrpmodification? Without editing the core files. I mean I know how I could by editing the core files… But like I said, I do not want to.

Thanks guys :slight_smile:

-snip- trash post, sorry

What are you trying to do with the custom check ? if you are trying to make it only the cook can spawn it try.




DarkRP.createFood("Banana", {
    model = "models/props/cs_italy/bananna.mdl",
    energy = 10,
    price = 10,
    requiresCook = false,
    allowed = {TEAM_COOK}
})



Check out the code… He is checking to see if anyone on the server has that job.

Percipience, explain what you’re trying to do, there’s obviously a logic error in your code. Assuming what tzahush said is true, you could just do:



customCheck = function( Player )
    return team.NumPlayers( TEAM_COOK ) == 0
end


Or is it supposed to be consumed only by cooks / non-cooks? I know nothing about DarkRP, so I can’t help in that sense.

It should be consumed ONLY by non-cooks. Only when there’s no cooks online.

So, if there are no cooks online, anyone who is not a cook can consume it? What happens if there are cooks online?

**Edit

**If so, I think this should do:

Assuming these are the conditions:
Only non-cooks can consume, when there are no cooks online.
“Player” is the player who is trying to consume the item.



customCheck = function( Player )
    return team.NumPlayers( TEAM_COOK ) == 0 -- If there are any cooks, restrict consumption
end


Okay so if the cook is online they shouldn’t be able to use the food. Because the cook can spawn the microwave.

Kinda like SUP

Then the code I gave should theoretically work.

It’s basically:

If the player attempting to consume the item is not a cook, and there are no players in the cook team, then consume.

Note that this restricts the cook from eating the item themselves, so the code likely needs further adaptation.

Edit

I just realised, the “Player:Team() ~= TEAM_COOK” is redundant, as it is cancelled out by team.NumPlayers( TEAM_COOK ), so that brings us back to the original code I posted.



customCheck = function( Player )
    return team.NumPlayers( TEAM_COOK ) == 0 -- If there are any cooks, restrict consumption
end


Have you tried that?