RPG-style Combat Library

The Pixie
We get people asking about making RPG-type games in Quest quite a lot. It is not straightforward! However, it did inspire me to create this library. It covers combat, magic, buying and selling and lots more. A demo can be played here:

http://textadventures.co.uk/games/view/ ... est-combat

This library offers a relatively simple, but comprehensive combat system, the basic mechanics being somewhat like D&D (d20, no hit locations). The system can be modified in various ways, some easier than others. Free feel to modify it as you like (but credit me!).

A character is defined by four statistics; strength, stamina, intelligence, agility. Strength determines what armour can be worn, increases weapon damage and chances to hit. Agility also affects the chances to hit, as well as the character's defence. Stamina determines hit points, intelligence the level of spell that can be learnt and cast.

Download:

Version 02 corrects a bug in the demo game with the Teleport spell and slightly changes how player death is handled (following a PM from someone). The modified files are CombatStuff.xml, CombatDemo.aslx, CombatTypes.xml and notes.txt; if you have already downloaded and installed the library, you should download the new version and replace the old versions of those files. If you have not edited those files yourself, there should be no effect on your game.


Original:


The download includes the demo game and a text file called notes.txt that explains how to do a lot of things; if you are trying to work out what is going on, or ghow to set something up, try there first.

Installation guide:

1. Add the library

Download the ZIP file, and extract all the files to your game folder (you do not actually need CombatDemo.aslx or notes.txt, but you do need the other nine).

