Basic Random Combat

Heya Everyone,

I've been looking into trying to make turn-based combat for a game. Just something simple, consider it Pokémon style, where you get the options, such as run, surrender, or fight, etc. Booth parties have a health bar, a stamina bar sounds too complex though. And I would enjoy some stats, but at the same time, with me being a novice, I should probably lay off those for now.

So what I'm looking for is the player has say, a safe area. Home. From home, they can go to another room, say Forest, and then a random event happens. Sometimes they might find an item, or an NPC or event, sometimes they might gain stats, (if I implement stats) or health, but sometimes they might get a random attack. Say there might be goblins, wolves and orcs, the player would have a random chance of encountering each. And really, when that system is implemented, it's not much of a stretch to add more enemy types.

I am assuming there are already combat libraries out there. I've never used a library, and don't fully understand what they are. Collections of preset attributes and such? I know how to make objects, I've recently started with attributes, and currently my combat menu is a menu printed from list options, which works. Anyway, enough rambling.

Has anyone got a recommendation for up to date libraries, or, failing that, a way to implement this style of combat? The player should, ideally, not be in the 'room' with an enemy, but have them occur as events, with the combat screen, then the loot/victory screen, then they end up back at Home as this is the end of their 'adventure' for that turn, if it makes sense. Until they set out again. If there's anyone experienced out there, how hard would this be to implement for a mostly GUI user?

Thanks for the help!


LIBRARY FILES:

Alex and co made the quest software extremely powerful, as the quest engine itself is merely a bunch of library files, so if you're a good programmer, you can create your own engine for quest (you can completely change quest into something else entirely different, hehe). The default library files for the quest engine are: English.aslx and Core.aslx (though the Core.aslx is actually also a hub to the many individual 'core' library files, and I've not yet looked at the 'English.aslx' library file yet, so I don't know if it's also a hub to many individual files or not. You can see these library files in your actual installed quest folder that has the quest.exe, not your quest saved games folder, and you can open them up too and take a look at them, but DO BE WARNED, if you make changes to these files and save ... these ARE the quest files for it to run/work, so unless you know what you're doing... if you mess up these files, you're going to have to un-install quest and re-install it...)

a game file is just a bunch of code, and so is a library file, it's just a bunch of code, as a separate file from your game file (useful when you make big games, having separate files of code for the various aspects/parts/features of your game, for organization and sanity and by having them self-contained, it's easier to trouble-shoot them too if you got things not working correctly: organization:compartmentalization and programming:encapsulation).

a game is initialized ("built-up") from its added (included) library files (top to bottom) and then from its own game file's code. Because of this, depending on your library files, if they're dependent upon each other, then their order matters. Think of like cooking for example, if you do the cooking/mixing order/steps out of order, you're not going to create the delicious food you wanted. For an example, if you change the 'Core.aslx' to be above the 'English.aslx', you're going to have an error, and won't be able to play your game, until you change the 'English.aslx' back to being on top of the 'Core.aslx"

If you ever worked with using/managing many mods for a a game, you should understand (dependant) library files (combatibilty issues). A library file is pretty much a 'patch/x-pac/mod/add-on' for your game (or they can be/have most of the content of your game too and/or an entirely new engine for your game).

both a game file and a library file use the same extension of: NAME_OF_FILE.aslx

the game file:

