Combat...Sigh.

Anonynn
07 Mar 2016, 23:44
Oi, I may need a little walk-through of how to implement combat. I already know there are libraries available and tutorials, but I already have my own sort of way to handle health and whatnot, so I cannot use those combat systems. As for the tutorials, I think some of them may be a little out of date anyway and I had a lot of problems with them several months back so I erased all the previous attempts and wanted to start over fresh when I understood things a little better. So anyway! This is where I'm currently at.

I have two Object TYPES at the moment.

Object type: monster
Object type: weapon

I know object types apply to all objects that you assign each "type" to. So if I made a "whip" I would go to the inherited attributes and type "weapon" to it and then all the components of "weapon" would apply to that weapon.

The first logical step would be to create the weapons; which I've done. There are Fists (which will be default attack with no weapon), Rickety Machete, Beating Stick, Frying Pan, Leather Whip.

So now I must apply the "weapon" type to each of them --- which I've done.

Next, I must apply attributes to the weapon type so that the weapons will inherit them.
I added...
Equip (string)
Unequip (string)

Now I have to apply the "inherited" monster type with "attack".
Attack (string)

And each monster gets it's own "current_health" integer, and "maximum_health" integer.


Is this correct so far?

Anonynn
09 Mar 2016, 05:06
Also, I'm aware that I can possibly use these equip and unequip scripts.

      if (this.parent = game.pov) {
if (not game.pov.equipped = fists and not game.pov.equipped = null) {
msg ("You put away your " + game.pov.equipped.alias + " and draw your " + this.alias + ".")
}
else {
msg ("You draw your " + this.alias + ".")
}
game.pov.equipped = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatus = "Wielding: " + this.alias
}
else {
msg ("You don't have it.")
}


and...

   if (this.parent = game.pov) {
msg ("You put away your " + game.pov.equipped.alias + ".")
game.pov.equipped = fists
this.inventoryverbs = Split ("Look at;Drop;Equip", ";")
game.pov.equippedstatus = "Wielding: nothing"
}
else {
msg ("You don't have it.")
}


I also don't care about the player pane saying "equipped status" because the player will see what is equipped/wielded in their inventory.

Is this correct as well?

HegemonKhan
10 Mar 2016, 21:45
If you don't have that many weapons/monsters/etc, you may not want to try to learn how to use the Object Types, as that will take more time and be more confusing, than if you didn't use them. However, you're probably going to be using lots of monsters/weapons/etc, as from what I've read, you're game seems to be really awesome!, so you might as well learn how to use Object Types.

a lot of all this advanced/fancy code stuff is for more macro-design systems (for really big games, to handle lots of objects, equipment, npcs, dialogue, fancy features of combat/magic/items, and etc). It's mostly for the scope of handling the size and/or complexity of the game.

---------

