Jump to content

Recommended Posts

i made a hole in the ground that finds nearby petals and move them towards it, then it was suposed to store the item in the inventory just like the mole does, so i can dig it later, but i cant find a way to pick a prefab  and move it to the inventory

aditionally i would also like for it to pick flowers as if a player had picked and then droped it in the ground, so they can be targeted by this effect
the idea is to make it look like invisible ants are harvesting the flowers

i used this code:
 

local food = GetClosestInstWithTag("cattoy", inst, 30)
    if food then
        if food:GetDistanceSqToPoint(inst:GetPosition())< 1 then
            inst.components.inventory:GiveItem(food)
        else
            move_food(food)
        end
    end



and i got this error:

master_server_log.txt

Edited by sauvva
[00:01:14]: [string "scripts/components/inventoryitem_replica.lu..."]:217: attempt to index field 'classified' (a nil value)
LUA ERROR stack traceback:
    scripts/components/inventoryitem_replica.lua:217 in (method) SetPickupPos (Lua) <211-219>
    scripts/components/stackable.lua:7 in (field) ? (Lua) <3-9>
    scripts/class.lua:43 in () ? (Lua) <36-45>
    scripts/components/stackable.lua:181 in (method) Put (Lua) <142-186>
    scripts/components/inventory.lua:1001 in (method) GiveItem (Lua) <908-1074>
    ../mods/sauvva/scripts/prefabs/anthill.lua:34 in (field) fn (Lua) <30-40>
    scripts/scheduler.lua:186 in (method) OnTick (Lua) <164-216>
    scripts/scheduler.lua:409 in (global) RunScheduler (Lua) <407-415>
    scripts/update.lua:240 in () ? (Lua) <224-298>

I think you are running this code on client side, in that side  "classified" doesn't exists, so you need to modify your code to run it on the server side, whether using an RPC or a validation check. That depends on how you handle the code you posted here.

  • Wavey 1
On 11/8/2025 at 10:52 PM, sauvva said:

sauvva_mod.zip

the entire mod, with the offending part comented

I apologize for the long wait. I have found a solution for your case:

-- Anthill.lua

local function store_pickable(inst,pickable)
    local pos = inst:GetPosition()
    if (not pickable:IsInLimbo()) and pickable.Physics~=nil then
        pickable.Physics:Teleport(pos:Get())
        inst.components.inventory:GiveItem(pickable)
    end
end

The issue pops up because that function calls twice. The second time, however, the object is in a state the game calls "limbo." In this state, the object doesn't have certain components because it is a state designed for the inventory system.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...