(though it has other requirements too of course: a 'player' Player Object being inside of a Room Object, the 'game' Game Settings Object, and some other stuff: http://docs.textadventures.co.uk/quest/asl_requirements.html )

<asl version="###"> // the hash symbols are replaced with numbers, for example, I still use an older version of quest: "version=550"
  // mass of content/code
</asl>

a library file:

<library>
  // mass of content/code
</library>

a library file is just like a game file, (most of) the same stuff you can have in the game file, you can have in a library file, for example, a library file can be as simple as having a single Object:

<library>
  <object name="dragon">
    <attr name="parent" type="object">room</attr>
  </object>
</library>

and let's say we named/saved this library file as: dragon_library_file.aslx

and then to have this library file's contents added to your game file:

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  
  <include ref="dragon_library_file.aslx" />

  <game name="example">
    // blah Attributes
  </game>

  <object name="room">
  </object>

  <object name="player">
    <attr name="parent" type="object">room</attr>
  </object>

</asl>

lastly, the library file(s) have to be in the same location as your game file, so that it/they can be found by quest for your being added to your game file

the above of using the 'dragon_library_file.aslx' added to your game file, is no different than if you had just put the 'dragon' Object into your game file yourself (a library file is just doing it for you instead of you doing it, lol. Either you add/write code directly into your game file, or use the GUI/Editor too of course, or you can add/write code into a library file, and then have the library file be added to your game file):

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game name="example">
    // blah Attributes
  </game>

  <object name="room">
  </object>

  <object name="player">
    <attr name="parent" type="object">room</attr>
  </object>

  <object name="dragon">
    <attr name="parent" type="object">room</attr>
  </object>

</asl>

so, really the only (main) difference with a library file, there's no GUI/Editor for you to use, you got to know how to do the code tag blocks.


COMBAT:

a combat system can be really complex or really simple, as it depends on what features you want of/from it and also on the design you want: popup menus or inline menus (hypertext links), being stuck in a combat turn battle, unable to do anything else in the game until the battle is over (win, lose, escape/retreat/flee, etc) or it being open/more game flowing, where you can do other stuff in the game (not stuck in a looping battle scripting block until the battle is over), like you choose to attack monster then you can choose to talk to an npc then choose to attack the monster again, if you want monsters to follow you if you try to run away to different rooms and/or seek you out, or not, if you want random chance encounters, or pre-located and either random or specific monsters, if you want item usage, magic and/or abilities/powers, being able to escape/flee/run-away, defending (and a cool feature from 7th Saga - SNES, is that after you defend a turn, if you then attack next round, you do double damage - which gives defend an actual reason to use it, as it now has a tactical use: do I just attack doing normal damage and take normal damage from mosnter, or do I defend and reduce damage done to me and also next round I do double damage), distance/movement (Grandia 1 for PS1 has one of the coolest combat system of all time) and/or weapon reach/range and/or weapon/attack speed, stealth and backstabbing bonus damage, and etc etc etc (if you played a lot of RPGs or whatever games with combat, you can be familiar with many different systems and features of combat)


the main way of doing all of this cool stuff is having lists of things/items/stuff, which enables you to select one of them and/or for one to be randomly selected. This is done through the use of List and/or Dictionary Attributes, and iterating/cycling through them (mostly via: foreach). But, this is a bit more advanced stuff though...


LIST/DICTONARY ATTRIBUTES:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk (my guide on lists/dictionaries)

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk (note that this is old and bad/poor code, as this was back when I was firsting learning how to do this, laughs)

see if these help at all, and please feel free to ask me about anything, I'd be glad to help you with whatever and/or explain the stuff (such as in the 'explore and travel code' link, which is on the stuff you're asking for/about)


Lastly, almost every guide/library file/code-example, is Pixie's, lol.

Pixie has a great combat library if you want to use it for your game and/or just study it and/or just get some ideas from it, though you do got to learn how to implement its stuff with your game if you want to use it for your game (aka how to use his Functions, and etc stuff in his combat library file with stuff in your game), which Pixie has guidance on it, as well as asking Pixie to help you with it.

