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
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: placing items

Post by KhrougH »

Zo Kath Ra wrote: Fri Jun 12, 2020 9:42 pm
KhrougH wrote: Fri Jun 12, 2020 11:31 am when you drop an item it stand on the ground in a "random" position.
i need to place an object on the ground but just at the center of the tile.
i already Defined my Object but i can't find a way to tell him to place it in the middle of the tile when you drop it. some help?
Please post the object definition.
something like this:

Code: Select all

defineObject{
	name = "figure_queens_guardian",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/figure_ice_guardian.fbx",
		},
		{
			class = "Item",
			uiName = "Queen's Guardian Figurine",
			description = "it's a figurine is a Queen's Guardian. Guessing what is used for?.",
			gfxIndex = 434,
			weight = 3.1,
		},	
	}
}
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
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 »

If this is an object on a shrine or carefully placed, then just use a socket component instead of a surface component.

Image
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post by KhrougH »

Isaac wrote: Sun Jun 14, 2020 3:22 am If this is an object on a shrine or carefully placed, then just use a socket component instead of a surface component.

Image
i can't. i need to place them on the floor
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
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 »

You need to place them?... or does the player need to place—or re-place them? Even so, the socket component is probably what you need.

You can position the socket to precisely anywhere, and there can be more than one socket. The socket(ed) object need not even be visible.

If you elaborate with the exact planned use, we can help. One can use sockets even for placing pickable fruit on a tree, berries on a bush, or mushrooms on the ground; dice, or coins on a table.
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post by KhrougH »

Isaac wrote: Sun Jun 14, 2020 1:52 pm You need to place them?... or does the player need to place—or re-place them? Even so, the socket component is probably what you need.

You can position the socket to precisely anywhere, and there can be more than one socket. The socket(ed) object need not even be visible.

If you elaborate with the exact planned use, we can help. One can use sockets even for placing pickable fruit on a tree, berries on a bush, or mushrooms on the ground; dice, or coins on a table.
PLAYER needs to place figures on the floor. i wish i can place them at the center of the tile so you can see them in line, not randomly placed. i can't use pedestals or tables.
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
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 »

There are many ways to implement this. It depends on the behavior that you want.

Will the player know to precisely center the figurine, or should they not have any clue that it needs to be centered?
(Would whole-tile item centering spoil it, or instead be what you need?)

Should other objects also be center-able, or just the queens figurine?

A socket component works well in most cases that allow for just one item.
_____________________________

Just place either of these objects on the tile you wish the figure to be centered. These objects expect the player to click in the approximate center of the tile.

Code: Select all

defineObject{
	name = "centered_queens_floor_socket",
	components = {
		
		{
			class = "Socket",
			offset = vec(0, 0, 0),
			onAcceptItem = function(self, item) 
								return item.go.name == "figure_queens_guardian"
							end,
		},	

		{
			class = "Clickable",
			offset = vec(0, 0, 0),
			size = vec(.5, 0.1, .5), 
			maxDistance = 1,
		}, 
	},
	placement = "floor",
	editorIcon = 140,
}


defineObject{
	name = "centered_floor_socket",  --Accepts any item
	components = {
		
		{
			class = "Socket",
			offset = vec(0, 0, 0),
			onAcceptItem = function(self, item) 
								return self:count() ~= 1
							end,
		},	

		{
			class = "Clickable",
			offset = vec(0, 0, 0),
			size = vec(.5, 0.1, .5),
			maxDistance = 1,
		}, 
	},
	placement = "floor",
	editorIcon = 140,
}
*If you want the whole tile to catch the click, and center the item, then you can adjust the size of the click region to this:

Code: Select all

size = vec(3, 0.1, 3),
But this will affect the placement of any other items on to the tile.
Last edited by Isaac on Sun Jun 14, 2020 7:19 pm, edited 1 time in total.
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post by KhrougH »

Isaac wrote: Sun Jun 14, 2020 5:05 pm There are many ways to implement this. It depends on the behavior that you want.

Will the player know to precisely center the figurine, or should they not have any clue that it needs to be centered?
(Would whole-tile item centering spoil it, or instead be what you need?)

