How can I change an attribute of worn clothes?
coms77
19 Aug 2018, 13:05Let's say I have some jacket on, and I want it to degrade after a fight. How can it be done? Thanks!
mrangel
19 Aug 2018, 13:42If you want to change some attribute of all the clothes you're wearing, you can use FilterByAttribute.
I'd probably give clothes a "condition" attribute; setting it to something like 100 for "new" and 0 for "falling apart".
At the end of a fight, you could have code like:
clothes = FilterByAttribute (GetAllChildObjects (game.pov), "worn", true)
foreach (garment, clothes) {
if (HasInt (garment, "condition)) {
garment.condition = garment.condition - GetRandomInt (1, 12)
}
else {
garment.condition = GetRandomInt(85, 99)
}
if (garment.condition < 0) {
msg ("Your "+GetDisplayAlias(garment)+" has fallen apart from the beating!")
RemoveGarment (garment)
RemoveObject (garment)
}
}

DarkLizerd
19 Aug 2018, 14:20Each hit, or damage done, to the clothing...
player.jacket=player.jacket- DamageDone
coms77
19 Aug 2018, 15:24Could you explain each line and detail and/or give me a non-code view? Thanks!
mrangel
19 Aug 2018, 16:16An explanation of my code. Not sure which bits you werehaving trouble with, so I'll explain all of it:
clothes = FilterByAttribute (GetAllChildObjects (game.pov), "worn", true)
- This starts with a list of everything in the inventory (GetAllChildObjects (game.pov)
) and then filters it to objects whoseworn
flag istrue
. It sets the variableclothes
to be a list of all objects that the player is wearing.foreach (garment, clothes) {
- the code in this loop is repeated once for each object in theclothes
list, with thegarment
variable being set to each one in turnif (HasInt (garment, "condition")) {
- if the garment has a "condition" attributegarment.condition = garment.condition - GetRandomInt (1, 12)
- reduce the condition by a random number between 1 and 12. You could use whatever numbers you want, I just gave this as an example
}
else {
- If it doesn't have a condition variable. I included this 'else' case so that you don't need to set the initial condition for every piece of clothinggarment.condition = GetRandomInt(85, 99)
- Set a 'new' garment's condition to what it would be after a single fight. In this case, a number between 85 and 99. The numbers are a matter of personal preference
}
if (garment.condition < 0) {
- after reducing the garment's "condition", check if it's less than zeromsg ("Your "+GetDisplayAlias(garment)+" has fallen apart from the beating!")
- display a message to the playerRemoveGarment (garment)
- remove the garment (not sure if this is necessary, unless you have a garment that does something special when it's put on)RemoveObject (garment)
- and move the garment outside of the game, where the player can't see it anymore. This is sometimes a safer way to destroyu objects you no longer need.
}
}
coms77
19 Aug 2018, 16:30Thanks, that helped a lot!
mrangel
19 Aug 2018, 20:49If you only want to damage a particular piece of clothing, you could use something like this. (Imagining the player has just been crawling across broken glass or something)
garment = GetOuterFor (game.pov, "legs")
if (garment = null) {
// not wearing anything
msg ("The glass digs into your bare legs")
DecreaseHealth (20)
}
else {
msg ("The glass rips your "+GetDisplayName(garment)+" to pieces")
garment.condition = garment.condition - GetRandomInt(20, 30)
// code here to check if the trousers are actually destroyed
}
This version, rather than running for every object the player is wearing, picks the outermost item in a given slot (in this example, "legs")