I also have a combat code post (which is based upon, and thus also there's, Pertex' Combat library, though his is a bit less noobie friendly than Pixie's), but my combat code is not that good (and has some errors in it and is old), so you're better off using Pixie's combat library. Though, you can take a look at my combat code, for possibly some ideas on things:

http://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread#22483 (my combat code)

http://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread#22486 (key/legend for my combat code, as unfortunately, I used a lot of abrevs for my attributes/stats stuff... I've learned to never ever use abrevs again... also in my combat code, I got my physical damage:pd and physical resistance:pr switched up, another reason that I've never used abrevs ever since, lol)

also, I'd actually recommend you take a look at this link/file, as Pertex cleaned up my very bad/poor combat code (so this is better to look at than my raw messy/poor/bad combat code):

(not sure if the link/file still works/exists or not... though)

http://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread#22485 (might need to scroll up/down to Pertex' post with the file link in it)


all of this stuff is advanced, so don't hesitate to ask about anything!


or simple... (using UI)
In the room, create an object (your creature)
inventory tab: uncheck Object can be taken
Verb tab: Add verb "hit" (and other commands as well)
select your new verb (hit) change the gray box (did say print a message) change to Run a script.

if (GetRandomInt(1,20)>10) {
msg ("You hit the dummy for {player.dam} points.")
}
else {
msg ("Shamefull!!! You miss the stationary dummy!")
}

then you just need a damage tracking system.


Libraries are a way to extend Quest. In fact, Quest has a bunch of libraries already incorporated, adding functions and types, such as containers. A combat library would add new functions and new types, such as weapon and monster (and hopefully new tabs for the editor to support them).

Here is my library and a tutorial that takes you through usng it. It is a pretty comprehensive system and may be more than you need.
https://github.com/ThePix/quest/wiki/CombatLib

This tutorial is for a simpler system, without using a library (as that is not possible for the web version).
https://github.com/ThePix/quest/wiki/The-Zombie-Apocalypse-(on-the-web-version)

That said, neither do exactly what you want so would take some modification.

I would suggest that as a first step you write down an example transcript (what the player would type, how the game would respond), to help you fix exactly how this would play out, before you start worrying about code. The big limitation in Quet (and all text adventures) is often the nature of parser, and it is good to sort that out on paper first.


I got this working just using counters and randomizers and pages in Gamebook mode.

So if you go to the forest page you script in RandomChance of something happening, so there can be random events on any given page/room. Sort of like:

RandomChance 10%,
then this thing happens.

Else if random chance 10%,
then this thing happens.

Else this thing happens.

And you can make as many or as few as you like with whatever chance you want. So when it goes to the forest page, there's a 10% chance of thing A happening, if it fails that chance there's another 10% chance thing B happens, if it fails that, just the normal thing happens.

In combat, say you just have a link to attack called ATTACK!, you can do it much the same way. Have the link go to alternating attack pages for that encounter (attack1, attack2, whatever you're calling it), with a random chance that you hit, or miss, or take damage yourself or whatever it is you want. And based on what happens, just change the counters accordingly (your health, the monsters health, etc.) And on the attack pages, you have a 'if monster health =<0' and 'if player health =<0' that will take you to a victory page (or a death page if you die).

if you're interested in how to exactly do that, let me know and I can put the code together for you. but again, this is for Gamebook mode, and it looks like you're in text adventure mode, so someone else could perhaps translate it to TA mode from GB mode if my way seems like something you'd want to do.


using the 'GetRandomInt' and 'RandomChance' together, let's you handle random stuff well:

you use a List Attribute with the GetRandomInt, for example, let's take a common feature of games: item-drop/treasure-chest-class

your List Attribute holds the selectable items (short_sword, long_sword, katana, claymore), and with the GetRandomInt, it selects one of those items, then, the RandomChance determines whether you actually get that selected item or not:

<object name="short_sword">
  <attr name="random_chance_integer_attribute" type="int">90</attr>
</object>
<object name="long_sword">
  <attr name="random_chance_integer_attribute" type="int">80</attr>
</object>
<object name="katana">
  <attr name="random_chance_integer_attribute" type="int">10</attr>
</object>
<object name="claymore">
  <attr name="random_chance_integer_attribute" type="int">10</attr>
</object>

game.sword_drop_class_1_objectlist_attribute = NewObjectList ()
list add (game.sword_drop_class_1_objectlist_attribute, short_sword)
list add (game.sword_drop_class_1_objectlist_attribute, long_sword)
list add (game.sword_drop_class_1_objectlist_attribute, katana)
list add (game.sword_drop_class_1_objectlist_attribute, claymore)
index_number_of_last_item_in_list_integer_variable = ListCount (game.sword_drop_class_1_objectlist_attribute) - 1
random_integer_variable = GetRandomInt (0, index_number_of_last_item_in_list_integer_variable)
randomly_selected_item_object_variable = ObjectListItem (game.sword_drop_class_1_objectlist_attribute, random_integer_variable)
if (RandomChance (randomly_selected_item_object_variable.random_chance_integer_attribute)) {
  randomly_selected_item_object_variable.parent = player
  msg ("You got the " + randomly_selected_item_object_variable.name)
} else {
  msg ("Sorry, you didn't get a dropped item this time")
}

// you can combine all of the functions too in one line if you prefer:

game.sword_drop_class_1_objectlist_attribute = NewObjectList ()
list add (game.sword_drop_class_1_objectlist_attribute, short_sword)
list add (game.sword_drop_class_1_objectlist_attribute, long_sword)
list add (game.sword_drop_class_1_objectlist_attribute, katana)
list add (game.sword_drop_class_1_objectlist_attribute, claymore)
randomly_selected_item_object_variable = ObjectListItem (game.sword_drop_class_1_objectlist_attribute, GetRandomInt (0, ListCount (game.sword_drop_class_1_objectlist_attribute) - 1))
if (RandomChance (randomly_selected_item_object_variable.random_chance_integer_attribute)) {
  randomly_selected_item_object_variable.parent = player
  msg ("You got the " + randomly_selected_item_object_variable.name)
} else {
  msg ("Sorry, you didn't get a dropped item this time")
}

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

Support

Forums