Jump to content

Recommended Posts

Hi, I started playing again and my mod "Groot" crashes on 1st day of summer because the character sheds random item each day of summer. It used to work many months ago. Below is the error log and below that is the code snippet.

 

Can anyone help?

Thanks.

 

Error log:

../mods/workshop-391743403/scripts/prefabs/gggroot.lua:446 in (upvalue) DropAnI
[00:09:08]: [string "scripts/entityscript.lua"]:985: assertion failed!
LUA ERROR stack traceback:
    =[C]:-1 in (global) assert © <-1--1>
    scripts/entityscript.lua:985 in (method) GetPosition (Lua) <981-987>
    ../mods/workshop-391743403/scripts/prefabs/gggroot.lua:446 in (upvalue) DropAnItem (Lua) <444-448>
    ../mods/workshop-391743403/scripts/prefabs/gggroot.lua:466 in (upvalue) DropItems (Lua) <450-468>
    ../mods/workshop-391743403/scripts/prefabs/gggroot.lua:472 in (upvalue) groot_shed (Lua) <470-473>
    ../mods/workshop-391743403/scripts/prefabs/gggroot.lua:538 in (local) fn (Lua) <536-540>
    scripts/entityscript.lua:962 in (method) PushEvent (Lua) <956-979>
    scripts/components/seasons.lua:248 in (local) fn (Lua) <240-253>
    scripts/entityscript.lua:962 in (method) PushEvent (Lua) <956-979>
    scripts/mainfunctions.lua:295 in () ? (Lua) <292-297>
 
[00:09:34]: Force aborting...

 

Snippet inside gggroot.lua:

...

local function DropAnItem(inst, prefab)
    local itemtoshed = SpawnPrefab(prefab)
local pos = inst:GetPosition()
    itemtoshed.Transform:SetPosition(pos.x + math.random()*2 - 1, 1, pos.z + math.random()*2 - 1)
end
 
local function DropItems(inst, itemname)
local itemtoshed, howmanytodrop
 
if itemname == "cutgrass" then
howmanytodrop = 3
elseif itemname == "twigs" then
howmanytodrop = 3
elseif itemname == "log" then
howmanytodrop = 1
elseif itemname == "petals" then
howmanytodrop = 2
else --unhandled
howmanytodrop = 1
end
 
for i=1,howmanytodrop do
DropAnItem(inst, itemname)
end
end
 
local function groot_shed(inst)
local shed_drops = {"cutgrass", "twigs", "log", "petals"}
    inst:DoTaskInTime(1, DropItems(inst, shed_drops[math.random(#shed_drops)]))
end
 
...
 
local master_postinit = function(inst)
  ...
  TheWorld:ListenForEvent("seasontick", function(world)
    if world.state.issummer then
      groot_shed(inst)
    end
  end)
 
...
Edited by SenL

Fixed.

I copied pigking.lua

 

local function DropAnItem(inst, prefab)
    local itemtoshed = SpawnPrefab(prefab)
local pos = Vector3(inst.Transform:GetWorldPosition())
    itemtoshed.Transform:SetPosition(pos.x + math.random()*2 - 1, 1, pos.z + math.random()*2 - 1)
end
 
If not correct, please let me know.
Thanks.

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...