How do I give my armor durability?

GC2

I want my armor to be able to break after taking enough damage. How do I check equipped gear and then change the stats of equipped gears?


Io

There's a ton of ways to do this. Generally, most of them will revolve around you having an Armor object, with attribute Durability. And you can check it by having {Armor.Durability} in your text, and change it with code like:

Armor.Durability=Armor.Durability-1
if Armor.Durability<=0:{
//Do Armor Destruction Stuff Here
}

GC2

I want to make it so that the game can detect what the current armor is equipped and make it lose durability when attacked. Is there a way to make that happen?


(filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)


here's a "quick simple" example (not remotely complete though, and: RPG functionality/mechanic systems, like equipment, items, combat, magic, stealth, diplomacy/dialogue, and etc, are complex, regardless of how complex or simple you want such a system for within your game) for you:

(I didn't show how to adjust/change the stats for your gear, but one way would be using a Command, as I did for the viewing of your equipped gear, but it's scripting would be quite different obviously, am too lazy to show it right now)

(ignore if can't understand coding yet, but try and see if it makes some sense and an idea of how to do things, hopefully... lol)

<asl version="550">

  <include ref="English.aslx" />

  <include ref="Core.aslx" />

  <delegate name="combat_delegate" parameters="self_object_parameter,enemy_object_parameter" />

  <delegate name="durability_delegate" parameters="object_parameter" />

  <game name="NAME_OF_GAME">

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

    <attr name="start" type="script">

      rundelegate (combat_object, "combat_script_attribute", game.pov, orc_object)

    </attr>

  </game>

  <object name="room">

    <inherit name="editor_room" />

  </object>

  <object name="player">

    <inherit name="editor_object" />
    <inherit name="editor_player" />

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

    <attr name="weapon_object_attribute" type="object">unarmed_object</attr>

    <attr name="armor_object_attribute" type="object">unarmored_object</attr>

  </object>

  <object name="orc_object">

    <inherit name="editor_object" />

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

    <attr name="alias" type="string">orc</attr>

    <attr name="strength_integer_attribute" type="int">25</attr>

  </object>

  <object name="unarmed_object">

    <inherit name="editor_object" />

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

    <attr name="alias" type="string">unarmed</attr>

    <attr name="equipped" type="boolean">true</attr>

  </object>

  <object name="unarmored_object">

    <inherit name="editor_object" />

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

    <attr name="alias" type="string">unarmored</attr>

    <attr name="equipped" type="boolean">true</attr>

  </object>

  <object name="power_armor_object">

    <inherit name="editor_object" />

    <inherit name="armor_type" />

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

    <attr name="alias" type="string">power armor</attr>

    <attr name="equipped" type="boolean">false</attr>

    <attr name="durability_integer_attribute" type="int">100</attr>

  </object>

  <object name="equipment_object">

    <inherit name="editor_object" />

    <attr name="maximum_durability_integer_attribute" type="int">100</attr>
    <attr name="minimum_durability_integer_attribute" type="int">0</attr>

    <attr name="durability_script_attribute" type="durability_delegate">

      if (object_parameter.durability_integer_attribute > this.maximum_durability_integer_attribute) {

        object_parameter.durability_integer_attribute = this.maximum_durability_integer_attribute

      } else if (object_parameter.durability_integer_attribute < this.minimum_durability_integer_attribute) {

        object_parameter.durability_integer_attribute = this.minimum_durability_integer_attribute

      }

      if (object_parameter.durability_integer_attribute = 0) {

        object_parameter.equipped = false

        if (DoesInherit (object_parameter, "weapon_type")) {

          game.pov.weapon_object_attribute = unarmed_object

        } else if (DoesInherit (object_parameter, "armor_type")) {

          gam.pov.armor_object_attribute = unarmored_object

        }

      }

    </attr>

  </object>

  <object name="combat_object">

    <attr name="combat_script_attribute" type="combat_delegate">

      // example simple scripting:

      self_object_parameter.armor_object_attribute.durability_integer_attribute = self_object_parameter.armor_object_attribute.durability_integer_attribute - enemy_object_parameter.strength_integer_attribute

    </attr>

  </object>

  <type name="weapon_type">

    <inherit name="equipment_type" />

  </type>

  <type name="armor_type">

    <inherit name="equipment_type" />

  </type>

  <type name="equipment_type">

    <attr name="changeddurability_integer_attribute" type="script">

      rundelegate (equipment_object, "durability_script_attribute", this)

    </attr>

  </type>

  <command name="view_equipped_command">

    <pattern>view #text#;view;v</pattern>

    <script>

      // (I forgot to handle for if text = null, aka, if they just used 'view' or 'v' for the Command input/pattern, but am too lazy to go back and do it now, lol)

      object_variable_1 = GetObject (text)

      if (object_variable_1 = null or not object_variable_1.equipped) {

        foreach (object_variable_2, ScopeInventory ()) {

          if (object_variable_2.equipped and object_variable_2.alias = text) {

            object_variable_1 = object_variable_2

          }

        }

      }

      if (object_variable_1 = null) {

        msg ("ERROR: wrong input, either: input isn't equipped or input doesn't exist within the game")

      } else {

        msg (object_variable_1.name)
        msg (object_variable_1.alias)
        msg (object_variable_1.durability_integer_attribute)

      }

    </script>

  </command>

</asl>

Io

@GC2, one way to do this is give the player an Object attribute named 'Armor'. Or, if you have multiple pieces of armor, separate object attributes called 'HeadArmor', 'ChestArmor' etc.

And when you equip an armor:

Player.HeadArmor=SomeArmorObject

And, when the player gets hit, you can check for their armor. Note, you can do attributes INSIDE attributes, like so:

Player.HeadArmor.Durability=Player.HeadArmor.Durability-1
if Player.HeadArmor.Durability<=0{
//Do Armor Destruction Stuff
}

The caveat with this method is you need a 'null' object, a NoArmor object that's slotted in by default and can't be destroyed, unless Armor with 0 durability is simply rendered useless, not destroyed.


If you're using the standard "wearables" system for armour, then you can check the worn attribute to find all the items the player is currently wearing.

So I'd end up using a script like this when the player takes damage:

armour = 0
foreach (obj, GetDirectChildren(game.pov)) {
  if (GetBoolean (obj, "worn")) {
    if (HasInt (obj, "armourvalue")) {
      armour = armour + obj.armourvalue
      obj.durability = obj.durability - 1
    }
  }
}
// The variable "armour" now contains the total armour value of all the armour the player is wearing
// so we use that to calculate damage

That will reduce the durability of your armour by 1 point each time the player is hit. And then you give the armour a changeddurability script attribute:

if (this.durability <= 0) {
  if (GetBoolean (this, "worn")) {
    RemoveGarment (this)
  }
  msg ("Your "+GetDisplayName(this)+" has broken!")
}

That would cause the item to be removed once its durability hits zero. If you want the armour to be destroyed, then you can just add the line RemoveObject (this); otherwise it would remain in the player's inventory (maybe they can take it to a shop to be repaired; or they can still sell it for scrap?). And then to make sure they don't just put it on again you'd create a function:

<function name="TestGarment" parameters="garment" type="boolean">
  if (HasInt (garment, "durability")) {
    if (garment.durability <= 0) {
      msg ("You need to repair that before you can wear it again.")
      return (false)
    }
  }
  return (true)
</function>

Or if broken armour can be sold for scrap but can't be repaired, then in the changeddurability script you would do something like this.alias = "Broken " + GetDisplayAlias(this) and this.worn = null.
(worn is null for non-wearable objects)


Log in to post a reply.

Support

Forums