Questions on turn based combat

Tomsa
05 Apr 2009, 13:53
I have a few questions regarding turn based combat.

1. How do I do the actual taking turns part, i e the player getting to attack the foe after he has attacked me, and so forth?

2. I have a dagger, which can do 2-5 damage, and a foe, who has 12 HP. How do I pull off this "dice roll"? Same goes for the foe, doing 3-7 damage for each turn.

3. Equipped/unequipped: how do I make the player do 1-3 damage when unarmed versus 2-5 damage when equipped with the aforementioned dagger?

Redsun
05 Apr 2009, 21:41
create stat vars, like strength, agility, health etc, these will be number vars.
the monster/enemy also has stats as well

add commands so that an item can be equipped, you do this by making commands like: "equip rusted axe" for example, once
the player types this the rusted axe in inventory is moved to another room and the player is givin an item called: rusted axe(equipped)
and his stats are boosted a tad bit as well.

player can type: "unequip rusted axe" and stats are reverted back to normal and "rusted axe(equipped) is moved to the hidden room and It's
replaced with "rusted axe".

for combat do not use menues(unless you really want to, some people perfer that design choice).
instead I use options within the room.

there will be several options for the player, for example: fight, run etc.
1. Fight
2. Run

now if the player types 1 and hit enter he engages the enemy, another choice options can be added like
Magic/Skill
Item
Flee
Attack
etc

if for example player types 1 the option 1 is 1. ATTACK then the player will attack the enemy with the weapon in hand
or fist if no weapon is in hand, for that turn you can compare the players attack power to the enemies defence and subtract
the results from the enemies health, then if that brings the enemies HP to 0 or below then Kill enemy.
if not allow Enemy to fight back, using a choice based off of an AI proc that you wrote.

If you kill enemy, display any loot and give player experience.
if experience reaches a certain amount then reset the experience var and level up player etc, how ever the game design
will be.

the fight will not take place until player chooses a combat option this way it is turned base.

Tomsa
07 Apr 2009, 10:41
I dabbled with this yesterday, so let's see if I got it right.

When I enter a room, I am encountered by a goblin with the stat var "goblin HP", which has the value 10. This triggers the procedure "my attack choices". If I choose "attack", I will strike the enemy with the weapon in hand, decrementing the value of "goblin HP" If I choose "magic", I get to choose "fireball, heal, etc" from a different procedure, decrementing the value from the stat var "mana".

When I have attacked, the AI proc will start. Goblin attacks me and decrements the value of the stat var "health", then triggers "my attack choices" again. If "health" reaches 0, the game over text block will be displayed, but if the goblin is slain, I will display loot and end all of the procedures.

Furter questions:

1. So far, my attack does 5 damage to the enemy HP, but I want to do 2-5 damage, with the additional chance of missing the target completely. How to do this "dice roll"?

2. How do you group enemies? By property or type? Example: If goblin (or any other object) has the property of "enemy", combat procedures will ensue, but if goblin (or any other object) has the property of "dead", no procedures will start.

3. If strenght has the value 4, equaling 2-5 attack damage, how do you make a leveled up strenght of 6 equal, say, 3-7 attack damage. What kind of system do you use in order to manage all status variables?

Redsun
07 Apr 2009, 12:50
Yes thats correct, also in the AI enemy proc you can have it so the enemy has a chance
of healing itself, running etc this way It seems more Dynamic and more Like the enemy is trying to defeat
you and/or Live.

I Usually give every enemy a Tag, this way I can write one proc and have
all AI bahaviors under one proc.

so in the main encounter/AI proc it'll start like this

if enemy var is equal to Goblin then run the Goblin AI data
if enemy var is equal to Orge then run the Orge AI data
etc

so now depending on the location and what monsters reside there(can be random)

enemynum var holds $rand(1, 2)$
if enemynum var is equal to 1 then change enemy var to Goblin and run the encounter/AI proc
if enemynum var is equal to 2 then change enemy var to Orge and run the encounter/AI proc
etc

Same goes for if you sometimes want a chance to miss the enemy.
enemynum var holds $rand(1, 10)$
if enemynum is equal to 8 or less then begin the comparison of the Defence versus strength so that player will hit enemy according to stats
else miss the enemy and display a message to player.

