• Disabling hunger on certain players not working
    10 replies, posted
Hi i was trying to create something to disable hunger on certain jobs but my script only makes hunger slower, any ideas why? hook.Add("hungerUpdate", "NoHunger", function(ply, en) if ply:Team() == "TEAM_OOC" then return true end end) this only makes hunger super slow i tried returning false and had the same problem local noHungerTeams = {   [TEAM_PRIVATE] = true,   [TEAM_OOC] = true,   [TEAM_VOIDLING] = true, } hook.Add("hungerUpdate", "NoHunger", function(ply, en) if noHungerTeams[ply:Team()] then return false end end)
local NoHunger = {     [TEAM_OOC] = true,     [TEAM_PRIVATE] = true,     [TEAM_VOIDLING] = true, } hook.Add("hungerUpdate", "Remove Hunger", function(ply, energy)     if (NoHunger[ply:Team()]) then         return true     end end) DarkRP/sv_player.lua at fd95cf68e6a01a1b0522c4a989d4512fc0fb202d..
Seems to still make hunger very slow, is there a specific place i should put it?
After trying to further do it i still cant seem to get hunger to disable, even with the code above
is there an error at startup? i ask cause modules are loaded BEFORE jobs are, you may be seeing an error saying "table index is nil"
You could try manually overriding the hunger value in the hook: local HungerWhitelist = { [TEAM_OOC] = true, [TEAM_PRIVATE] = true, [TEAM_VOIDLING] = true } hook.Add("hungerUpdate", "HungerWhitelist", function(ply, energy) if not HungerWhitelist[ply:Team()] then return end ply:setSelfDarkRPVar("Energy", 100) -- Just set their energy to 100 for good measure. return true end)
i have the file in a autorun folder in darkrp modification and now that i look i am getting an error in console error with "my code" [ERROR] addons/darkrpmodification-master_gmchosting/lua/autorun/sv_hunger.lua:13: '=' expected near 'end' 1. unknown - addons/darkrpmodification-master_gmchosting/lua/autorun/sv_hunger.lua:0 error with Doctors code [ERROR] addons/darkrpmodification-master_gmchosting/lua/autorun/sv_hunger.lua:3: '=' expected near 'HungerWhitelist' 1. unknown - addons/darkrpmodification-master_gmchosting/lua/autorun/sv_hunger.lua:0   it might have somthing to do with what joey said although
Okay so for anybody who wants to know how to do it local function init() NoHunger = {     [TEAM_OOC] = true,     [TEAM_PRIVATE] = true,     [TEAM_VOIDLING] = true, } end hook.Add( "Initialize", "some_unique_name", init ) hook.Add("hungerUpdate", "Remove Hunger", function(ply, energy)if (NoHunger[ply:Team()]) then return true end end) this disables hunger for certain teams
You really shouldn't be creating a global table
you could do this local NoHunger={} local func=function()--function is called by the last 2 lines NoHunger[TEAM_OOC] = true, NoHunger[TEAM_PRIVATE] = true, NoHunger[TEAM_VOIDLING] = true, end hook.Add("hungerUpdate", "Remove Hunger", function(ply, energy) if (NoHunger[ply:Team()]) then return true end end) hook.Add("Initialize","Remove Hunger",func)--calls the function when the gamemode has finished loading if player.GetAll()[1] then func() end--calls the function when the file is refreshed while players are on we create the table when the file is loaded, but populate it when the gamemode has finished loading
local noHunger = {} local function init() noHunger = {     [TEAM_OOC] = true,     [TEAM_PRIVATE] = true,     [TEAM_VOIDLING] = true, } end hook.Add("hungerUpdate", "Remove Hunger", function(ply, energy)if (noHunger[ply:Team()]) then return true end end) hook.Add( "Initialize", "Removehunger", init) if player.GetAll()[1] then  init() end Okay so I've done this but i don't think I've done it correct(i haven't worked with lua lists in a while and i wasn't sure what the difference between local func=function() and localfunction init()
Sorry, you need to Log In to post a reply to this thread.