Object to get used up
Omega001
19 Jul 2012, 10:38I need to make a object that gets destroyed after a certain amount of uses. What it is a antiseptic spray that runs out after 5 uses, so I'm working in the "use on it's own" section, then after it's used 5 times, gets removed from the game. I need a way to do this.
sgreig
19 Jul 2012, 11:32All you really need is to set an attribute on the bottle, and call it something like "uses". Then in the use script for the object, first have it check that "object.uses" is less than 5. If it is, use the object as normal and add 1 to the "uses" attribute. If it's equal to 5, display a message that it's empty. So code-wise it would look something like this:
if (object.uses < 5) {
code for what happens when you use the spray bottle
object.uses = object.uses + 1
}
else {
msg ("The bottle is empty.")
}
Omega001
19 Jul 2012, 12:39Yes that worked. Thank you for this I should be able to imply this into other stuff.
xordevoreaux
22 Jul 2012, 02:15I do something similar for burning matches, lighting lighters, etc. I have an object class that I apply to everything in the game, and it has various properties regarding an object's ability to burn:
burnability, isburning, burnticklife, burntickconsumed,
where:
burnability determines if it can be burned at all,
isburning is lit, essentially
burnticklife is the total number of ticks of the timer that the object can burn, for the life of the object
burntickconsumed is how many of the total ticks of the burnticklife have been spent.
So for a candle, for instance, it may have a burnticklife of 50, but if you keep dousing it before burntickconsumed >= burnticklife, you can ignite it over and over again, until, of course, burntickconsumed >= burnticklife, and then it's spent, it cannot burn any more.
burnability, isburning, burnticklife, burntickconsumed,
where:
burnability determines if it can be burned at all,
isburning is lit, essentially
burnticklife is the total number of ticks of the timer that the object can burn, for the life of the object
burntickconsumed is how many of the total ticks of the burnticklife have been spent.
So for a candle, for instance, it may have a burnticklife of 50, but if you keep dousing it before burntickconsumed >= burnticklife, you can ignite it over and over again, until, of course, burntickconsumed >= burnticklife, and then it's spent, it cannot burn any more.