But I'd do it more realisticly, to see if player may miss you'd first compare both players agility with the enemies agility(or whatever stat name you choose)
so Lets say player has a stat called: Agility(of course then the enemy does to) and Players Agility is
lets say 10 and the Enemies is 8, there are many ways to compare this and everyone has thier own preferences but I'll do the most easiest way
just to show you an example, Your Agility is higher by two points so you could do this

if pagility is greater then egoblin agility then
enemynum var holds $rand(1, 10)$
if enemynum is equal to or less then 9 then run the Goblin AI data
else It's 10 then miss the enemy

This way there is always a chance to miss the enemy, though not a great chance but It's still there.

Now if Enemies agility was higher it can be
enemynum var holds $rand(1, 10)$
if enemynum is equal to 5 or less then run the Goblin AI data
else It must be 6 to 10 and in that case miss the enemy.

enemynum can be used for multiple purposes, but I'm using the name as an example only.

There are so many different ways to write this and it can be very complex, I'm only using this way as an example.

also It's 2 folds, Enemy attacks you a very simular statement will run just as when you attack enemy.
But you can make it so enemies act different then each other.

1. So far, my attack does 5 damage to the enemy HP, but I want to do 2-5 damage, with the additional chance of missing the target completely. How to do this "dice roll"?
Hard to write this on a forum but I'll do the best to explain how to do this.

When you attack an enemy you could use pdamage var holds $rand(2, 5)$
so everytime you attack decrep enemy health by pdamage
to make it miss sometimes, pretty much follow with what I said up top.

2. How do you group enemies? By property or type? Example: If goblin (or any other object) has the property of "enemy", combat procedures will ensue, but if goblin (or any other object) has the property of "dead", no procedures will start.
I usually don't group them like this, but then again I never dabbled much with this.
How ever Is your Enemy an Object that is listed in the room or simply a step monster? like Final Fantasy games?

3. If strenght has the value 4, equaling 2-5 attack damage, how do you make a leveled up strenght of 6 equal, say, 3-7 attack damage. What kind of system do you use in order to manage all status variables?
Usually every level I give the player a points or so to put into a chosen stat but the weapon in hand also strongly Influences the attack power.
so if it was 2-5 next point would be 4 to 7 on top of whatever the weapon damage does, so if weapon does 11-19 damage then it could
be 13-24 or 15-26 damage, so pdamage can now be $rand(15, 26)$

Redsun
07 Apr 2009, 12:56
also Don't forget to after killing enemy reset It's stats to original values so it can be reused.

Tomsa
11 May 2009, 15:50
I also have some questions about equipping and unequipping weapons.

I have a weapon rack with three weapons in it. The weapons are dagger, gladius and claymore.

I have created two commands: equip and unequip (equip #@weaponsandarmor#)

Each of the weapons has the property of "equipable". Or should I use actions? In that case, how?

When equipped, I want to set a flag, i e "dagger equipped".

QUESTIONS: What do I put into the #@weaponsandarmor" string variable? When I equip a weapon, I would like it to say "You equip the dagger" respectively "You equip the claymore", and of course, set above mentioned flag.

Redsun
11 May 2009, 16:27
For weapons you'd print to the screen, "You equiped the #weapon#", for armor, you print to the screen " You put on the #armor#."

This is how I'd do it but It is not the only way to do it.

I Usually don't dabble to much with properties, so maybe someone else can help you better with that question.

But here is how I'd do it, First Armor and Weapons shouldn't use the same command.
Weapons you'd "equip", armor you'd "put on"

so if I type: Equip claymore, set the flag to on, romove claymore from inventory to a hidden room, replace it
with an equiped version of the claymore but the name is: Clamore(equiped) or Claymore(E).

If you type: unequip claymore then romove Claymore(E) to the hidden room, replace it with the other Claymore
that was there before, and set flag to off.

Use another variable called #weapon#, so that you can print to the screen: You just equiped the #weapon#!
This way when the weapon is equiped just Change the #weapon# var to Claymore for example.
Some people would argue that you don't need to use such a var like #weapon#, but I'd use it to shorten my work
and so it can be display easily if you so choose.

also You need to make sure the player has the Claymore in his Inventory, not just on the ground in the room, so each Armor, weapon will
have two flags, one to check if it's in Inventory, one to check if It's not already equiped.

So lets say I typed: equip claymore
IF hasClaymore flag "IS" set then
IF equipClaymore flag is "NOT" set then
Set equipClaymore flag to on
Move Claymore object from inventory and put it in the Hidden room
Give to the player the object: Claymore(E)
Change the var #weapon# put in it "Claymore"
Print to the screen: You equiped the #weapon#!
ELSE equipClaymore flag is already on
Print "You already have the #weapon# equiped.
ELSE hasClaymore flag is "NOT" set then
You are not carrying a Claymore!"in red print"

Also make it so when the player picks up the weapon from the ground, the hasClaymore flag turns
on so the game knows the player has it.

Not sure if this helped you or made it more confusing LOL :)