Should other objects also be center-able, or just the queens figurine?

A socket component works well in most cases that allow for just one item.
_____________________________

Just place either of these objects on the tile you wish the figure to be centered. These objects expect the player to click in the approximate center of the tile.

Code: Select all

defineObject{
	name = "centered_queens_floor_socket",   --Only accepts figure_queens_guardian items
	components = {
		
		{
			class = "Surface",
			offset = vec(0, 0, 0),
			size = vec(.05, .05,.05),
			onAcceptItem = function(self, item) 
								return item.go.name == "figure_queens_guardian"
							end,
		},	

		{
			class = "Clickable",
			offset = vec(0, 0, 0),
			size = vec(.5, 0.1, .5), 
			maxDistance = 1,
		}, 
	},
	placement = "floor",
	editorIcon = 140,
}


defineObject{
	name = "centered_floor_socket",  --Accepts any item
	components = {
		
		{
			class = "Socket",
			offset = vec(0, 0, 0),
			onAcceptItem = function(self, item) 
								return self:count() ~= 1
							end,
		},	

		{
			class = "Clickable",
			offset = vec(0, 0, 0),
			size = vec(.5, 0.1, .5),
			maxDistance = 1,
		}, 
	},
	placement = "floor",
	editorIcon = 140,
}
*If you want the whole tile to catch the click, and center the item, then you can adjust the size of the click region to this:

Code: Select all

size = vec(3, 0.1, 3),
But this will affect the placement of any other items on to the tile.
that's briliant, man :D
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
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 »

this is an underwater level
SpoilerShow
Image
on the top is the watersurface, going into the end of the level and so ends its watersurface rendering

Is there a way to make that watersurface been seeing after the level limit?
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 »

There are a couple options:
1. Use a ModelComponent for the water with a model that extends past the edge of the map, instead of a WaterSurfaceMeshComponent. See the ocean_water model in the standard assets for an example. Depending on your needs, you might be able to just use that model and change the material to water_surface_underwater.

2. Alternatively, you can use WaterSurfaceMeshComponent and then move/rotate/scale the resulting mesh using setWorldPosition() and setWorldRotation(). You will probably need to do this again every time the player loads a saved game - you'll have to test that yourself.
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 »

ah yes thank you!

I didn't think to use something like ocean model.
SpoilerShow

Code: Select all

-- ocean special for lake rhun
-- watersurface component is dealed by a standart water_surface object

defineObject{
	name = "lake_rhun_special_ocean",
	components = {
		{
			class = "Model",
			model = "assets/models/env/ocean_water.fbx",
material = "water_surface_calm",
			offset = vec(0, -0.2, -1.5),
			renderHack = "ForceZWrite",
			sortOffset = 100000,	-- force water rendering before other transparent surfaces
		},
	},
	placement = "floor",
	dontAdjustHeight = true,
	editorIcon = 264,
	reflectionMode = "never",
}

-- ocean model used underwater for rendering outside level limit
-- watersurface component is dealed by a standart water_surface object

defineObject{
	name = "lake_rhun_special_underwatersurface",
	components = {
		{
			class = "Model",
			model = "assets/models/env/ocean_water.fbx",
material = "water_surface_underwater",
			offset = vec(0, -0.85, 1.5),
			renderHack = "ForceZWrite",
			sortOffset = 100000,	-- force water rendering before other transparent surfaces
		},
	},
	placement = "floor",
	dontAdjustHeight = true,
	editorIcon = 264,
	reflectionMode = "never",
}
it's done, but with 3 different object/surface, for better viewing:

I finally use ocean model for rendering water on the surface, because ocean and water_surface generated by the water tile does not look the same, so I put an ocean over the real water_surface object.

Then for the underwater, I use another ocean model to render the underwater material. Again, I put it after the water_surface generated by the water tile, so you can only see the ocean object and hide the real water_surface

you can only see them if you go out the water, but

this is underwater, on the edge of the level
SpoilerShow
Image
this is on the surface:
SpoilerShow
Image
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply