Re: Spike trap script help
Posted: Tue Apr 28, 2015 7:14 am
Did you try with x.name == "dungeon_pit" (with the underscore)?
Alois
Alois
Code: Select all
for x = 1,15 do
local pit = findEntity("dungeonpit"..x)
Code: Select all
function teleport(caller)
local pit
for x in entitiesAt(caller.level, caller.x, caller.y) do
--Here. This should probably be the default name for a pit of the tile-set you are using.
if x.name == "dungeonpit" then
pit = x
end Code: Select all
if (string.find(x.id,"dungoenpit")) then pit = x endCode: Select all
if (party.x < 10) then
tail = "0" .. party.x
else
tail = tostring(party.x)
end
if (party.y < 10) then
tail = tail .. "0" .. party.y
else
tail = tail .. tostring(party.y)
end
local pit = findEntity("dungeonpit .. tail)
if (pit:isOpen()) then
-- your code here
end
Be careful that "entity.name" and "entity.id" are two different things. For example, you may have a torch (name = torch) whose id is (for example) "torch_10" because it is the tenth torch spawned in the dungeon. Thus: "dungeonpit1" is the id of the pit (and if you look for findEntity("dungeonpit1") you are going to find the one and only entity with that id since ids are unique in the dungeon), while "dungeonpit" is the name of a generic "dungonpit"; if you are using standard assets, the "name" of the entity should be "dungeon_pit".
Oh! Okay now that makes a ton of sense and explains why it wasn't working with "dungeon_pit" simply because I'm not using default assets for this particular room. Now of course this presents another problem, I have two very similar traps using completely different assets that can be ran using the same script. So for this case I probably should use Alois's code to find the pits for the script:The scripts I wrote don't look for the object.id, they look for a match in the object.name.... is it a pit?
There should only be one pit per cell, one pit to find. It searches for a pit, and doesn't care what the id string of the pit happens to be.
Code: Select all
if (string.find(x.id,"dungoenpit")) then pit = x end
Code: Select all
if x.name == {"dm_floor_pit", "dungeon_pit", "spiked_pit"} thenThat won't work as typed. It's comparing a string to a table; (not to the specific strings in the table).Killcannon wrote:This brings up a question as well could I possibly in the future when doing this write something like this when calling the entity.names of multiple different assets:
Code: Select all
if x.name == {"dm_floor_pit", "dungeon_pit", "spiked_pit"} then
Code: Select all
if x.name == "dm_floor_pit" or x.name == "dungeon_pit" or x.name == "spiked_pit" thenCode: Select all
local pits = {"dm_floor_pit", "dungeon_pit", "spiked_pit"}
for count = 1,#pits do
if x.name == pits[count] then
--instructions...
end
end
Code: Select all
local pits = {"dm_floor_pit", "dungeon_pit", "spiked_pit"}
for count = 1,#pits do
if x.name == pits[count] then
--instructions...
end
end