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
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

How can I define a proper "fence"?

When I define the object as "base_door" I get warning messages as the gate node is missing. Using "base_wall" will just let the party walk through. A workaround is the added "obstacle" component which blocks the tile the wall is attached to. So for wall_decorations that is no problem, but in a more central position it is not an option.

I also tried using an existing fence as "base_object". Works, but with the obligatory console warning of a missing gate node.

Code: Select all

defineObject{
	name = "cemetery_fence_02",
--	baseObject = "base_wall",
--	baseObject = "base_door",
	baseObject = "cemetery_wall_01",
	components = {
		{
			class = "Model",
			model = "mod_assets/models/cemetery_fence_02.fbx",
			staticShadow = true,
		},
	},
	placement = "wall",
	editorIcon = 124,
	automapIcon = 84,
}
PS: The constrainBox doesn't seem to work either. Am I right in assuming that box1 and box2 are needed to form an impassible... box for items, for instance throwing weapons? Would that refer to the party as well?! Puzzling...
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You need to make a model with a mesh node named "gate". That mesh will be used for detecting collisions with the DoorComponent.

ItemConstrainBoxComponent only affects dropping and pushing items, not thrown items; you want ProjectileColliderComponent for colliding with thrown items. But you normally don't want to add a ProjectileColliderComponent to a door, because the DoorComponent already handles projectile collision using the gate node.

The ItemConstrainBoxComponents on base_door are there to stop you from dropping items inside the door frame.
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.
User avatar
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

minmay wrote: Thu Mar 28, 2019 10:44 am You need to make a model with a mesh node named "gate". That mesh will be used for detecting collisions with the DoorComponent.

ItemConstrainBoxComponent only affects dropping and pushing items, not thrown items; you want ProjectileColliderComponent for colliding with thrown items. But you normally don't want to add a ProjectileColliderComponent to a door, because the DoorComponent already handles projectile collision using the gate node.

The ItemConstrainBoxComponents on base_door are there to stop you from dropping items inside the door frame.
Yes, I figured it out in the meantime, thanks. Apparently it does not work with "Gate", but the node needs to be called "gate" - the usual. Do not forget to "update" the node before you save the model.
Thanks for the constrain box explanation. Wall_grating objects seem to have none, hence the reason why you can lay things beyond the frame. Having no ProjectileCollider for a waist-high fence or low wall would be prefered anyway.

So in case anyone else was wondering, this here should work for a proper fence:
SpoilerShow

Code: Select all

defineObject{
	name = "cemetery_fence_02",
	baseObject = "base_wall_grating",
	components = {
		{
			class = "Model",
			model = "mod_assets/models/cemetery_fence_02.fbx",
			staticShadow = true,
		},
	},
	placement = "wall",
	editorIcon = 124,
	automapIcon = 84,
}
Wouldn't a constrainBox work the same way as a surface component, for instance for a raised floor tile model to prevent things from falling "into" the model?
shayologo
Posts: 8
Joined: Wed Feb 13, 2013 12:10 pm

Re: Ask a simple question, get a simple answer

Post by shayologo »

Hello

It's a way to fixe range from firearm? I don't want to take care about to firearm skill

I want a range of 1 for one firearm
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 »

shayologo wrote: Sat Mar 30, 2019 12:25 pm Hello

It's a way to fixe range from firearm? I don't want to take care about to firearm skill

I want a range of 1 for one firearm
Define a new firearm that sets the Firearms skill to 1 when equipped and remembers the old value, maybe in a Counter component.
Problem: If the champion increases his Firearms skill while wielding the weapon, that's not taken into account.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Zo Kath Ra wrote: Sat Mar 30, 2019 4:00 pmDefine a new firearm that sets the Firearms skill to 1 when equipped and remembers the old value, maybe in a Counter component.
Problem: If the champion increases his Firearms skill while wielding the weapon, that's not taken into account.
Uhh, please don't do that. As soon as the player opens the skill screen, that approach is ruined.
A much simpler way to force a specific range: set the range to 1-champion:getSkillLevel("firearms") in the onAttack hook, and set it back to 1 right after the attack, like this:

Code: Select all

defineObject{
	name = "really_crappy_gun",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/pistol.fbx",
		},
		{
			class = "Item",
			uiName = "Really Crappy Gun",
			gfxIndex = 333,
			impactSound = "impact_blunt",
			weight = 1.1,
			traits = { "firearm" },
		},
		{
			class = "FirearmAttack",
			attackPower = 5,
			cooldown = 6,
			range = 1,
			attackSound = "gun_shot_small",
			ammo = "pellet",
			requirements = { "firearms", 1 },
			onAttack = function(self, champion, slot)
				self:setRange(1-champion:getSkillLevel("firearms"))
			end,
			onPostAttack = function(self, champion, slot)
				self:setRange(1)
			end,
		},
	},
}
It's a bit more involved if you want the firearm to be able to jam or backfire (jams don't call onPostAttack, backfires call onBackfire instead of onPostAttack) but still fairly simple, and I can explain how to do that too if needed.
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.
shayologo
Posts: 8
Joined: Wed Feb 13, 2013 12:10 pm

Re: Ask a simple question, get a simple answer

Post by shayologo »

Thx you man :) you are my hero
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam »

is there a way to spawn an object in a specific direction, or force direction?

Code: Select all

if g.map:getCeilingElevation(g.x,g.y)-1 == g.elevation then
		local choice2 = math.random()
		if choice2 <= 0.25 then
			g:spawn("sg_forest_rock_ceiling_trim01")
		elseif choice2 <= 0.50 then
			g:spawn("sg_forest_rock_ceiling_trim02")
		elseif choice2 <= 0.75 then
			g:spawn("sg_forest_rock_ceiling_trim03")
		else
			g:spawn("sg_forest_rock_ceiling_trim04")
		end
	end
	
For example in this section what could I do to get it to spawn in a specific direction?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You'll have to use the global spawn(name, level, x, y, facing, elevation, [id]) function. GameObject:spawn() always spawns the new object with the facing of the object you're spawning it from.

g:spawn("thing") is equivalent to spawn("thing",g.level,g.x,g.y,g.facing,g.elevation)
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.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam »

minmay wrote: Mon Apr 01, 2019 5:42 am You'll have to use the global spawn(name, level, x, y, facing, elevation, [id]) function. GameObject:spawn() always spawns the new object with the facing of the object you're spawning it from.

g:spawn("thing") is equivalent to spawn("thing",g.level,g.x,g.y,g.facing,g.elevation)
Awesome ty sir :)
Post Reply