Page 1 of 1

Pressure Plates - Checking what's actually on it.

Posted: Wed Oct 29, 2014 2:15 am
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.

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

Posted: Wed Oct 29, 2014 3:06 pm
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


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

Posted: Wed Oct 29, 2014 7:13 pm
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.

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

Posted: Wed Oct 29, 2014 8:00 pm
by SpacialKatana
@Prozail

Cheers m8 ;)

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

Posted: Wed Oct 29, 2014 8:18 pm
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"

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

Posted: Thu Oct 30, 2014 2:06 pm
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