Overriding exiting for ALL rooms

duggold
10 Jun 2012, 19:43
I want to setup a system whereby any visible objects with a flag "enemy" set to 1 will have a chance of keeping you from leaving your current room. The idea being, if there are monsters in the room, you can't leave until they die. I may code a flee chance to let you have a chance of fleeing. In any event, I need a way to have code executed BEFORE the person leaves ANY Room that checks for enemies. IF flee chance isn't rolled, tell them they can't leave (in any direction). If the flee chance is rolled (or no monsters in room), continue doing the normal exiting stuff. I don't see where in the supplied aslx files the actual movement code is so I could change its behavior. I don't want to code stuff to lock/unlock exits as I think that's overkill and I want to allow locked exits on top of this system.

Pertex
10 Jun 2012, 20:12
Not that easy. I think you must lock all exits, something like

for each (exit, Allexits()) {
exit.locked=true
}

duggold
10 Jun 2012, 22:11
How about a way to make the normal compass commands all issue a FLEE command (like Flee north). So when they click the compass it doesn't issue the normal move command but FLEE command instead? Then, when the monster dies, it reinstates the normal action from the compass clicks? Maybe a way on a per room basis to redirect the movement commands to my own scripts and then set the commands back again?

What if I redefine the movement verbs for my game so my own scripts handle them. Then, I can call the built in commands if I allow the player to move? If my game has a verb defined (like move), won't my code get called before the normal Move function? And if so, how could I call the "old" built in move function to allow things to continue as they would normally go?

duggold
11 Jun 2012, 03:05
I ended up getting this working by putting in my game my own default exit template (code below). I set objects with an enemy=1 attribute if they are combatants. If in a room with a combatant, it doesn't let you leave. It also respects the locked attribute of the exit so will never let you leave through a locked exit. Any feedback on this? Seem reliable? Any issues I need to be aware of?

<type name="defaultexit">
<displayverbs type="list">Go to</displayverbs>
<locked type="boolean">false</locked>
<lockmessage>That way is locked.</lockmessage>
<lookonly type="boolean">false</lookonly>
<script type="script">
locked_out = 0
if (this.locked) {
locked_out = 1
msg (this.lockmessage)
}
if (locked_out = 0) {
found_one = 0
foreach (enemy, ScopeVisibleNotHeld()) {
if (HasAttribute(enemy,"enemy")) {
if (enemy.enemy = 1) {
found_one = 1
}
}
}
if (found_one = 0) {
MoveObject (player, this.to)
}
else {
msg ("You can't move while in combat")
}
}
</script>

Pertex
11 Jun 2012, 08:42
looks great