The problem is that when I try to buy food "/buyfood" server generates an error.
[code]
[ERROR] gamemodes/darkrp/gamemode/modules/hungermod/sv_hungermod.lua:78: attempt to call method 'Setowning_ent' (a nil value)
1. callback - gamemodes/darkrp/gamemode/modules/hungermod/sv_hungermod.lua:78
2. callback - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17
3. RP_PlayerChat - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:78
4. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:142
[/code]
And this feature "addMoney(-cost)" works. The player was withdrawn money.
I already tried to reinstall the gamemode.
The file in which the problem:
[code]
local function HMPlayerSpawn(ply)
ply:setSelfDarkRPVar("Energy", 100)
end
hook.Add("PlayerSpawn", "HMPlayerSpawn", HMPlayerSpawn)
local function HMThink()
Random = math.random(0,6)
-- print("HungerTimer: "..Random)
if Random == 3 then
for k, v in pairs(player.GetAll()) do
if not v:Alive() then continue end
v:hungerUpdate()
end
end
end
timer.Create("HMThink", 5, 0, HMThink)
local function HMPlayerInitialSpawn(ply)
ply:newHungerData()
end
hook.Add("PlayerInitialSpawn", "HMPlayerInitialSpawn", HMPlayerInitialSpawn)
local function HMAFKHook(ply, afk)
if afk then
ply.preAFKHunger = ply:getDarkRPVar("Energy")
else
ply:setDarkRPVar("Energy", ply.preAFKHunger or 100)
ply.preAFKHunger = nil
end
end
hook.Add("playerSetAFK", "Hungermod", HMAFKHook)
timer.Simple(0, function()
for k, v in pairs(player.GetAll()) do
if v:getDarkRPVar("Energy") ~= nil then continue end
v:newHungerData()
end
end)
local function BuyFood(ply, args)
if args == "" then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
return ""
end
local trace = {}
trace.start = ply:EyePos()
trace.endpos = trace.start + ply:GetAimVector() * 85
trace.filter = ply
local tr = util.TraceLine(trace)
for _,v in pairs(FoodItems) do
if string.lower(args) ~= string.lower(v.name) then continue end
if (v.requiresCook == nil or v.requiresCook == true) and not ply:isCook() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/buyfood", DarkRP.getPhrase("cooks_only")))
return ""
end
if v.customCheck and not v.customCheck(ply) then
if v.customCheckMessage then
DarkRP.notify(ply, 1, 4, v.customCheckMessage)
end
return ""
end
local cost = v.price
if not ply:canAfford(cost) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("cant_afford", string.lower(DarkRP.getPhrase("food"))))
return ""
end
ply:addMoney(-cost)
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("you_bought", v.name, DarkRP.formatMoney(cost), ""))
local SpawnedFood = ents.Create("spawned_food")
SpawnedFood:Setowning_ent(ply)
SpawnedFood:SetPos(tr.HitPos)
SpawnedFood.onlyremover = true
SpawnedFood.SID = ply.SID
SpawnedFood:SetModel(v.model)
-- for backwards compatibility
SpawnedFood.FoodName = v.name
SpawnedFood.FoodEnergy = v.energy
SpawnedFood.FoodPrice = v.price
SpawnedFood.foodItem = v
SpawnedFood:Spawn()
hook.Call("playerBoughtFood", nil, ply, v, SpawnedFood, cost)
return ""
end
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
return ""
end
DarkRP.defineChatCommand("buyfood", BuyFood)
[/code]
An addon you have must be overriding spawned_food; the NWVar is defined here [url]https://github.com/FPtje/DarkRP/blob/353dc3286092cdb2efade2cc0f2145db5a6c2e69/entities/entities/spawned_food/shared.lua[/url]
[QUOTE=code_gs;51588915]An addon you have must be overriding spawned_food; the NWVar is defined here [url]https://github.com/FPtje/DarkRP/blob/353dc3286092cdb2efade2cc0f2145db5a6c2e69/entities/entities/spawned_food/shared.lua[/url][/QUOTE]
I am very grateful, thank you.
Sorry, you need to Log In to post a reply to this thread.