actually, you want to have your actions (attack, equip, unequip, etc) be scripts (Script Attributes ARE your "Verbs"), so change them from "string" to "script". Then you add the whatever Scripts to them (exactly like a Verb). Otherwise, maybe you want to use the Commands (like how Chase's library works), in this case, you'd NOT add any of the action stuff as Script Attributes of/for/to your Object Types.

However, there's an issue with using Object Types, as their Attributes will be applied/added to many different weapon/monster Objects, which MEANS you have to use the 'this' special word, in place of the spot where you'd use the Object's name. if you're 'monster' Object Type scripting uses for example, 'orc.damage = 1", it'll work fine being applied to your 'orc' monster Object, but won't work being applied to your 'ogre' monster Object.

that's where the special 'this' comes in:

this.damage = 1

when quest applies this 'monster' Object Type's Script Attribute to your 'orc' monster Object (you added the 'monster' Object Type, via Inherited Attribute, to the 'orc' monster Object), the 'this' will get the Object's name, which for the 'orc' monster Object, is 'orc', and so it works.

When quest applies this 'monster' Object Type's Script Attribute to your 'ogre' monster Object (you added the 'monster' Object Type, via Inherited Attribute, to the 'ogre' monster Object), the 'this' will get the Object's name, which for the 'ogre' monster Object, is 'ogre', and so it works.

----------

the more challenging/difficult part with combat is with getting the other Object involved in the scripting... as the special 'this' word ONLY gets the Object that this Attribute is added to, you got to use some other method of getting the other Object that is also involved. This is much more code intensive, but we'll help you through it, hehe.

--------

personally... if you got the time (which I don't think you do, as you're trying to get out your game), it'd be better to slowly learn combat, first making / understanding how to do the most simple type of combat, getting down how to do basic combat (simple damage, etc). And then slowly build up to more complex combat designs for your game's needs. As it sounds like you got really confusd with trying to jump in and use Chase's (wearables/equipment) and Pixie's combat libraries, for your combat. If you got the time, learn the very basics of how to do simple damage (you and one other monster, via using an "attack" Verb with that one monster), then learn to use basic equipment with it, and then slowly build up from there to more advanced stuff, such as having to choose/get between different monsters or multiple monsters at once, and etc various fancy combat features seen in many games.

Anonynn
11 Mar 2016, 21:10

as from what I've read, you're game seems to be really awesome!



Thanks!

actually, you want to have your actions (attack, equip, unequip, etc) be scripts (Script Attributes ARE your "Verbs"), so change them from "string" to "script". Then you add the whatever Scripts to them (exactly like a Verb). Otherwise, maybe you want to use the Commands (like how Chase's library works), in this case, you'd NOT add any of the action stuff as Script Attributes of/for/to your Object Types.



Oops! Yeah, I meant to say scripts not strings! Nice catch!

However, there's an issue with using Object Types, as their Attributes will be applied/added to many different weapon/monster Objects, which MEANS you have to use the 'this' special word, in place of the spot where you'd use the Object's name. if you're 'monster' Object Type scripting uses for example, 'orc.damage = 1", it'll work fine being applied to your 'orc' monster Object, but won't work being applied to your 'ogre' monster Object.

that's where the special 'this' comes in:

this.damage = 1



So you're saying I want to apply:

this.damage = 1

Okay! So I removed "Attack" from the object type "Monster" and instead put it on the first monster in the game. "Attack" script, and then I put this.damage = 1 on it. I think this will be easier to manage. I can just apply universal things to the object type "Monster" like how strength, defense, etc varies the attacks.

personally... if you got the time (which I don't think you do, as you're trying to get out your game), it'd be better to slowly learn combat, first making / understanding how to do the most simple type of combat, getting down how to do basic combat (simple damage, etc).



Probably! But you know me, I like to jump right in! I mean, look how much I learned in the last...what 5 months? :)

So anyway, what should the equip/unequip weapons code be? As I mentioned I don't care to show the status of the weapons in the player pane, just the (equipped) or (wielded) in the inventory pane. Fists are obviously default and unequippable.

equip
if (this.parent = game.pov) {
if (not game.pov.equipped = fists and not game.pov.equipped = null) {
msg ("You put away your " + game.pov.equipped.alias + " and draw your " + this.alias + ".")
}
else {
msg ("You draw your " + this.alias + ".")
}
game.pov.equipped = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatus = "Wielding: " + this.alias
}
else {
msg ("You don't have it.")
}

unequip

if (this.parent = game.pov) {
msg ("You put away your " + game.pov.equipped.alias + ".")
game.pov.equipped = fists
this.inventoryverbs = Split ("Look at;Drop;Equip", ";")
game.pov.equippedstatus = "Wielding: nothing"
}
else {
msg ("You don't have it.")
}

BTW, thank you for your help so far! I appreciate it!

HegemonKhan
12 Mar 2016, 01:51
I too like jumping right into stuff too, hehe ;)

-----

actually... your actions are (should be) universal, so they're good to place/add into Object Types, whereas your 'stat' Attributes usually are (their values are) specific for individual monsters, and thus not good for putting into Object Types.

------

the use of 'this' instead of your Object's name in scripting is for (and required) when using (adding/creating the Attribute in the) Object Types. If you're not using Object Types, and just adding the Attributes (Script Attributes), or Verbs, directly to (into) each of your Objects, then you can just use the Object's name.

-----------

a very simple combat example:

<object name="player">
<attr name="alias" type="string">Neonayon</attr>
<attr name="damage" type="int">100</attr>
<attr name="current_life" type="int">999</attr>
</object>

