Pixie's Simple Combat Library is best for people new to this stuff (and~or want an 'open' combat system), but if you're more interested in a 'script-locked' (you're stuck in the battle sequence until you win, you lose, you run away, or monster runs away) combat system, you can take a look at my (using a variation of Pertex' Combat Library code ~ all credit goes to Pertex) combat code, though it is a bit more complex in design, but at least maybe it can help you see and get some ideas at doing combat:
viewtopic.php?f=10&t=3348&start=120#p22483and just search my posts for~on 'attributes' and~or 'if' scripts, as I got a lot of posts explaining these things, lol.
-----------
conceptually:
1. both characters ( 'player' Player Object and 'orc' Object) need a 'life' Integer Attribute
2. both characters ( 'player' Player Object and 'orc' Object) need a 'damage' Integer Attribute
3. the 'orc' Object needs a 'dead' Boolean Attribute that is set to Value: false
4. the 'orc' Object needs a 'fight' Verb
5. inside the 'orc' Object's 'fight' Verb, you want this (in code) setup:
with my comments:
// you check if the 'orc' is not dead (if so: subsequently do battling scripts) or dead (if so: subsequently msg that the orc is already dead ~ see the very bottom of this code block):
if (orc.dead = false) {
// you go first, attacking the orc:
orc.life = orc.life - player.damage
msg ("You attack the orc, hitting it for " + player.damage + " damage, leaving it with only " + orc.life + " life left.")
// you check if the orc is dead (via if it has 0 or less life):
if (orc.life <= 0) {
// you alter~re-set the 'orc' Object's 'dead' Boolean Attribute to now having the Value of 'true', making it be 'dead' :
orc.dead = true
msg ("You killed the orc.")
// if the orc is not dead (if it has more than 0 life remaining), it now attacks you:
} else {
player.life = player.life - orc.damage
msg ("The orc attacks you for " + orc.damage + " damage, leaving you with only " + player.life + " left.")
// we check if you're dead (via if your life is 0 or less), and if you are, we msg it and that the game is over, and lastly, we end the game:
if (player.life <= 0) {
msg ("You were killed by the orc.")
msg ("GAME OVER")
finish
// this below is to loop~continue the combat sequence until you or the orc is killed, locking you into the battle sequence, preventing you from doing anything else, until the battle is over:
} else {
// this entire 'fight' scripting block would have to be put inside of a Function (which the Function would be called upon from within your 'orc' Object's 'fight' Verb), so that you can then use this here code line to 'call upon' this Function, to loop~run through it again
}
}
// remember, we got to deal with if the orc is already dead (see the very top comment):
} else if (orc.dead = true) {
msg ("The orc is already dead, silly. You can't fight a dead rotting corpse!")
}
without my comments, full code (using looping ~ as a Function):
the 'orc' Object's 'fight' Script Attribute (GUI~Editor: Verb) and the 'fight' Verb (the GUI~Editor automatically creates this for you):
<object name="orc">
<inherit name="editor_object" />
<parent type="object">room</parent>
<fight type="script">
orc_fight_function
</fight>
</object>
<verb>
<property>fight</property>
<pattern>fight</pattern>
<defaultexpression>You can't fight that!</defaultexpression>
</verb>
the 'orc_fight_function' Function:
<function name="orc_fight_function">
if (orc.dead = false) {
orc.life = orc.life - player.damage
msg ("You attack the orc, hitting it for " + player.damage + " damage, leaving it with only " + orc.life + " life left.")
if (orc.life <= 0) {
orc.dead = true
msg ("You killed the orc.")
} else {
player.life = player.life - orc.damage
msg ("The orc attacks you for " + orc.damage + " damage, leaving you with only " + player.life + " left.")
if (player.life <= 0) {
msg ("You were killed by the orc.")
msg ("GAME OVER")
finish
} else {
orc_fight_function
}
}
} else {
msg ("The orc is already dead, silly. You can't fight a dead rotting corpse!")
}
</function>