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

ratman wrote: Tue Nov 24, 2020 11:59 pm How would I make a script so it gets all the party's items in their inventory, removes them, then spawns them in a chest?
Updated with the tips in the post below

Code: Select all

function removeItems()
	local items = {}
	for c = 1, 4 do
		local champion = party.party:getChampion(c)
		if champion:getEnabled() then
			for slot = ItemSlot.BackpackFirst, ItemSlot.BackpackLast do
				local item = champion:getItem(slot)
				if item then
					table.insert(items, item)
					champion:removeItem(item)
				end
			end
		end
	end
	for _,item in pairs(items) do
		chest_37.surface:addItem(item)
	end
end
If you want to also include the equipped items, replace ItemSlot.BackpackFirst with ItemSlot.Weapon
And replace chest_1 with the id of your chest
Last edited by 7Soul on Wed Nov 25, 2020 6:32 pm, edited 1 time in total.
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
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 »

7Soul wrote: Wed Nov 25, 2020 4:57 am
ratman wrote: Tue Nov 24, 2020 11:59 pm How would I make a script so it gets all the party's items in their inventory, removes them, then spawns them in a chest?

Code: Select all

function removeItems()
	local items = {}
	for c = 1, 4 do
		local champion = party.party:getChampion(c)
		for slot = ItemSlot.BackpackFirst, ItemSlot.BackpackLast do
			local item = champion:getItem(slot)
			if item then
				table.insert(items, item.go.name)
				champion:removeItem(item)
			end
		end
	end
	for _,id in pairs(items) do
		local newItem = spawn(id).item
		chest_1.surface:addItem(newItem)
	end
end
If you want to also include the equipped items, replace ItemSlot.BackpackFirst with ItemSlot.Weapon
And replace chest_1 with the id of your chest
I'd like to suggest two enhancements:
1) Check the champion with Champion:getEnabled()
2) Instead of spawning new items, add the existing items to the surface.
You can do this before or after removing them from their inventory slot.
IttaBitta
Posts: 21
Joined: Thu Oct 22, 2020 12:14 am

Re: Ask a simple question, get a simple answer

Post by IttaBitta »

[string "Arch.lua"]:0: undefined object: castle_ceiling_shaft_0000

I've gotten this error multiple times for seemingly random reasons. What gives?
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 »

IttaBitta wrote: Thu Nov 26, 2020 7:32 am [string "Arch.lua"]:0: undefined object: castle_ceiling_shaft_0000

I've gotten this error multiple times for seemingly random reasons. What gives?
I got that before too, but I don't remember why. The solution I found was to copy "castle_ceiling_shaft" and rename it

Code: Select all

defineObject{
	name = "castle_ceiling_shaft_0000",
	baseObject = "base_ceiling_shaft",
	components = {
		{
			class = "Model",
			model = "assets/models/env/castle_ceiling_shaft_01.fbx",
			staticShadow = true,
		}
	},
	minimalSaveState = true,
}
Just put this anywhere in your init file or a file with other object definitions
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
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 »

IttaBitta wrote: Thu Nov 26, 2020 7:32 am [string "Arch.lua"]:0: undefined object: castle_ceiling_shaft_0000

I've gotten this error multiple times for seemingly random reasons. What gives?
Is that the entire error?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You've placed a PitComponent above a castle_floor or castle_floor_water tile. These tiles don't have a ceiling shaft that fits with them. You could either make ceiling shaft models for it yourself (see the dungeon tileset ceiling shafts for an example), or switch to using castle_floor_tall tiles, and define a water version of castle_floor_tall if necessary.
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 got an issue while testing my mod:

Is it ok or not recommended to block the party while spawning objects in the level?

The tester didn't have a chest and a wooden box which are spawned in the level. It seems that everything is fine in the editor/and script, but this time he didn't have these objects while playing that level.

These objects are part of a whole external lua script, that spawn every items, chest and possibly alcove with items, monsters, etc.., it is called when the player enter the level, but in the same time I use.

Code: Select all

	GameMode.setGameFlag("DisableMovement", true)
	GameMode.setGameFlag("DisableMouseLook", true)
	GameMode.setGameFlag("DisableKeyboardShortcuts", true)
to block the party, and pop up a dialogue via hudprint, then after a few seconds the party movement is re-enabled.

Edit: it was a mistake, the object weren't spawned for another reason.
Last edited by bongobeat on Wed Dec 02, 2020 5:01 pm, edited 1 time in total.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Those game flags won't affect anything like that.
It sounds like your problem is instead related to saving and loading the game; perhaps you've put minimalSaveState on an object that you shouldn't have, or something like that? Have you tested this outside the editor?
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 have not checked if there is minimal save state on these objects, but I doubt it. It's a chest and a wooden box, I certainly didn't put minimalsavestate = true on these one. <<- will check it. In a moment of distraction, maybe I have copied something in the wrong area.



Also these objects have been tested, many times since i published many version, and I or the testers didn't notice something like that.


Edit:

I just try a new game, and I didn't notice anything wrong. Don't know what caused that.
Last edited by bongobeat on Fri Nov 27, 2020 5:52 pm, edited 1 time in total.
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: Thu Nov 26, 2020 11:49 pm Also these objects have been tested, many times since i published many version, and I or the testers didn't notice something like that.
How many objects does your mod have in total?
Maybe there are so many that the game decides to just drop some of them...
Post Reply