Escaping from Battle

Hello! This forum was able to help me the last time, so I thought I’d ask again. Of course, if I ever figure something out, I’ll help, too! Anyways, all I need to know is how to escape from battle before I can get to work on this massive game of mine. I decided to use the combat code stuff from the site/book in order to help me out. I have no idea how to run from the battle. My idea is to have two options. Have the person make a roll to see if they can run. And if not, then they are stuck in the battle. If that is not possible, then I don’t want them leaving the battle at all. Here’s the combat code that I am using:

Understand the commands “attack” and “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as something new.

Attacking it with is an action applying to one visible thing and one carried thing. Understand “attack [someone] with [something preferably held]” as attacking it with.

Understand the commands “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as “attack”.

The attacking it with action has a number called the damage inflicted.

Setting action variables for attacking something with something:
if the second noun is a weapon:
let the maximum attack be the maximum damage of the second noun;
now the damage inflicted is a random number between 1 and the maximum attack.

Check an actor attacking something with something (this is the can’t attack with something that isn’t a weapon rule):
if the second noun is not a weapon:
if the actor is the player, say “[The second noun] does not qualify as a weapon.”;
stop the action.

Check an actor attacking something with something (this is the can’t attack a non-person rule):
if the noun is not a person:
if the actor is the player, say “[The noun] has no life to lose.”;
stop the action.

Carry out an actor attacking something with something (this is the standard attacking it with a weapon rule):
decrease the current hit points of the noun by the damage inflicted;
if the noun is dead:
now the noun is nowhere.

Report attacking a dead person with something (this is the death-report priority rule):
say “You attack with [the second noun], killing [the noun]!” instead.

