Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

It can't auto-pickup...Who does it give it to?
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Isaac wrote: Thu Dec 19, 2019 11:39 pm It can't auto-pickup...Who does it give it to?
That's a good question!
If champion 1 throws a rock, and then champion 2 throws a rock, and the party walks over them, champions 1 gets both rocks.
Even if you throw the rocks in opposite directions, and they're not close to each other.

So the lowest-ordinal champion who has recently thrown a rock gets the throwItem() rock?

But you're right, it would be nice if we could specify the champion in throwItem(), or if we could use ProjectileComponent:setCastByChampion() to determine which champion receives the rock from auto-pickup.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

ItemComponent:throwItem() specifically credits the item to no champion, it won't give any xp if it kills a monster, etc.
It's not really made for throwing items at monsters, it's more for the situation where you have an existing item on the map and you want to make it fly somewhere.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

I wonder if someone can help me to find what's wrong with this message?

I've got a crash when loading my savegame:
(same with the regular savegame)

Code: Select all

Loading save game C:\Users\Bong\Documents/Almost Human/Legend of Grimrock 2/quicksave.sav
Loading dungeon House Hardabar's Call by Bongobeat
=== Software Failure ===

[string "MessageSystem.lua"]:0: could not resolve object reference with id LVL13chest_57
stack traceback:
	[C]: in function 'assert'
	[string "MessageSystem.lua"]: in function 'loadState'
	[string "GameMode.lua"]: in function 'loadGame'
	[string "GameMode.lua"]: in function 'update'
	[string "Grimrock.lua"]: in function 'display'
	[string "Grimrock.lua"]: in main chunk
that object is a chest, who is spawned from an external script and set as mimic then.
It is loaded when activating a hidden pressure plate.

Code: Select all

isSPITEMLEVEL13Finished = false -- is at the begining of the script
function spItmlv13()
        if isSPITEMLEVEL13Finished == true then
            return
        end
spawn("pickaxe",13,9,2,0,0,"LVL13pickaxe_3")
spawn("chest",13,30,22,0,0,"LVL13chest_57")
LVL13chest_57.chest:setMimic(true)
spawn("fire_bomb",13,30,22,0,0,"LVL13fire_bomb_15")
LVL13fire_bomb_15.item:setStackSize(3)
LVL13chest_57.surface:addItem(LVL13fire_bomb_15.item)
spawn("meteorite",13,30,22,0,0,"LVL13meteorite_4")
LVL13chest_57.surface:addItem(LVL13meteorite_4.item)
spawn("meteorite",13,30,22,0,0,"LVL13meteorite_3")
LVL13chest_57.surface:addItem(LVL13meteorite_3.item)

-- I'll pass other stuff and come right to the end.

isSPITEMLEVEL13Finished = true -- to be sure that those items are not loaded again -- I got multiple entrance in the level so I put a trigger at each of them

-- then I go to the next function, for the rest of the items (there is spItmlv13 and spItmlv13B functions)
delayedCall(self.go.id, 0.5, "spItmlv13B")
end
(I've spawn most items, chest, alcoves or any objects that don't have minimalSaveState = true that way)

For unknow reasons to me, the savegame wouldn't load itself.
I've already had some chest spawned like this in previous levels, and set as mimic, and I never had loading problem.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post by 7Soul »

I'm not sure what the error means, but I wanted to point out a different way to make sure the object spawns only once (because at first I thought the problem could have been the variable being reset)

Instead of using a boolean variable, you can just check if the object already exists:

Code: Select all

if not LVL13chest_57 then
 -- code
end
If the object doesn't exist, LVL13chest_57 will be nil
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

I'm not sure this will resolve the problem.

my condition works. If you do spawn it twice, you got directly a game crash. And it wasn't spawned twice, or the game would have crashed while I entered this level, exited it and come again from another entry.

Beside, I couldn't even re-trigger it, because I use invisible floor trigger, that auto destroy itself after use.

Here all was spawned, I play a few hours in other level, then save, then reload the next day, and I got the error mesage.
The error didn't even come from the level I was.

Could it be that spawning chest and making mimic of them is bad after the mod is loaded?
I mean, maybe all mimic has to be set at the first loading, chest placed in the editor?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

bongobeat wrote: Wed Feb 19, 2020 10:24 pm I'm not sure this will resolve the problem.

my condition works. If you do spawn it twice, you got directly a game crash. And it wasn't spawned twice, or the game would have crashed while I entered this level, exited it and come again from another entry.

Beside, I couldn't even re-trigger it, because I use invisible floor trigger, that auto destroy itself after use.

Here all was spawned, I play a few hours in other level, then save, then reload the next day, and I got the error mesage.
The error didn't even come from the level I was.

Could it be that spawning chest and making mimic of them is bad after the mod is loaded?
I mean, maybe all mimic has to be set at the first loading, chest placed in the editor?
If you could upload a savegame, we could look at it with the LoG2 savegame editor.
There must be a reference to LVL13chest_57 somewhere in the savegame.
We just need to find out where...
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

That message means that an item is still marked as being contained in the chest, but the chest doesn't exist anymore.

It doesn't matter when you call setMimic(), the chest being a mimic or not doesn't have any effect until the player opens it. When they do, the chest spawns a mimic, adds all its surface's contents to the mimic's inventory, then destroys itself.

If you really haven't done anything else to the chest & items other than the code you pasted, then my only guess as to what's going wrong is that when ChestComponent moves its items to the mimic monster, it might be removing items from the surface while inside the contents() iterator, which might cause the iterator to skip over items if there's more than one item in the chest - and if that happens, then that item will be left behind floating in the air, still marked as being contained in a surface that no longer exists. Which would cause that error.
That is, however, just a wild guess.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
SluisE
Posts: 8
Joined: Fri Nov 30, 2018 4:56 pm

Re: Ask a simple question, get a simple answer

Post by SluisE »

Could it be a problem that the fire_bombs are stacked? That somehow stacked items disrupt the conversion of items from chest to mimic ?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Extremely unlikely. The items being stacked just means that a number in the ItemComponent is 3 instead of 1. A stack of 5000 bombs is still a single fire_bomb object with a single ItemComponent.

Mind you, my guess is also extremely unlikely (there are mimic chests with multiple items in Isle of Nex and we certainly would've heard of it if this ever happened there), which is why I suspect the pasted code doesn't provide the full story. For example, you could easily cause this error with a bad onRemoveItem hook.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply