Pressure Plates - Checking what's actually on it.

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!
Post Reply
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Pressure Plates - Checking what's actually on it.

Post by SpacialKatana »

Until the scripting ref is released all the new stuff is confuddling my brain, I'm not too good with lua anyway :(

How can I check what's actually on my pressure plate?
All I want to do is switch off a forcefield when a certain item is placed onto and therefore activates it.

Cheers.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Pressure Plates - Checking what's actually on it.

Post by Prozail »

Since the pressureplate doesn't contain a surface, like say, an alcove, i think the easiest way is to loop through items on a specific coordinate.

Code: Select all

function checkplate()
    for i in self.go.map:entitiesAt(dungeon_pressure_plate_1.x,dungeon_pressure_plate_1.y) do
        print(i.id)
    end
end

-- Edit: Or like this...


function checkstuff(sender)
	for j in self.go.map:entitiesAt(sender.go.x,sender.go.y) do
		if j.id == "acolyte_staff_1" then
			force_field_1.controller:deactivate()
		end
	end
end

User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Pressure Plates - Checking what's actually on it.

Post by Eleven Warrior »

Now this is a Script I am after. How can it done with more plates? Also can the Item id be any eg: it does not matter what the item id is if it's a rock on 1 plate and arrow on 2nd plate a door opens. Could be any arrow or rock on the chosen plate.
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: Pressure Plates - Checking what's actually on it.

Post by SpacialKatana »

@Prozail

Cheers m8 ;)
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Pressure Plates - Checking what's actually on it.

Post by Prozail »

Eleven Warrior wrote:Now this is a Script I am after. How can it done with more plates? Also can the Item id be any eg: it does not matter what the item id is if it's a rock on 1 plate and arrow on 2nd plate a door opens. Could be any arrow or rock on the chosen plate.
Not really sure what you're trying to achive. You can hook up the script above to any number of plates (since it's based on caller id), but it will only check for the same item on all of them.
You'll have to tweak the rest of the script to suit your needs.

If you want to check the class of the item use "obj.name" instead of "obj.id"
User avatar
ahn
Posts: 6
Joined: Thu May 03, 2012 10:07 pm

Re: Pressure Plates - Checking what's actually on it.

Post by ahn »

Eleven Warrior wrote:Now this is a Script I am after. How can it done with more plates? Also can the Item id be any eg: it does not matter what the item id is if it's a rock on 1 plate and arrow on 2nd plate a door opens. Could be any arrow or rock on the chosen plate.
You can get the "type" of the entity (rock, arrow,...) with entity.name

Eg. something like this:

Code: Select all

function entityIn(x, y, name)
	for e in self.go.map:entitiesAt(x, y) do
		if e.name == name then
			return true
		end
	end
	return false
end

if entityIn(3, 3, "rock") and entityIn(3, 4, "arrow") then
    print("ye")
end
Post Reply