Report attacking someone with something (this is the normal attacking report rule):
say “You attack [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

Report someone attacking the player with something when the player is dead (this is the player’s-death priority rule):
say “[The actor] attacks you with [the second noun], finishing you off!”;
end the story;
stop the action

Report someone attacking the player with something (this is the standard report someone attacking the player with rule):
say “[The actor] attacks you with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

Report someone attacking something with something (this is the standard report attacking it with rule):
say “[The actor] attacks [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

When play begins:
now the left hand status line is “Health: [current hit points of player]”.

Every turn (this is the noun-attack rule):
if the noun is not dead, try the noun attacking the player.

note: the following code is not tested, just tossing out ideas.

Well, you’re missing a period and the syntax requires tweakage. Also, your code won’t apparently compile happily even when I corrected the indentations. What version of I7 are you using?

Apart from that, the first thing that pops to mind is this: why not leave the “attack” verb the way it is, with all its synonyms, and simply add a line like:

Carry out attacking something (called the target): if the player carries [a weapon], try attacking the target with [the weapon].

just a thought. Obviously if the player can have and use a variety of weapons, you might add a new verb such as “wield” or “use.”

also, I hope you’ve studied the example “Lanista” in the documentation and “The Reliques of Tolti Aph” (out of date though it may be) on the I7 website, both of which feature randomized combat.

Now then. As far as combat/retreat goes, I imagine a couple of ways to do it. You could tag the player’s status:

[code]A person can be combative or peaceful. A person is usually peaceful.

Check attacking someone (called the target): now the player is combative; now the target is combative.
[/code]

Alternately you could make Combat a recurring scene, and Peace a recurring scene. One starts when the other ends. Roughly like this:

Combat is a recurring scene.  Peace is a recurring scene.  Peace begins when play begins.  Peace ends when Combat begins.  Peace begins when Combat ends.

Carry out attacking someone (called the target): now Peace is not happening; now Combat is happening.

Retreating is an action applying to nothing.  Understand "escape" or "retreat" as retreating.

Carry out retreating: 
if Peace is happening: say "There's nothing to retreat from here."; 
stop the action; 
otherwise:
if a 3 in 5 chance succeeds: 
say "You beat a hasty retreat!"; 
now Combat is not happening; 
otherwise: 
say "The [enemy] won't let you escape!";
stop the action.

Your mention of rolls makes me think you’re using the Reliques code. Why not use the code for leaving combat from that game also?

Merlin: did you mean something like this?

Instead of attacking a person (called the target) when the player carries a weapon (called the armament): try attacking the target with the armament.

I haven’t touched the Reliques code, actually. I don’t think. It’s just this one.

Ah, I see. Well, the combat works for me. So maybe something didn’t copy right, I’m not sure. The peace scene will work? I’m liking that idea. Considering the insane game I’m making, I should know more about the language. I know enough, just not how this bit works. :stuck_out_tongue:

When you post code in the forum, you should use “code” tags. Hit the “code” button up where the formatting buttons are and then paste your code in between where it says “code” in square brackets and where it says “/code” in square brackets. That’ll give you those nice code boxes that Merlin and Draconis has, and not only does it absolutely say where your code begins and ends, it preserves your formatting and makes it easier for other people to check your code. (Though I think the indentation got munged in Merlin’s code.)

One point is that I don’t think this will work right:

Every turn (this is the noun-attack rule): if the noun is not dead, try the noun attacking the player.

This seems like it will make whatever the noun was that turn attack the player. So if the player types “x me,” since the player is the noun, the player will attack themselves! If the player types “open door,” the door is the noun and the door will attack the player. That’s not what you want; find a way of storing the current combatant and use that instead.

(“The noun” should really only be used in rules for actions. It’s basically whatever the direct object of the action is. If there are two things involved, like “unlock door with key,” the first (the door) is the noun and the second (the key) is the second noun.)

Oh, okay. And I’ve been trying to get the code Merlin gave me to work, but I must be typing it wrong in all sorts of ways. The one in Reliques involves all sorts of leveling and stuff I don’t want to put into my game. Because you need that for the escape roll. Unless if I completely misunderstood that.

And I’ll continue with the attacking thing, then. I thought I had it. It had the “random weapon” line in there that I had to get rid of because it was messing with all of my actions. I’ll mess around with it some more. @_@ All I want is to attack people and not run off into the next room without some type of challenge or not being able to at all! Heh, crazy thing. This is pretty much the only thing that’s stopping me.

well, how about posting the relevant portions of your combat code? It’s hard to tell you what will work if we have no idea what you’re using right now.

What I put in those code boxes in my previous post was not actual code. I hadn’t tested it in I7 because my computer wasn’t handy. It was a paraphrasing of suggested code.

Okay, I clicked on the code button so hopefully I did the post right… Here’s what I’m using for the full combat. Oh, and I just tested the door thing. Nope, I’m not attacking any doors. Haha. :slight_smile:

[code]A weapon is a kind of thing. A weapon has a number called maximum damage. The maximum damage of a weapon is usually 5.

A club is a kind of weapon. The player carries a club. The Orc carries a club.

Understand the commands “attack” and “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as something new.

Attacking it with is an action applying to one visible thing and one carried thing. Understand “attack [someone] with [something preferably held]” as attacking it with.

Understand the commands “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as “attack”.

The attacking it with action has a number called the damage inflicted.

Setting action variables for attacking something with something:
if the second noun is a weapon:
let the maximum attack be the maximum damage of the second noun;
now the damage inflicted is a random number between 1 and the maximum attack.

Check an actor attacking something with something (this is the can’t attack with something that isn’t a weapon rule):
if the second noun is not a weapon:
if the actor is the player, say “[The second noun] does not qualify as a weapon.”;
stop the action.

Check an actor attacking something with something (this is the can’t attack a non-person rule):
if the noun is not a person:
if the actor is the player, say “[The noun] has no life to lose.”;
stop the action.

Carry out an actor attacking something with something (this is the standard attacking it with a weapon rule):
decrease the current hit points of the noun by the damage inflicted;
if the noun is dead:
now the noun is nowhere.

Report attacking a dead person with something (this is the death-report priority rule):
say “You attack with [the second noun], killing [the noun]!” instead.

Report attacking someone with something (this is the normal attacking report rule):
say “You attack [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

Report someone attacking the player with something when the player is dead (this is the player’s-death priority rule):
say “[The actor] attacks you with [the second noun], finishing you off!”;
end the story;
stop the action

Report someone attacking the player with something (this is the standard report someone attacking the player with rule):
say “[The actor] attacks you with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

Report someone attacking something with something (this is the standard report attacking it with rule):
say “[The actor] attacks [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

Every turn (this is the noun-attack rule):
if the noun is not dead, try the noun attacking the player.[/code]

well, that still doesn’t even slightly compile. Obviously you’ve left out some of your code (eg, the definition of a “dead person”). I would suggest you start by making a simple mini-game with only the combat code, and use that for testing.

meanwhile, here is one way to get enemies to attack the player, with a simple combative/peaceful flag:


Section 5 - Combat

A person can be combative or peaceful.  A person is usually peaceful.

Every turn (this is the combative-persons-attack rule):
	repeat with potential-enemy running through the people in the location of the player:
		if the potential-enemy is combative:
			try the potential-enemy attacking the player with a random weapon which is carried by the potential-enemy.


Section 6 - Taunting

[this section lets us turn combativeness on and off.]

Taunting is an action applying to one visible thing.  Understand "taunt [someone]" or "insult [someone]" as taunting.  [optionally you can allow taunting of inanimate objects, but using 'someone' means Inform will only allow it on people.]

Carry out taunting something (called the audience):
	if the audience is combative:
		say "[The audience] [are] already angry.";
		stop the action;
	otherwise:
		say "[The audience] [are] enraged by your taunts!  [They are] now ready to kill you.";
		now the audience is combative.
		
[note: this currently only works if the player taunts things.  If you order someone else to taunt something, nothing will happen.  More code is necessary if you want other people to taunt.]
					
Pacifying is an action applying to one visible thing.  Understand "pacify [someone]" as pacifying.  [optionally, you could kill the 'block saying sorry' rule and allow apologies to pacify.]

Carry out pacifying something (called the audience):
	if the audience is combative:
		if a random chance of 3 in 5 succeeds:
			say "[The audience] mellows out, and decides to show mercy.";
			now the audience is peaceful;
		otherwise:
			say "[The audience] [are] not swayed by your pleas for mercy.  [They] continues to press the attack!";
	otherwise:
		say "[The audience] [are not] interested in killing you.  There is no need to pacify [them]."

p.s. I got bored and fixed the whole thing, creating a mini-game that actually works.

Here it is in full.

[rant][code]
“Sandbox” by Merlin Fisher

Arena is a room. “Various persons, beasts, and things are fighting all around you. The roar of the crowd fails to drown out the screams, grunts, and clashes of metal.” [obviously if this were a real location, the crowd would be examinable scenery.]

Chapter 1 - Hit Points, Alive and Dead status

A person can be alive or dead. A person is usually alive. [setting this should allow I7 to understand what “dead person” means.]

A person has a number called maximum hit points. The maximum hit points of the player is 30.

The maximum hit points of a person is usually 20. [note: unless this is specified, I7 will default to 0.]

A person has a number called current hit points. The current hit points of the player is 30.

The current hit points of a person is usually 20. [ditto]

Every turn:
repeat with potential-corpse running through the people in the Arena:
if the current hit points of the potential-corpse is less than 1:
now the potential-corpse is dead;
say “[The potential-corpse] succumbs to [their] wounds. [Their] body is quickly carted off by the Arena attendants.”;
if the potential-corpse is not the player:
remove the potential-corpse from play;
otherwise:
end the story saying “You have died”.

When play begins:
now the left hand status line is “Health: [current hit points of player] / [maximum hit points of player]”.

[adding the latter tells the player what his max is, which is customary in RPGs, although if you prefer you may leave that a mystery of course.  It's especially helpful to know your max if the player is able to increase or decrease his max, for instance if he gains 'levels' or is affected by poison, fatigue, temporary strengthening spells, etc.]

After examining someone (called the examinee):
if the examinee is alive:
say “[The examinee] appears to currently have [current hit points of the examinee] out of [maximum hit points of the examinee] hit points. [run paragraph on]”;
if the examinee is combative:
say “[They] appears combative.”;
otherwise:
say “[They] appears peaceful.” [combative/peaceful will be discussed below.]

Section 1 - Weapons

A weapon is a kind of thing. [not specifying this will leave I7 confused when you start talking about weapons.]

A sword is a weapon. It is carried by the player. The maximum damage of the sword is 8.

A club is a weapon. It is carried by the player. The maximum damage of the club is 6.

A chocolate kettle is a thing. It is carried by the player. [this is to test whether attacking with non-weapons does anything.]

Test weapon with “attack bear with sword / attack bear with kettle / x bear”.

Chapter 1 - Attacking With, a new verb

Section 1 - Defining Attack With

Understand the commands “attack” and “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as something new.

Attacking it with is an action applying to one visible thing and one carried thing. Understand “attack [someone] with [something preferably held]” as attacking it with.

Understand the commands “punch” and “destroy” and “kill” and “murder” and “hit” and “thump” and “break” and “smash” and “torture” and “wreck” as “attack”.

Section 2 - Causing Damage

The attacking it with action has a number called the damage inflicted.

Every weapon has a number called maximum damage. The maximum damage of a weapon is usually 5.

Maximum attack is a number that varies.

Setting action variables for attacking something (called the target) with something (called the instrument):
if the instrument is a weapon:
let the maximum attack be the maximum damage of the instrument;
now the damage inflicted is a random number between 1 and the maximum attack.

Section 3 - Standard Messages

Check an actor attacking something (called the target) with something (called the instrument) (this is the can’t attack with something that isn’t a weapon rule):
if the instrument is not a weapon:
say “[The second noun] does not qualify as a weapon.”;
stop the action.

Check an actor attacking something (called the target) with something (called the instrument) (this is the can’t attack a non-person rule):
if the target is not a person:
if the actor is the player, say “[The noun] has no life to lose.”;
stop the action.

Check an actor attacking something (called the target) with something (called the instrument) (this is the can’t attack oneself rule):
if the actor is the target:
say “[The actor] refuses to attack [themselves].”;
stop the action.

Section 4 - Destroying People

[careful; if the game ever requires the player to attack a door, chest, or other inanimate object, this routine will foil the attempt.]

Carry out an actor attacking something (called the target) with something (called the instrument) (this is the standard attacking it with a weapon rule):
decrease the current hit points of the target by the damage inflicted.

Report attacking someone with something (this is the normal attacking report rule):
say “You attack [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!” instead.

[Report attacking a dead person (called the target) with something (called the instrument) (this is the death-report priority rule):
say “You attack with [the instrument], killing [the target]!” instead. ]

[I've blocked this out because I can't tell when it would be useful.  You must be using the "dead" flag differently than I have here.]

[Report someone (called the enemy) attacking the player with something (called the instrument) when the player is dead (this is the player’s-death priority rule):
say “[The enemy] attacks you with [the instrument], finishing you off!”;
end the story;
stop the action.]

[ditto.]

Report someone attacking something (called the target) with something (called the instrument) (this is the standard report attacking it with rule):
say “[The actor] attacks [the target] with [the instrument], causing [damage inflicted] point[s] of damage!” instead.

Section 5 - Combat

A person can be combative or peaceful. A person is usually peaceful.

Every turn (this is the combative-persons-attack rule):
repeat with potential-enemy running through the people in the Arena:
if the potential-enemy is combative:
try the potential-enemy attacking the player with a random weapon which is carried by the potential-enemy.

Section 6 - Taunting

[this section lets us turn combativeness on and off.]

Taunting is an action applying to one visible thing. Understand “taunt [someone]” or “insult [someone]” as taunting. [optionally you can allow taunting of inanimate objects, but using ‘someone’ means Inform will only allow it on people.]

Carry out taunting something (called the audience):
if the audience is combative:
say “[The audience] is already angry.”;
stop the action;
otherwise:
say “[The audience] is enraged by your taunts! It is now ready to kill you.”;
now the audience is combative.

[note: this currently only works if the player taunts things. If you order your minion to taunt something, nothing will happen. More code is necessary if you want other people to taunt.]

Pacifying is an action applying to one visible thing. Understand “pacify [someone]” as pacifying. [optionally, you could kill the ‘block saying sorry’ rule and allow apologies to pacify.]

Carry out pacifying something (called the audience):
if the audience is combative:
if a random chance of 3 in 5 succeeds:
say “[The audience] mellows out, and decides to show mercy.”;
now the audience is peaceful;
otherwise:
say “[The audience] is not swayed by your pleas for mercy. [They] continues to press the attack!”;
otherwise:
say “[The audience] [are not] interested in killing you. There is no need to pacify [them].”

Test taunt with “x henchman / taunt henchman / x henchman / pacify henchman / pacify henchman / x henchman”.

Chapter 0 - Not for release - Combat Test victims

Section 1 - Punching bag

The teddy bear is a neuter person in Arena. “A life-size teddy bear rests against the wall, waiting for someone to beat the stuffing out of it.” [the bear is alive but will not fight back.] The maximum hit points of the teddy bear is 10. The current hit points of the bear is 10.

Test bear with “attack bear with club / g / g / x bear / retreat / attack bear”.

Section 2 - Furniture

The wooden column is an enterable supporter in Arena. “A short column with steps leading up to it, marked ‘WINNER,’ is in the center of the arena.” [this is here to test what happens when the player attacks inanimate objects. It can also test his ability to attack things while he is standing on something.]

Test column with “attack column with club / get on column / attack column / attack bear / retreat / x column”.

Section 3 - Unbeatable enemy

The scarlet dragon is a female person in Arena. Understand “red” as the scarlet dragon. “Stalking here and there, occasionally commenting on the battles, is a magnificent scarlet dragon.” [the dragon is a test subject that is guaranteed to beat the player.] The maximum hit points of the dragon is 100. The current hit points of the dragon is 100.

The fiery breath is a weapon. It is carried by the dragon. [more likely we’d want to make the weapon part of the dragon, but let’s skip that for now.] The maximum damage of the fiery breath is 20.

Test dragon with “dragon, attack me / attack dragon with club / x dragon / retreat / x dragon / attack dragon / g / g / g”.

Section 4 - Minion

The obedient henchman is a male person in Arena. Understand “minion” or “friend” or “Kenny” as the obedient henchman. “Your obedient henchman is here, awaiting your orders.” [this is to see if the attack rules work for OTHER people.] The maximum hit points of the henchman is 20. The current hit points of the henchman is 20.

The mace is a weapon. It is carried by the obedient henchman. The maximum damage of the mace is 5.

The cotton candy is a thing. It is carried by the obedient henchman.

Persuasion rule for asking the obedient henchman to try doing something:
persuasion succeeds.

Test minion with “x minion / minion, kill bear with mace / x bear / minion, kill minion with mace / minion, kill minion with cotton candy / minion, kill bear with cotton candy / minion, kill me with cotton candy / x minion / minion, kill me with mace / minion, kill dragon with mace / g / g / g”.

[/code][/rant]

Eh? I thought I just responded? I don’t see it… Oh well. Yeah, I forgot to leave out the definition.

Definition: a person is dead if his current hit points are less than 0.

Sorry about that. Anyway, thanks again! It looks really good. I messed around with the money stuff while I was hoping for an answer. That system is solid now. All I need is the escape and this crazy game that has over 6,000 words in it can actually get started!

I had to get rid of the “random weapons” lines from my game, though. For some reason, it messed up every action I had. Kept on getting errors. The rest of the combat code I used worked fine without it, so I didn’t think it was a problem.