Tomsa
12 May 2009, 10:49
Thank you, I think I can manage from there, will try it out tonight. One quick question though: Instead of moving the weapon to a hidden room and replacing it with an equipped version, is it possible to just modify the property of the weapon to "equipped", as compared to "not equipped"?

Overcat
12 May 2009, 15:26

is it possible to just modify the property of the weapon to "equipped", as compared to "not equipped"?



Of course. You sound like you already know the answer to that question. Am I wrong?

Using a property for "equip" and "unequip" makes your game more manageable - you only need one copy of an item, instead of two! Having more than one way to accomplish something, however, is always good.

Redsun
12 May 2009, 21:54
Yes it is possible, Just I don't dabble to much(yet) with types and properties and didn't want to act as if I knew what I was talking about
when I don't, so I only told you a way to do it that I know would work.

Tomsa
15 May 2009, 12:07
I have tried both ways now. I tend to use properties in this case, but it depends on how many weapons you need for your game. In my honest opinion, this seems to be a lot of work, especially if you compare this gaming style to a simple adventure game, where you can focus on prose and puzzles.

My alternative to the equip-command:

"Having an object with the property 'weapon' in your inventory sets the flag 'weapon_equiped' to on", that is, "having" equals "equipping". This way, you avoid being a pack-mule, because you can only carry one weapon at a time - the weapon equipped. Same should go for armor items. Besides, it would not be realistic if you could carry 19 halberds in one backpack.
What do you think of this?

Also, I have one more question (for the moment)... If "dagger" does 2-5 damage and "claymore" does 15-25 damage, can I use select case to differ between them when attacking an enemy (decrementing the num var "enemy HP")? For example, if "dagger" is in inventory, decrement num var 2-5 damage.

Redsun
15 May 2009, 22:48
I Think You should beable to carry a sword and Dagger at the same time, This is possible and realistic, This
is how it was back in the ancient days, Daggers are small and light.

So depending on this decision will depend on how you write the code.

Overcat
16 May 2009, 22:00

Also, I have one more question (for the moment)... If "dagger" does 2-5 damage and "claymore" does 15-25 damage, can I use select case to differ between them when attacking an enemy (decrementing the num var "enemy HP")? For example, if "dagger" is in inventory, decrement num var 2-5 damage.



It might be good to keep all the information about the weapon on the weapon itself. That is, give every weapon 'lowDamage' and 'highDamage' properties that hold the minimum and maximum damage respectively.

define object <SomeWeapon>

...
properties <lowDamage = 2; highDamage = 5>
...

end define

define object <AnotherWeapon>

...
properties <lowDamage = 6; highDamage = 10>
...

end define


When a successful attack is made, generate a random number for damage based on the properties of the weapon used for the attack:

set numeric <damageDealt; $rand(#(WeaponUsed):lowDamage#; #(WeaponUsed):highDamage#)$>
property <#SomeEnemy#; hitPoints = #(SomeEnemy):hitPoints# - %damageDealt%>


Besides, it would not be realistic if you could carry 19 halberds in one backpack.



Be careful about how far you're willing to take the 'realistic' line. A text 'game' as opposed to IF (interactive fiction) must necessarily sacrifice all sorts of realism in order to make the project plausible. Although no text creation can ever perfectly mimic reality, RPG's by definition incorporate gamist elements that simplify, rather than exemplify, reality. I think 'gamers' realize this and are down with it, for the most part. IF afficionado's, however, may not be so willing to put up with these mechanisms. In which case I would caution against advertising any project that is 'gamist' as 'interactive fiction'. (Not that this is your intent.)

Point is, if you're writing an RPG be prepared to either dispense with a lot of realism or cut your project size by 90% (maybe more). :)

But in the end, I must say, Fun is more important than Perfection! (And I certainly wouldn't let a player carry 19 halberds in their backpack!)