<object name="orc_1">
<inherit name="monster" />
<attr name="alias" type="string">orc</attr>
<attr name="damage" type="int">25</attr>
<attr name="current_life" type="int">250</attr>
</object>

<object name="ogre_1">
<inherit name="monster" />
<attr name="alias" type="string">ogre</attr>
<attr name="damage" type="int">50</attr>
<attr name="current_life" type="int">500</attr>
</object>

<type name="monster">
<attr name="dead" type="boolean">false</attr>
<attr name="attack" type="script">
if (this.dead) {
msg ("The " + this.alias + " is already dead, silly")
} else {
this.current_life = this.current_life - player.damage
msg ("You attack the " + this.alias + ", doing " + player.damage + " damage, leaving the " + this.alias + " with only " + this.current_life + " life left.")
if (this.current_life <= 0) {
this.dead = true
msg ("You killed the " + this.alias + "!")
} else {
player.current_life = player.current_life - this.damage
msg ("The " + this.alias + " attacks you, doing " + this.damage + " damage, leaving you with only " + player.current_life + " life left.")
if (player.current_life <= 0) {
msg ("You were killed by the " + this.alias +".")
msg ("GAME OVER")
finish
}
invoke (this.attack) // this will loop the 'attack' script, meaning that you and the monster will continue damaging each other, until one is dead.
}
}
</attr>
<attr name="displayverbs" type="simplestringlist">look;attack</attr>
</type>

<verb>
<property>attack</property>
<pattern>attack</pattern>
<defaultexpression>"You can't attack it"</defaultexpression>
</verb>


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

to understand Object Types:

for any Object that has (using my example code above) the '<inherit name="monster" />' Inherited Attribute, pretend that every Attribute within the 'monster' Object Type, is written/added into that Object, just as if you done it yourself.

so, for example, doing this (writing/typing/coding it in) yourself:

<object name="orc_1">
<attr name="alias" type="string">orc</attr>
<attr name="attack" type="script">
msg ("The " + orc_1.alias + " attacks you!")
</attr>
</object>

<object name="ogre_1">
<attr name="alias" type="string">ogre</attr>
<attr name="attack" type="script">
msg ("The " + ogre_1.alias + " attacks you!")
</attr>
</object>

<object name="troll_1">
<attr name="alias" type="string">troll</attr>
<attr name="attack" type="script">
msg ("The " + troll_1.alias + " attacks you!")
</attr>
</object>


is the exact same as this (quest will add/write in the Attributes to the Objects for you, and 'this' will get the Object's name, so it'll correctly use and display the right/correct name for each of the 3 monster Objects):

<object name="orc_1">
<inherit name="monster" />
<attr name="alias" type="string">orc</attr>
</object>

<object name="ogre_1">
<inherit name="monster" />
<attr name="alias" type="string">ogre</attr>
</object>

<object name="troll_1">
<inherit name="monster" />
<attr name="alias" type="string">troll</attr>
</object>

<type name="monster">
<attr name="attack" type="script">
msg ("The " + this.alias + " attacks you!")
</attr>
</object>


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

I think your 'equip' and 'unequip' code will already work correctly for/with your 'weapon' Object Type, so go ahead and add them as Script Attributes to your 'weapon' Object Type

a quick (incomplete) example below, using my own coding...

<object name="player">
<attr name="equipped" type="object">fist</attr>
</object>

// I'm NOT giving the 'fist' Object the 'weapon' Object Type (and you don't want it to be drop'able, and you want it to always be on the player), because I don't want it to have the 'unequip' Script Attribute/Verb, as the 'fist' is your default weapon (weaponless: "naked weapon"), so you can always do some damage. Well, you could just have your player have a 'damage=1' Integer Attribute, and not even have a "fist" weapon, but by using a 'fist' weapon, it allows for more easily done complex combat features, if you wish to go there with your combat.

<object name="fist">
<attr name="parent" type="object">player</attr>
<attr name="damage" type="int">1</attr>
<attr name="equip" type="script">
if (this.parent = player and not player.equipped = this) {
msg ("You remove the " + player.equipped.alias + ", and put on the " + this.alias +".")
player.equipped = this
} else if (player.equipped = this) {
msg ("You're already wearing the " + this.alias + ".")
} else if (not this.parent = player) {
msg ("You can't equip the " + this.alias + " when it's not in your possession!")
} else {
msg ("You can't equip it for whatever the reason.")
}
</attr>
<attr name="displayverbs" type="simplestringlist">equip</attr>
</object>