Open you game up in Quest, and in the left hand pane, expand "Advanced", at the very bottom. Click on "Included libraries", then, in the right pane, click on "Add". By Filename, click on None, to open the drop down list. CombatLib.aslx should be there (probably at the top). Select it, then save your game and reload (you should see a "Reload" button towards the top right.



2. Edit the start script

Click on the "game" object in the left pane, then go to the "Script" tab. Towards the top, it says "Start script", followed by a series of icons. Click on the seventh, "Code view". A text box will appear. Paste this in:

CombatInitialise(true)


This will set up all sorts of stuff when the game starts, and initiate the character creation process. Alternatively, use this to skip character creation (very useful when testing):

CombatInitialise(false)


3. Create

Now you need to create your world. As you populate it, go to the "Combat" tab, and set objects to be the appropriate thing. The readme.txt file in the download describes those options if it is not obvious. Take a look at how it was done in the demo too.

Edit: Corrected the link to ther demo game.

HegemonKhan
thanks pixie, as all these libraries~codings really help us noobs with learning to code better and more, they're of such great help to us to study and learn from, as well as using them to make our game making easier with quest, helping out quest, opening it up for more non-coders to do more with quest and their games with quest.

The Pixie
All the fancy coding (basically tabs and types) you can read about in these guides in the "How to" section of the documentation:

• Using Types and Tabs (Advanced)
• More on Tabs (Advanced) (implementing a magic system)
• Simple Combat System (Advanced)
• Second Inventory Pane (Advanced) (listing spells for your magic system)

HegemonKhan
Oh, for me, I already know of them, from trying to learn how you did your magic system, your 'Spell~Magic Library' (before the new wiki conversion), hehe :D

(I haven't worked with the 'tabs' in a long time, as I don't use the GUI~Editor anymore, so I've forgotten how to do~create them, I'd have to re-learn, but again not too much reason to do so, as for myself, I don't need them, as I try to code, hehe)

though I'm sure in your code, you also do some fancy stuff which will be of use, when I get around to checking it out (haven't looked at yours or Jay's yet as I'm still without a pc, and am not quite sure how to read the files on this mac, which isn't mine, as well, so I don't really want to mess, or put to much on it).

The Pixie
Tabs are good. If I want to set the hits for a large number of monsters, I would prefer to click on a tab and type a number in a box, rather than go to the attributes tabs and do it that way. For one thing I know the name of the attribute will be the same every time, for another I can quickly check back later and see that it has been set, and it is less typing too, once it is set up.

HegemonKhan
there are indeed some instances where the GUI~Editor (via its Tabs) is easier~quicker~better to do stuff for game making, than in code, definately. But, I'm mostly doing stuff in code, as I've gotten used to coding now, and as I'm lazy to open up the GUI~Editor (and it also takes it awhile to load up due to my old computer), and that just be another thing to learn: the GUI~Editor, whereas I want to focus on learning to code more and better, hehe.

vergil7
error all the way when i start using teleport spells

adrao
Started having a look at this yesterday, looks very nice indeed!I might use this as a starting point for my second game...

The Pixie
vergil7 wrote:error all the way when i start using teleport spells

Thanks, I have updated and it should work properly now.

Connormon99
Sadly, I am not that great at programming. :oops:

But I wish to replace gold with credits, is there an easy way to do this or do I have to rewrite everything? I could do that, but I hope that there is an easier way.

Silver
Have you tried replacing the word gold with credits in the code? You'd need to replace every instance of it and not delete out anything else.

The Pixie
Connormon99 wrote:But I wish to replace gold with credits, is there an easy way to do this or do I have to rewrite everything? I could do that, but I hope that there is an easier way.

This is covered in the notes.txt file:

To change the currency, create a function, GetPrice, which takes an integer as a parameter and returns a string. It might look like this:

<function name="GetPrice" parameters="price" type="string">
return ("" + price + " gp")
</function>


If you are not sure how to do that, go to Tools - Code view in the menu. You will see a whole load of code. Scroll right down to the bottom. The last line will be:

</asl>


Paste the code above in just above that line, so now the code ends:

  <function name="GetPrice" parameters="price" type="string">
return ("" + price + " credits")
</function>
</asl>

Connormon99
I feel like an idiot, I didn't see that!

Astral-Messenger
Is there a way, using this combat library, to remove the bodies of the enemies after they die? Or interact with them beyond the quick loot? I can't think of a way to add it in, since they become the new dead object. Any answer would be appreciated.

The Pixie
Look in the file CombatTypes.xml for the "monster" type, and a script called "makedead" (open in a text editor like NotePad, and search for "makedead"). If you want the body to disappear, set up a room to send it to, perhaps called "nowhere", and add this line:
this.parent = nowhere

To allow new actions you would need to add a new verb to the monster type, but check the attribute "dead" is set to true. You could also add the verb to the display list in "makedead" too.

LOTW
I'm not finding CombatLib.aslx in the drop down list.

The Pixie
Check the library files are in the right folder. You need to extract them from the downloaded .zip file and put them in the same folder as your game (Quest creates a folder for your game with the same name, there need to go in there). Make sure CombatLib.aslx is there and several others ending .xml.

DmNerd
Thank you for this awesome script. Just one quick question, is it possible to add the ability to run a script when a monster is killed?

The Pixie
When a monster dies, the makedead script runs. You can modify that.

If you modify the library version it will apply to all monsters, or you can modify it for an individual monster (look for it on the attributes tab, and click on the Make editable copy button).

DmNerd
Thank you, that really opens up what I can do with this script. Instead of monster attacks just damaging hit points, do you have an example of how I could tweak the code to attack attributes? For example if I wanted a monster to use a spell (or attack) that damaged my Players.fatigue score instead?

HegemonKhan
Attributes' using my-generalized syntax:

Object_name.Attribute_name = Value_or_Expression

--------------

THE TWO SUPER SCRIPTS (especially when used together, lets you do 90% of everything that you want to do in~for your game!):

1. 'set a variable or attribute' Script

run as script -> add new script -> variables -> 'set a variable or attribute' Script -> set variable ________ = [expression] _________

example (Object_name.Attribute_name = Value):

set variable player.strength = [expression] 100

example (Object_name.Attribute_name = Expression):

set variable player.damage = [expression] player.katana.damage + player.katana.damage * player.strength / 100 - (orc.full_plate_armor.resistance + orc.full_plate_armor.resistance * orc.endurance / 100)

2. 'if' Script

run as script -> add new script -> scripts -> 'if' Script -> if [expression] Object_name.Attribute_name OPERATOR Value_or_Expression

OPERATORS:

Math:

Addition: +
Subtraction: -
Multiplication: *
Division: /
Modulus (same as Division, but it gets the remainder instead): %
Greater Than: >
Lesser Than: <
Greater Than and~or Equal To: >=
Lesser Than and~or Equal To: <=
Equals: =
Not Equals 1: <>
Not Equals 2: not xxx = xxx

Strings~Text:

Assignment: =
Comparison: =
Concatenation: +
??? etc etc etc

-------

Basic Math Expressions (some examples):

Addition:

player.strength = player.strength + 20
player.damage = player.strength + player.endurance

Subtraction:

player.strength = player.strength - 15

Multiplication:

player.strength = player.strength * 7
player.damage = player.strength * player.endurance

Division:

player.strength = player.strength / 3

--------------

CONCEPTUAL example of how~why it works and~or is working (using addition):

initial~original~starting Value: player.strength = 0

Old Value: player.strength = 0

player.strength (new) = player.strength (old: 0) + 5
player.strength (new) = (0) + 5 = 5

New Value: player.strength = 5

Old Value: player.strength = 5

player.strength (new) = player.strength (old: 5) + 5
player.strength (new) = (5) + 5 = 10

New Value: player.strength = 10

Old Value: player.strength = 10

player.strength (new) = player.strength (old: 10) + 5
player.strength (new) = (10) + 5 = 15

New Value: player.strength = 15

Old Value: player.strength = 15

player.strength (new) = player.strength (old: 15) + 5
player.strength (new) = (15) + 5 = 20

New Value: player.strength = 20

etc etc etc

--------------

example of Transactions (buying~selling):

player.cash = 500
shop_owner.cash = 2000
sword.price = 100

Buying:

// sword.parent = shop_owner

if (player.cash >= sword.price) {
player.cash = player.cash - sword.price
shop_owner.cash = shop_owner.cash + sword.price
sword.parent = player
msg ("You bought the sword at 100 gold, leaving you with only 400 gold, the shop owner now has 2100 gold, and you place the sword into your inventory.")
} else {
msg ("Sorry, but you don't have enough gold to buy the sword.")
}


Selling:

(usually the selling amount in RPGs, is half the buying amount, so that's why I got the 'sword.price / 2' below)

(we're returning back to the original values for this example, we're NOT using the changed values of after buying the sword)

// sword.parent = player

if (shop_owner.cash >= sword.price / 2) {
player.cash = player.cash + sword.price / 2
shop_owner.cash = shop_owner.cash - sword.price / 2
sword.parent = shop_owner
msg ("You sell the sword at 50 gold, you now have 550 gold, the shop owner only has 1950 gold now, and you hand the sword over to the shop owner.")
} else {
msg ("Sorry, but the shop owner doesn't have enough gold to buy the sword from you.")
}

The Pixie
DmNerd wrote:... Instead of monster attacks just damaging hit points, do you have an example of how I could tweak the code to attack attributes? For example if I wanted a monster to use a spell (or attack) that damaged my Players.fatigue score instead?

The same principle as before, but the script to change in called "attackplayer". There is a line in there that looks like this:
game.pov.hitpoints = game.pov.hitpoints - damage

Change it to:
game.pov.fatigue = game.pov.fatigue - damage

I would have a totalfatigue attribute on the player too, so it can be restored back to that value.

By the way, game.pov is just the player. Assuming the player is the "player" object, which is the default, you could do this instead:
player.fatigue = player.fatigue - damage

DmNerd
Pixie, thanks a ton for taking the time to answer.

MissSearle
I followed the instructions and this happened.



I now cant access the game I created, help?

The Pixie
There are about half a dozen files in the zip file you downloaded; they all need to be in your game folder. Quest will do that for you when you add a library if it is just one file; in this case you have to do it yourself.

Start up Windows Explorer (eg hold the windows button and press 'E'). In the left pane, go to Libraries - Documents - My Documents - Quest Games (on Windows 7; may be slightly different on other versions). You should see a folder in there with the same name as your game. Copy all the files from the zip file you downloaded into that folder.

Hopefully that should fix it.

MissSearle
Ah!
My mistake, all sorted, thank you!

Vox_Populi
I'm sorry if this seems newbish or something, but I'm facing problems trying to figure out how do I get the code to print the name of my main character, any ideas on how I can fix this? Please and thank you

The Pixie
The name is in an attribute called "alias". You should be able to use a "text process" command to show it. For example:

Your name is {player.alias}.

Vox_Populi
Thank you very much pixie. I kept trying to do it like "+player.alias"

HegemonKhan
@ Vox Populi:

The text processor commands are very nice, but they do have some limitations, so here's help if/when you need to do the normal text+script scripting:

the secret trick of writing msg expressions (text+VARIABLES):

break it up into chunks

there's two types of chunks:

1. "text"
2. +VARIABLES+

for example:

HK is a 18 year old adult male human warrior.

player.alias = "HK"
player.age_integer = 18 // I wish I was 18, lol
player.age_string = "adult"
player.sex = "male"
player.race = "human"
player.class = "warrior"

msg (player.alias + " is a " + player.age_integer + " year old " + player.age_string + " " + player.sex + " " + player.race + " " + player.class + ".")

the chunks: 12

01) player.alias +
02) " is a "
03) + player.age_integer +
04) " year old "
05) + player.age_string +
06) " "
07) + player.sex +
08) " "
09) + player.race +
10) " "
11) + player.class +
12) "."

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums