Page 1 of 2
Entity/Item Facing Activating A Script
Posted: Fri Feb 08, 2013 5:27 pm
by Grimfan
Hi,
another question (possibly another one worthy of the editing superthread... we'll see).
Can you activate a script and open a door based on an entity's facing? After playing through One-Room I know something like that can be done (Kuningas's room I think), I just don't know where to start (or where to look if it has already been documented elsewhere). I would like two entities to face the same direction to open a door, so that's why I'm asking.
I should create
Grimfan's Corner or something, just so scripting wizards like Xanathar, Diarmuid and Komag know where to look if they want to answer highly worthwhile, completely nonsensical or thoroughly inane scripting questions.

Re: Entity/Item Facing Activating A Script
Posted: Fri Feb 08, 2013 5:45 pm
by Komag
How are you changing the entities' directions? Whatever button or trigger does the turning, just also have it run an entity facing check function:
Code: Select all
function turnThingOne()
--turnItSomehow
thingFaceCheck()
end
function thingFaceCheck() -- trig by turnThingOne(), turnThingTwo()
if thingOne.facing == 2 and thingTwo.facing == 2 then
mySpecialDoor:open()
end
end
Re: Entity/Item Facing Activating A Script
Posted: Fri Feb 08, 2013 5:49 pm
by Xanathar
Hi

you can do it going through a scripting_entity.
Let's say, for the sake of an example, you want to have a pressure plate which opens "my_door_1" only if the party goes on it while facing east:
Put the pressure plate in the middle of a 3x3 room, connect it to this script:
Code: Select all
function openIfEast()
if (party.facing == 1) then
my_door_1:open()
end
end
Replace party with any item or entity you wish and you are done (facing 0=N, 1=E, 2=S, 3=W).
EDIT: AH! Komag was faster

Re: Entity/Item Facing Activating A Script
Posted: Fri Feb 08, 2013 6:02 pm
by Grimfan
Wow!
I didn't expect the answer to be so straightforward. I was actually on the right track with my first attempt at it, but forgot about the old entity check function.
In answer to your first question, I'll be using the old destroy an object and spawn another in a different position/facing to rotate the objects. I'm not going for anything more complicated just yet. I'll leave that to you guys.
And Xanathar, you are welcome to chime in since you are actually answering the question from the perspective of opening a door dependent on the party's facing and not an object's facing.
Thanks guys!
Now that I think about it I have two other questions that possibly haven't been asked before.
1. Can you trigger a receptor with a weapon blow rather than a spell? Would it be a newly defined or cloned receptor, a script activated by a hidden pressure plate or is it a hard coded thing that cannot be modifed?
And a related question:
2. Can you change a spawner to fire arrows or quarrels, like an arrow trap? Again would this be a newly defined or cloned spawner, a script activated within the dungeon or is it another hard coded thing?
Re: Entity/Item Facing Activating A Script
Posted: Fri Feb 08, 2013 6:11 pm
by Xanathar
Just a fair warning.. if you want to go the spawn/destroy way for anything.. do it as long that "anything" is not an item.
With an item things go weird quite quickly - items in inventory are not found by findEntity, items can be on a mouse cursor, inside containers, inside containers which are inside containers which are on the mouse cursor.
It can be done and has been done, but things are not that trivial anymore

Feel free to ask help when and if you have this need.
Re: Entity/Item Facing Activating A Script
Posted: Sat Feb 09, 2013 8:15 am
by Grimfan
Okay,
Now I have another problem.
It's my first time trying to spawn and destroy the same object multiple times and of course the first time I tried it I got the "bad self x" message, then I thought I could use the id.sub method or the i.name method. Of course, it couldn't be that easy and the game either crashed or worked but didn't spawn a second entity. So what's the trick guys?
I was actually amazed I couldn't find the answer in the editing superthread. Is the answer so simple I should be kicking myself or has it just flown under the radar so to speak?

Re: Entity/Item Facing Activating A Script
Posted: Sat Feb 09, 2013 11:10 am
by Xanathar
Can you post the script ?
Re: Entity/Item Facing Activating A Script
Posted: Sat Feb 09, 2013 11:19 am
by Komag
don't forget about the Script Repository thread (the top link of the scripting section)

Re: Entity/Item Facing Activating A Script
Posted: Sat Feb 09, 2013 12:42 pm
by Grimfan
Okay here's the basic starting script for simply moving two goromorg statues forward one space.
Code: Select all
function goromorgMove1()
if steel_lever_1:getLeverState(activated) then
for j in allEntities(party.level) do
if j.id:sub(1,24) == "goromorg_statue_blockage" then
j:destroy()
spawn("goromorg_statue_blockage",10,25,13,0)
spawn("goromorg_statue_blockage",10,27,13,0)
playSound("wall_sliding_lock")
end
end
end
end
Now of course that part of the code works just fine, but if I want to move those goromorg statues again (to say coordinates 10,25,14,0 and 10,27,14,0) I run into problems.
If i just repeat the function in a different script nothing happens. There are no errors or anything, they just don't do anything. If I try to do it in the same script I get the bad self message. I just know that there is some small portion of the script that is holding me back. I'm just not sure what it is.
I also realize that the above script is fairly primitive (neanderthal even), but when you are completely new to something I think it's best to take baby steps.
Re: Entity/Item Facing Activating A Script
Posted: Sat Feb 09, 2013 12:46 pm
by Grimfan
Komag wrote:don't forget about the Script Repository thread (the top link of the scripting section)

Agreed, but it actually doesn't really cover this.

It sort of skirts around it without actually answering the question.
What I want to do is similar to Grimwold's room in the One-Room dungeon or what you did with the spawning fx lights to create ground-level fireballs. I just want it on a smaller scale, and I just know it's something stupidly easy!