<object name="sword">
<inherit name="weapon" />
<attr name="damage" type="int">50</attr>
</object>

<object name="axe">
<inherit name="weapon" />
<attr name="damage" type="int">100</attr>
</object>

<type name="weapon">
<attr name="equip" type="script">
if (this.parent = player and not player.equipped = this) {
msg ("You remove the " + player.equipped.alias + ", and put on the " + this.alias +".")
player.equipped = this
} else if (player.equipped = this) {
msg ("You're already wearing the " + this.alias + ".")
} else if (not this.parent = player) {
msg ("You can't equip the " + this.alias + " when it's not in your possession!")
} else {
msg ("You can't equip it for whatever the reason.")
}
</attr>
<attr name="unequip" type="script">
if (player.equipped = this) {
msg ("You remove the " + this.alias + ".")
player.equipped = fist
} else if (not player.equipped = this) {
msg ("You're already not wearing the " + this.alias + ".")
} else if (not this.parent = player) {
msg ("You can't unequip the " + this.alias + " when it's not in your possession! Houston, we got a coding logic bug/error/mistake problem!")
} else {
msg ("You can't unequip it for whatever the reason.")
}
</attr>
<attr name="displayverbs" type="simplestringlist">equip;unequip</attr>
<attr name="inventoryverbs" type="simplestringlist">equip;unequip</attr>
</type>

Anonynn
12 Mar 2016, 05:37

I too like jumping right into stuff too, hehe ;)



^_~

I think your 'equip' and 'unequip' code will already work correctly for/with your 'weapon' Object Type, so go ahead and add them as Script Attributes to your 'weapon' Object Type



