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
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Ask a simple question, get a simple answer

Post by Drakkan »

aaneton wrote:How do I check if a alcove has an item with a specific trait, e.g. I want to check if an alcove surface has a two-handed sword placed on surface. The traits would be "two_handed" and "sword".
I believe you can use modified script which was used for glutony shrine in original dungeon (just changing trait you need / number of required objects and what need to be triggered eventualy)

Code: Select all

function checkItems(surf)
	local count = 0
	
	for _,i in surf:contents() do 
		if i:hasTrait("consumable") then
			count = count + 1
		end
	end
	
	if count >= 3 then
		gluttonDoor.door:open()
	else
		gluttonDoor.door:close()
	end
end
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
aaneton
Posts: 189
Joined: Fri Sep 21, 2012 1:53 pm

Re: Ask a simple question, get a simple answer

Post by aaneton »

Drakkan wrote:
aaneton wrote:How do I check if a alcove has an item with a specific trait, e.g. I want to check if an alcove surface has a two-handed sword placed on surface. The traits would be "two_handed" and "sword".
I believe you can use modified script which was used for glutony shrine in original dungeon (just changing trait you need / number of required objects and what need to be triggered eventualy)
Excellent. Thanks!
My Grimrock mod (LoG1): The Onkalo Project
My Android (and windows desktop) game: Balloon Gentleman
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Re: Ask a simple question, get a simple answer

Post by Kuro01 »

Anyone have imfo somewhere on how to spawn a pressure plate or a lever and then set the components and connectors?
Nero44
Posts: 1
Joined: Mon Aug 17, 2015 10:42 pm

Re: Ask a simple question, get a simple answer

Post by Nero44 »

Can a floor trigger only be activated when the party is facing in a certain direction ?
Last edited by Nero44 on Tue Aug 25, 2015 7:47 pm, edited 2 times in total.
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 »

Nero44 wrote:Can a floor trigger only be activated when the party is facing in a certain direction ?
Here are two methods.

For the the first you define this particular floor_trigger as a custom object.

Code: Select all

defineObject{
	name = "floor_trigger_checked",
	baseObject = "floor_trigger",
	components = {
		{
			class = "FloorTrigger",
			onActivate = function(self) if party.facing ~= self.go.facing then return false end end,
		},
	},
}

Alternatively, you can connect the floor_trigger to a script_entity, and call the connection manually:

Code: Select all

function faceCheck(self) 
	if party.facing == self.go.facing then
		my_door.door:open()
 	end
end
*In both cases, it's setup that the facing of the floor_trigger, is the facing it checks for, before activating.

The floor_trigger should be set to only trigger for the party, unless you add a condition that checks that the party is standing on the floor_trigger; (that both are in the same tile). Also these do not account for the party turning in place; that requires a party onTurn hook... which can be done easy enough, but that changes the core behavior of the floor_trigger (as does having the facing check to begin with).
______________




Kuro01 wrote:Anyone have imfo somewhere on how to spawn a pressure plate or a lever and then set the components and connectors?
You use the Spawn function, and then call the spawned object's addConnector function, and give it the parameters to indicate how and what to connect to.

Example:

Code: Select all

spawn("dungeon_pressure_plate",1, 15,15,0,0).floortrigger
	:addConnector("onActivate", spawn("dungeon_door_iron",1,15,15,0,0).id, "open") 
A more clear example: ;)

Code: Select all

spawn("dungeon_pressure_plate",1, 15,15,0,0, "my_plate")
spawn("dungeon_door_iron",1,15,15,0,0, "my_door")
my_plate.floortrigger:addConnector("onActivate", "my_door", "open") 
*They both do the same thing.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I am trying to check, if a certain monster is still alive on the map (and I can do something with it).

Code: Select all

if ratling1_1.monster:isAlive() then
doesn't seem to work, because if this monster is dead (and not on the map) I got an error message ("nil value")

so what to do?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

check that ratling1_1 exists first...
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
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I thought, I do that... :?

So isAlive doesn't check, if a monster exists - but what than? How can a monster exist but being not alive???
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Code: Select all

if ratling1_1 ~= nil and ratling1_1.monster:isAlive() then ... end
When a monster dies, it still exists for a few seconds (before some kind of garbage collector eats it ?!).
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

THOM wrote:I thought, I do that... :?

So isAlive doesn't check, if a monster exists - but what than? How can a monster exist but being not alive???
you're trying to call a function named "isAlive" belonging to a table named "monster" belonging to a table named "ratling1_1" in the global environment. if ratling1_1 is nil, i.e. doesn't exist, you can't index it, so you get an error when you try
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