How to create patrolling guard?
Hibiki
18 Aug 2015, 15:25please help me with quest, i need to create a patrolling guard, i made 3 rooms connected to each other, and a guard in the first room, so when the player makes a turn the guard moves to room 2, then room 3, then room 2, then room 1, and then all this cycle must repeat, so the guard will be patrolling and the player can avoid him, but i also want the guard to be visible in nearby room, so when the player is in the room 2 and the guard is in room 1, the message should appear that the guard is nearby, and i also want the game to finish when the player and the guard are in the same room (guard catches the player). please help me.

XanMag
18 Aug 2015, 16:23So... It's just at a three room cycle?
If so, I'll try to whip something up when I get home in 5 hrs. My explanation will be GUI heavy. If you prefer code heavy explanation, someone else will have to help you! Good luck.
If so, I'll try to whip something up when I get home in 5 hrs. My explanation will be GUI heavy. If you prefer code heavy explanation, someone else will have to help you! Good luck.

Forgewright
18 Aug 2015, 17:08If only three rooms, won't the guard always be nearby? The turn script is probably the answer here.

XanMag
19 Aug 2015, 01:32Here is the code for the three rooms. I have connected the rooms in a simple triangle. I did not add an exit from this triangle as I'm not sure exactly what you want to do with it.
It's late and I just started school, so please forgive me if this copy-paste of my code is incomplete or if you find an error!! You should be able to copy-paste this code into a new game and see what I tried to do. It should give you a template to use for your own game. If it doesn't work, let me know and I'll try and give you a fix.
I added a 2 time turn script because I figured you might want to give your player a chance to do something in each room. One turn per room would give you just enough time to leave. You can easily change it by switching my 2's to 1's. Again, please let me know if this is helpful or needs amended. It will help me in my attempt at creating a good GUI tutorial for common problems asked on the forum. THANKS!
EDIT: Well... Lol
I just re-read your post... I see now that you wanted the rooms linear it appears. Oops. Hopefully you can tweak my code to make the rooms in a straight line!! But... How could you ever get into room three? I guess if you have a way to hide from the guard, you could do it.
XanMag (who still has part II of Xanadu waiting to be finished... lol)
It's late and I just started school, so please forgive me if this copy-paste of my code is incomplete or if you find an error!! You should be able to copy-paste this code into a new game and see what I tried to do. It should give you a template to use for your own game. If it doesn't work, let me know and I'll try and give you a fix.
<object name="patrolling guard room 1">
<inherit name="editor_room" />
<enter type="script">
</enter>
<firstenter type="script">
msg ("An alarm sounds when you enter the room. A guard will be here shortly. Better get a move on!")
SetObjectFlagOn (Magoo, "patrolled")
guarding
</firstenter>
<object name="Magoo">
<inherit name="editor_object" />
<inherit name="editor_player" />
<look>You're Magoo. A simple being trapped in a test game.</look>
<attr name="pov_look">You're Magoo. A simple being trapped in a test game.</attr>
</object>
<exit alias="southeast" to="patrolling guard room 2">
<inherit name="southeastdirection" />
</exit>
<exit alias="southwest" to="patrolling guard room 3">
<inherit name="southwestdirection" />
</exit>
</object>
<object name="patrolling guard room 2">
<inherit name="editor_room" />
<exit alias="northwest" to="patrolling guard room 1">
<inherit name="northwestdirection" />
</exit>
<exit alias="west" to="patrolling guard room 3">
<inherit name="westdirection" />
</exit>
</object>
<object name="patrolling guard room 3">
<inherit name="editor_room" />
<exit alias="east" to="patrolling guard room 2">
<inherit name="eastdirection" />
</exit>
<exit alias="northeast" to="patrolling guard room 1">
<inherit name="northeastdirection" />
</exit>
</object>
<turnscript name="guarding TS">
<enabled />
<script>
if (ListContains(ScopeVisible(), guard)) {
msg ("You and the guard have happened to stumble into the same room. He looks incensed that he has been put to work. He takes his frustration out on you with his billy club. He pummels you to death. Sorry.")
finish
}
if (GetBoolean(Magoo, "patrolled")) {
if (GetBoolean(guard, "room1")) {
if (game.pov.parent = patrolling guard room 2) {
msg ("You look over your shoulder to the northwest and into patrol room 1 and you see the guard patrolling that room.")
}
else if (game.pov.parent = patrolling guard room 3) {
msg ("You look over your shoulder to the northeast and into patrol room 1 and you see the guard patrolling that room.")
}
}
else if (GetBoolean(guard, "room2")) {
if (game.pov.parent = patrolling guard room 1) {
msg ("You look off to your southeast and see a nasty looking guard patrolling guard room 2.")
}
else if (game.pov.parent = patrolling guard room 3) {
msg ("You hear some noise to the east and you take a look that way. You see the guard loitering in room 2.")
}
}
else if (GetBoolean(guard, "room3")) {
if (game.pov.parent = patrolling guard room 2) {
msg ("The guard is certainly making some noise off to the west as he searches patrol room 3 for you.")
}
else if (game.pov.parent = patrolling guard room 1) {
msg ("As you dawdle in room 1, the guard is frantically searching for you in patrol room 3 to your southwest.")
}
}
}
</script>
</turnscript>
<command name="look guard cmd">
<pattern>look at guard; x guard</pattern>
<script>
if (GetBoolean(guard, "room1")) {
msg ("You look carefully into room 1 where you believe the guard to be... He is large and angry. He is weilding a fearsome looking billy club.")
}
else if (GetBoolean(guard, "room2")) {
msg ("You look carefully into room 2 where you believe the guard to be... He is large and angry. He is weilding a nasty and heavy billy club.")
}
else if (GetBoolean(guard, "room3")) {
msg ("You look carefully into room 3 where you believe the guard to be... He is large and angry. He is weilding a fearsome looking billy club.")
}
</script>
</command>
<function name="guarding">
SetTurnTimeout (1) {
MoveObject (guard, patrolling guard room 1)
SetObjectFlagOn (guard, "room1")
SetObjectFlagOff (guard, "room3")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 2)
SetObjectFlagOn (guard, "room2")
SetObjectFlagOff (guard, "room1")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 3)
SetObjectFlagOn (guard, "room3")
SetObjectFlagOff (guard, "room2")
SetTurnTimeout (2) {
MoveObject (guard, patrolling guard room 1)
guarding
}
}
}
}
</function>
I added a 2 time turn script because I figured you might want to give your player a chance to do something in each room. One turn per room would give you just enough time to leave. You can easily change it by switching my 2's to 1's. Again, please let me know if this is helpful or needs amended. It will help me in my attempt at creating a good GUI tutorial for common problems asked on the forum. THANKS!
EDIT: Well... Lol
I just re-read your post... I see now that you wanted the rooms linear it appears. Oops. Hopefully you can tweak my code to make the rooms in a straight line!! But... How could you ever get into room three? I guess if you have a way to hide from the guard, you could do it.

XanMag (who still has part II of Xanadu waiting to be finished... lol)