Nope. I put this code in the object type "weapon" which is applied too all the current weapons (except the fist) and when I click the "Equip" in the game, it says "You cannot equip the Rickety Machete" for example. And fists also came up as an item which is equippable and droppable. Also, "attack"ing the monsters did nothing (though I imagine it's because I didn't have "fists" to attack with.

I made sure and matched up all the codes for what it's labeled in my game as well. For example, "current_life" in your code is "health" in my game. So all of those are matched up.

This is what happened last time I tried doing this e_____e

HegemonKhan
12 Mar 2016, 08:27
I would create a new game, and try to learn how to use Object Types, starting simple and then building up with them, then hopefully, you'll be able to create them for your own game, setting them up to match up with all of your code and design and features in your game.

The reason being that probably most of your difficulties with trying to use Objects Types is in setting them up to work with your entire game code and its design. By creating a new game, you can learn directly how they work and how to use them, without having to figure out how to match them up to your game code that you've already created. Once you understand how to use them, then hopefully it'll be a bit easier in setting them up for your game's code.

--------

Start simple:

(not completed, sorry, but hopefully you can figure out the rest... at least it's a starting point for you)

Game Object:

<attr name="pov" type="object">player</attr>


Room Objects:

1. 'room' Room Object

character Objects:

1. 'player' Player Object

<inherit name="actor" />
<inherit name="playable" />


2. 'orc' monster Object

<inherit name="actor" />
<inherit name="monster" />


weapon Objects:

1. unarmed

<attr name="parent" type="object">game.pov</attr>

<attr name="damage" type="int">1</attr>

<attr name="equip" type="script">
</attr>


2. club

<attr name="parent" type="object">orc</attr>

<attr name="damage" type="int">10</attr>


3. sword

<inherit name="weapon" />
<attr name="damage" type="int">50</attr>


4. axe

<inherit name="weapon" />
<attr name="damage" type="int">100</attr>


Object Types:

1. 'actor' Object Type, this will have the Attributes that both the 'player' Player Object and 'whatever' monster Object share (remember keeping this simple):

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

<attr name="changedequipped" type="script">
this.damage = this.equipped.damage
</attr>


2. 'playable' Object Type, normally this will have the Attributes that all Player Objects share, but we're only working with one, the 'player' Player Object (so, the 'life' is included here, otherwise, it shouldn't be, as likely you'd have your Player Objects all starting at different stat values, based upon character creation choices for example):

<attr name="life" type="int">999</attr>

<attr name="equipped" type="object">unarmed</attr>

<attr name="changedlife" type="script">
if (this.life > 999) {
this.life = 999
} else if (this.life <= 0) {
msg ("You were killed or you've died.")
msg ("GAME OVER")
finish
}
</attr>

<attr name="statusattributes" type="simplestringdictionary">life = Life: !; equipped = Weapon: !; damage = Damage: !</attr>


3. 'monster' Object Type, normally this will have the Attributes that all monster Objects share, but we're only working with one, the 'orc' monster Object (normally, you'd have your monster Objects all having different stat values, adn thus not have those Attributes here, but we're only working with one monster Object, in this case):

<attr name="life" type="int">500</attr>

<attr name="equipped" type="object">club</attr>

<attr name="displayverbs" type="simplestringlist">attack;loot</attr>

<attr name="attack" type="script">
if (this.dead) {
msg ("The " + this.name + " is already dead, silly.")
} else {
this.life = this.life - game.pov.equipped.damage
msg ("You attack the " + this.name + " for " + game.pov.equipped.damage + " damage, leaving the " + this.name + " with only " + this.life + " life left.")
game.pov.life = game.pov.life - this.equpped.damage
msg ("The " + this.name + " attacks you for " + this.equipped.damage + " damage, leaving you with only " + game.pov.life + " life left.")
invoke (this.attack)
}
</attr>

<attr name="loot" type="script">
if (this.dead and not this.equipped = unarmed) {
this.equipped.parent = game.pov
msg ("You loot the corpse of the dead " + this.name + ", finding a " + this.equipped.name + ", which you take and store away in your inventory.")
this.equipped = unarmed
} else if (this.dead) {
msg ("You search the corpse of the dead " + this.name + ", but find nothing of value.")
} else {
msg ("The " + this.name + " is still alive, and it's not going to let you just take its weapon, silly.")
}
</attr>

<attr name="changedlife" type="script">
if (<this.life <= 0) {
this.dead = true
msg ("You killed the " + this.name + "!")
}
</attr>


4. 'weapon' Object Type, this will have the Attributes that both the 'player' Player Object and 'whatever' monster Object share (remember keeping this simple):

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

<attr name="displayverbs" type="simplestringlist">take</attr>
<attr name="inventoryverbs" type="simplestringlist">drop;equip</attr>

<attr name="equip" type="script">
</attr>

<attr name="unequip" type="script">
</attr>


Verbs:

1. attack

<verb>
<property>attack</property>
<pattern>attack</pattern>
<defaultexpression>"You can't attack that!"</defaultexpression>
</verb>


2. loot

<verb>
<property>loot</property>
<pattern>loot</pattern>
<defaultexpression>"You can't loot that!"</defaultexpression>
</verb>

Anonynn
12 Mar 2016, 18:39
I appreciate all the help HK, but don't worry about it. I'll just have to come up with my own combat system or something I guess. Thank you!

HegemonKhan
13 Mar 2016, 00:35
let us know if you need help with anything, like if you're still having trouble with Object Types, or whatever aspect that you're trying to do with your combat.

If you can make your own combat, that's definately best, as you understand it well, whereas it's more difficult to work with someone else's code system (such as other people's combat libraries, and etc). You know your own code best, and what you need to do to apply whatever you're trying to do to it or it to whatever you're trying to do.

-------

I was just trying to help walk you through on how to use Object Types, as I know your game and its needs are very different than the code I was giving for using Object Types, my code wasn't for you to use in your game, just to try to learn.understand how they work and how to get them to work correctly for you to then apply Object Types into your game creation.

Anonynn
13 Mar 2016, 01:57
Hmm. I understand how to use the Object Types, I just can't get things to work in my game regarding the steps....like for example equipping weapons and unequipping them. The original code doesn't really work. Remember the last time I tried it and it still wasn't working properly. I think taking steps little by little would be more beneficial than trying to use something preexisting.

For example, what might be the minimal equip/unequip code be. Do I need fists as an object or can I just put the damage right on the player object? Yada yada.

Maybe one small thing at a time will help :) Otherwise I start getting really frustrated.