Code for basic combat. Feel free to use it in your story or modify it.
Copy this into your startup.txt
*comment attribute
*create strength 20
*create agility 20
*comment skills
*create combat 20
*create weapons 20
*create stealth 20
*comment status
*create health 100
*comment booleans
*create has_dagger false
*create has_bow false
*create has_poison false
*comment fight
*create opp_awareness 0
*create weapon ""
*create armor ""
*create weapon_range 0
*create weapon_atk 0
*create armor_def 0
*create weapon_speed 0
*create armor_weight 0
*create opp_health 0
*create opp_strength 0
*create opp_agility 0
*create opp_strength 0
*create opp_alerted false
*create opp_name ""
*create opp_dist 0
Make a file called combat_util.txt in the same folder as your startup.txt, then copy this bit in to combat_util.txt
*label check_health
*if health <= 0
*set health 0
Your health is depleted, you died.
*goto_scene ending
*return
*label switchweapon
*if (weapon="dagger")
*set weapon_range 5
*set weapon_atk 5
*if (weapon="bow")
*set weapon_range 50
*set weapon_atk 4
*if (weapon="longsword")
*set weapon_range 10
*set weapon_atk 7
*if (weapon="unequipped")
*set weapon_range 5
*set weapon_atk 0
*return
*label fight
*temp won false
*temp escaped false
*temp attack ((strength/10)+weapon_atk)
*temp def (strength/10)+armor_def
*temp opp_health_max opp_health
*temp opp_health_percent 0
*temp player_actions agility
*temp opp_actions opp_agility
*if (player_actions>opp_actions)
*set player_actions (player_actions/opp_actions)
*set opp_actions 1
*if (opp_actions>player_actions)
*set opp_actions (opp_actions/player_actions)
*set player_actions 1
*set player_actions (player_actions*10)
*set opp_actions (opp_actions*10)
*temp bow_stage 0
*temp weapon_poisoned false
*temp facing_opp true
*temp fight_msg "You have encountered an enemy"
*temp player_action_point player_actions
*temp opp_action_point opp_actions
*gosub display_fight_stats
*page_break
*goto turn
*return
*label turn
*set player_action_point player_actions
*set opp_action_point opp_actions
*gosub opp_turn
*gosub player_turn
*if (won)
*page_break
You are victorious.
*return
*if (escaped)
*page_break
You have escaped.
*return
*goto turn
*return
*label display_fight_stats
*set opp_health_percent (opp_health/opp_health_max)*100
${fight_msg}
You are fighting ${opp_name}
Distance: ${opp_dist}
Enemy Attack: ${opp_strength}
Enemy Action: ${opp_action_point}
Enemy Health:
*stat_chart
percent opp_health_percent Health
Your Attack: ${attack}
Your Actions: ${player_action_point}
Your Health:
*stat_chart
percent health Health
*return
*label opp_turn
*page_break
*if (opp_action_point=0)
*set fight_msg "Your turn"
*return
*if (opp_alerted = false)
*set fight_msg "The enemy doesn't see you"
*return
*if (opp_action_point<10)
opp_action_point = 0
*if (opp_dist<=5)
*set opp_action_point - 10
*set health - opp_strength
*gosub check_health
*set fight_msg "Enemy attacks you bare handed"
*if (opp_dist>5)
*set opp_action_point - 10
*if (opp_dist<opp_agility)
*set opp_dist 5
*if (opp_dist>opp_agility)
*set opp_dist - opp_agility
*set fight_msg "Enemy approaches you"
*gosub display_fight_stats
*goto opp_turn
*return
*label player_turn
*page_break
*if (player_action_point<=0)
*gosub display_fight_stats
*return
*if (opp_health<1)
*set won true
*return
*temp attack ((strength/10)+(weapon_atk*(1+(weapons/100))))
*gosub display_fight_stats
*temp can_poison_weapon
*fake_choice
#Maneuvers
*set fight_msg "Choose a manuver"
*set player_action_point - 10
*gosub display_fight_stats
*choice
#Walk
*set fight_msg "You walked forward"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness+10))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility*0.5))
*set opp_dist - (agility*0.5)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility*0.5)
*goto player_turn
#Backstep
*set fight_msg "You take a few steps back"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness+5))
*set opp_alerted true
*if (facing_opp)
*set opp_dist + (agility*0.33)
*goto player_turn
*elseif (opp_dist>(agility*0.33))
*set opp_dist - (agility*0.33)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
#Turn around
*set fight_msg "You make a quick turn"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness+5))
*set opp_alerted true
*if (facing_opp)
*set facing_opp false
*goto player_turn
*else
*set facing_opp true
*goto player_turn
#Run
*set fight_msg "You run as fast as you could"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness+20))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility*0.7))
*set opp_dist - (agility*0.7)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility*0.7)
*goto player_turn
*selectable_if (agility>=20) #Sprint
*set fight_msg "You sprinted at your top speed, making clacking cacophonies with your footwear"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness+40))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>agility)
*set opp_dist - agility
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + agility
*goto player_turn
*selectable_if (stealth>=20) #Leopard crawl
*set fight_msg "Like a militia you went down on your front and crawled awkwardly"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility*0.33))
*set opp_dist - (agility*0.33)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility*0.33)
*goto player_turn
*selectable_if (agility>=80) #Dash
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness + 30))
*set opp_alerted true
*if (facing_opp)
*set fight_msg "In the blink of an eye you dashed towards your opponent, leaving a trail of blurry shadows behind you"
*if (opp_dist>(agility * 1.5))
*set opp_dist - (agility * 1.5)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set fight_msg "In the blink of an eye you dashed away from your opponent, leaving a trail of blurry shadows behind you"
*set opp_dist + (agility * 1.5)
*goto player_turn
*selectable_if (stealth>=40) #Cat walk
*set fight_msg "Footsteps as light as a cat, you slipped across"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility*0.5))
*set opp_dist - (agility*0.5)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility*0.5)
*goto player_turn
*selectable_if (stealth>=50) #Efficient silent strides
*set fight_msg "You silently but swiftly strode"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility/1.5))
*set opp_dist - (agility/1.5)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility/1.5)
*goto player_turn
*selectable_if ((agility>=20) and (stealth>=60)) #Silent run
*set fight_msg "You run stealthily, without losing any pace"
*if (((1 + (stealth / 100)) *opp_dist) < (opp_awareness))
*set opp_alerted true
*if (facing_opp)
*if (opp_dist>(agility*0.7))
*set opp_dist - (agility*0.7)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*else
*set opp_dist + (agility*0.7)
*goto player_turn
*selectable_if ((agility>=60) and (stealth>=60)) #Evade
*set fight_msg "The opponent is unable to track your position through sight alone, to them, you have faded from existence"
*set opp_alerted false
*if (facing_opp)
*set opp_dist + (agility*0.33)
*goto player_turn
*elseif (opp_dist>(agility*0.33))
*set opp_dist - (agility*0.33)
*goto player_turn
*else
*set opp_dist 0
*goto player_turn
*selectable_if ((agility>=80) and (stealth>=80)) #Blink
*set opp_alerted false
*if (facing_opp)
*set fight_msg "With this overpowered maneuver, you can instantly arrive at the opponent's position without them even realising"
*set opp_dist 0
*goto player_turn
*else
*set fight_msg "The prerequisite for flight is blinking away without your opponent noticing, but it is also excellent for ranged retaliation"
*set opp_dist + (agility*2)
*goto player_turn
#Go back
*set player_action_point +10
*goto player_turn
*selectable_if (opp_dist<=5) #Unarmed combat
*set opp_alerted true
*set fight_msg "Choose an unarmed melee move"
*gosub display_fight_stats
*choice
#Throw in a jab to the chest
*set opp_health - (attack-weapon_atk)
*set player_action_point - 5
*set fight_msg "You punched your opponent in the chest"
*goto player_turn
*selectable_if (combat>=20) #Throw a hook to the face
*set opp_health - ((attack-weapon_atk)+(combat/10))
*set player_action_point - 5
*set fight_msg "You punched your opponent in the face"
*goto player_turn
*selectable_if (combat>=40) #Turning side kick to the head
*set opp_health - ((attack-weapon_atk)+(combat/7))
*set player_action_point - 10
*set fight_msg "You kicked your opponent in the face"
*goto player_turn
*selectable_if (combat>=50) #Roundhouse kick to the neck
*set opp_health - ((attack-weapon_atk)+(combat/5))
*set player_action_point - 15
*set fight_msg "You roundhouse kicked your opponent in the back of their neck"
*goto player_turn
*selectable_if (combat>=60) #Flying reverse roundhouse kick
*set opp_health - (((attack-weapon_atk)+10)+(combat/5))
*set player_action_point - 15
*set fight_msg "You roundhouse kicked your opponent in the face"
*goto player_turn
*selectable_if (combat>=70) #Quick combo: jab, hook, side kick
*set opp_health - ((attack-weapon_atk)+2)
*set opp_health - ((attack-weapon_atk)+(combat/10))
*set opp_health - ((attack-weapon_atk)+(combat/7))
*set player_action_point - 15
*set fight_msg "You performed a quick set of combos"
*goto player_turn
*selectable_if (combat>=80) #Forearm headlock, then repetitive knee strikes to the head
*temp luck 0
*rand luck 0 8
*set opp_health - (((attack-weapon_atk)+(combat/10))*luck)
*set player_action_point - 15
*set fight_msg "You kneed the opponent"
*goto player_turn
*selectable_if (combat>=90) #Master combo: reverse wristlock, downward wrist breaker, elbow head strike, face jab, double left right side kick, flying reverse roundhouse kick, headscissors
*set opp_health - ((attack-weapon_atk)+(combat/1.5))
*set player_action_point - 30
#Change weapon
*set fight_msg "Choose your main equipement"
*gosub display_fight_stats
*choice
#Unequip
*set weapon "unequipped"
*set player_action_point - 5
*gosub switchweapon
*set fight_msg "You equipped fist"
*goto player_turn
*if (has_dagger) #Dagger
*set opp_alerted true
*set weapon "dagger"
*set player_action_point - 5
*gosub switchweapon
*set fight_msg "You equipped dagger"
*goto player_turn
*if (has_bow) #Bow
*set weapon "bow"
*set player_action_point - 5
*gosub switchweapon
*set fight_msg "You equipped bow"
*goto player_turn
#Go back
*goto player_turn
*if (weapon="dagger")
*selectable_if ((opp_dist<=weapon_range) and (player_action_point>=5)) #Use dagger
*set fight_msg "How would you like to use your dagger?"
*gosub display_fight_stats
*choice
#Stab whereever
*set opp_alerted true
*if (weapon_poisoned)
*set attack + 10
*set opp_health - (attack+(weapons/5))
*set player_action_point - 5
*set fight_msg "You stabbed the opponent in the arm"
*goto player_turn
*if (weapons >= 20)
#Lateral cut
*set opp_alerted true
*if (weapon_poisoned)
*set attack + 10
*set opp_health - ((attack+(weapons/5))*1.5)
*set player_action_point - 5
*set fight_msg "You cut the opponent's chest, they're bleeding badly"
*goto player_turn
*if (weapons >= 50)
#Neck stab
*set opp_alerted true
*if (weapon_poisoned)
*set attack + 10
*set opp_health - ((attack+(weapons/5))*2)
*set player_action_point - 5
*set fight_msg "You stabbed the opponent's neck, what a savage move"
*goto player_turn
*if (weapons >= 80)
#Slice and dice
*set opp_alerted true
*if (weapon_poisoned)
*set attack + 10
*set opp_health - ((attack+(weapons/5))*3)
*set player_action_point - 5
*set fight_msg "After a sequence of flashes in the air, your opponent gained numerous wounds"
*goto player_turn
#Go back
*set fight_msg "You didn't know what you wanted to do with your dagger"
*goto player_turn
*if ((weapon="bow") and (bow_stage=0))
*selectable_if (player_action_point>=10) #Load bow
*set bow_stage 1
*set player_action_point - 10
*set fight_msg "You loaded an arrow"
*goto player_turn
*if ((weapon="bow") and (bow_stage=1))
*selectable_if (player_action_point>=10) #Draw bow
*set bow_stage 2
*set player_action_point - 10
*set fight_msg "You aim and draw"
*goto player_turn
*if ((weapon="bow") and (bow_stage=2))
*selectable_if ((opp_dist<=weapon_range) and (player_action_point>=10)) #Fire arrow
*set opp_alerted true
*set bow_stage 0
*if (weapon_poisoned)
*set attack + 10
*set weapon_poisoned false
*set opp_health - attack
*set player_action_point - 10
*set weapon_poisoned false
*set fight_msg "You fired an arrow"
*goto player_turn
*if (has_poison)
*selectable_if ((weapon != "unequipped") and (player_action_point>=10)) #Poison weapon
*set weapon_poisoned true
*set fight_msg "You poisoned your weapon"
*set player_action_point - 10
*goto player_turn
#Do nothing
*set player_action_point 0
*set fight_msg "You did nothing"
#Escape
*temp luck 0
*rand luck 0 6
*if (((luck) + (agility/opp_agility))>6)
*set escaped true
*return
*else
*set fight_msg "You failed to escape"
*set player_action_point - 10
*goto player_turn
*return
Then just put this bit of code into where you want to have the fight. Change these variables or rid of them as you will.
*set combat 40
*set agility 40
*set stealth 40
*set weapons 40
*set has_dagger true
*set has_bow true
*set has_poison true
*set weapon "unequipped"
*gosub_scene fighter switchweapon
*set opp_awareness 100
*set opp_name "Guard"
*set opp_health 200
*set opp_agility 20
*set opp_strength 10
*set opp_alerted false
*set opp_health 200
*set opp_dist 50
*gosub_scene combat_util fight