Item Health
billypaulhaley
21 Mar 2018, 19:39Is there a way to make an item only have a certain amount of uses before they get destroyed?
XanMag
21 Mar 2018, 20:36Depending on your methodology...
Hackers way... and only reasonable to use if the object is only used a few times
- Create an empty room (that is one with no entrances or exits).
- Create your object (I made a "Fart Machine" in code below) that you want to use and put it in whatever room you want it.
- Go to the Features tab and and select 'use (on its own)'.
- Choose to run a script.
- Print whatever message you want to appear when you use the object.
- Run a Remove Object script and choose this object.
- Run a Move Object To Inventory (if it is an inventory object) or a Move Object To Current Room (if it is a stationary object) and move the copied object (from step 8 below) to the appropriate place (inventory or current room)
- Copy this object and paste it in the empty room (from #1) however many times you want the object to be used before it 'breaks' (or whatever). Make sure you change the 'alias' to get rid of the number that follows the object name.
- On the last object coming out of the empty room, you will probably want to print a message saying the object is now useless (or whatever) and maybe remove the object (or whatever =)
More Elegant Way
- Create your object and place it in your room.
- Go to the attributes tab and click 'add' next to 'attributes'
- Add an attribute and name it something like 'TimesUsedCount' and set it to an 'Integer' attribute (at bottom) equal to zero.
- Go to the features tab and click use.
- On the Use (on its own) section...
- Add an 'If ' script and select 'attribute equals'
- If [object attribute equals] Object [fart machine] Attribute [TimesUsedCount] = [0]
then print whatever message you want. - Add another script here and select 'set a variable or attribute'. It should look like this:
Set variable [fart machine.TimesUsedCount] = expression [fart machine.TimesUsedCount + 1] - Add an Else If script in the same script box but just change the 0 (in step 7) to a 1. If you want a different message to print, go ahead and change it.
- Continue adding Else If scripts for the number of times you want the object to be used (MAKE sure you add 1 to the previous number each time you add an else if). ^NOTE: If the object is something you can use a BUNCH of times, you will only want to add as many Else Ifs as you want the message printed when used to change.
- When complete, add an Else message that indicates that using the object no longer works.
- In the example below, I also added set a flag script to change the 'look at' response when you look at the object.
FOR THE USE OBJECT SCRIPT (I also copy-pasted this on the 'push' verb on the button of the machine)
if (fart machine.TimesUsedCount = 0) {
msg ("You push the button and a squeaky sounding fart emits from the machine.")
fart machine.TimesUsedCount = fart machine.TimesUsedCount + 1
}
else if (fart machine.TimesUsedCount = 1) {
msg ("You push the button and a wet, rumbling noise emits from the machine.")
fart machine.TimesUsedCount = fart machine.TimesUsedCount + 1
}
else if (fart machine.TimesUsedCount = 2) {
msg ("You push the button and the fart machine produces a VERY loud sound similar to the explosion of a hand grenade followed by a ker-thunk.")
fart machine.TimesUsedCount = fart machine.TimesUsedCount + 1
SetObjectFlagOn (fart machine, "broken")
}
else {
msg ("You push the button, but the machine does nothing. Must be broken.")
}
FOR THE LOOK AT DESCRIPTION:
if (GetBoolean(fart machine, "broken")) {
msg ("It's a fart machine, but you think it is broken. It appears to do nothing.")
}
else {
msg ("It's a fart machine with a button on it.")
}
Hopefully that is clear enough. If you need clarification, please ask!
^If it is an object that you use a BUNCH, indicate that and I will help there too. It's a little different, but not too bad.
hegemonkhan
22 Mar 2018, 08:49a simple example (using scripting only, might be missing some stuff and/or wrong syntax, too lazy to test it)
create ("room_x")
object_variable = create ("potion")
object_variable.parent = room_x
object_variable.quantity = GetRandomInt (1,9)
object_variable.consume => {
this.quantity = this.quantity - 1
}
list add (object_variable.displayverbs, "consume")
list add (object_variable.inventoryverbs, "consume")
object_variable.changedquantity => {
if (object_variable.quantity = 0) {
destroy (object_variable.name)
}
}