Diminishing water supply

OurJud
07 Dec 2015, 08:28Let's say I give my player the opportunity to fill a vessel of some sort with water. I would like that supply to diminish every time I force them to drink.
Is there a pre-written script for this in existence, as I'm not sure how I'd go about it.
I'd like to create a global command for 'drink; drink water' that checks for a number of things.
1. If the player is carrying water >> give water >> diminish supply by a quarter (indicated by inventory saying 'A flask of water, full / A flask of water 3/4 full, etc etc')
2. If there's a source nearby (in other words in my description) >> give water >> if already carrying water don't diminish supply
3. If player is not carrying water and there's no nearby source >> no water.
I'd also need a script which when near a source, the command "collect water" would return supply to full.
Not asking anyone to simply write the script for me, but any pointers in terms of what I would need (flags, etc) would be appreciated.
Is there a pre-written script for this in existence, as I'm not sure how I'd go about it.
I'd like to create a global command for 'drink; drink water' that checks for a number of things.
1. If the player is carrying water >> give water >> diminish supply by a quarter (indicated by inventory saying 'A flask of water, full / A flask of water 3/4 full, etc etc')
2. If there's a source nearby (in other words in my description) >> give water >> if already carrying water don't diminish supply
3. If player is not carrying water and there's no nearby source >> no water.
I'd also need a script which when near a source, the command "collect water" would return supply to full.
Not asking anyone to simply write the script for me, but any pointers in terms of what I would need (flags, etc) would be appreciated.
The Pixie
07 Dec 2015, 08:56I would set flags on any rooms that have water sources, and then check them first for your DRINK command, and for FILL command. For the container, I would use an integer (int) attribute, and reduce it by 1 each time the player takes a drink from it. When it gets to zero, it is empty.

OurJud
07 Dec 2015, 09:23Why do I do this to myself?
So this is what I have so far:
I created a room with an object called 'empty water bottle. I also unset the flag ('water') from the next room.
That room leads to another with a water source. In this room I set a flag to the 'player' called 'water'.
I then created two commands for 'drink' and 'fill bottle'. Under 'drink' I check for the flag. If the flag is present I grant water, if not I don't.
... and that's where my brain starts to freeze up.
On the command 'drink' I need to check for both a source and whether the bottle is full or not.
If the bottle contains any water AND there's a source, I need to grant water without taking it from the bottle.
If there's no source BUT the bottle contains water, I need to grant water AND reduce the supply.
If there's neither I need to deny water.
But then I need to handle the 'fill' command ramifications.
If there's a supply and the bottle is anything but full, then replenish on 'fill bottle'.
If there's a supply and the bottle is already full, print 'Already full'
If there isn't a supply, then print 'No supply'
And then there's the inventory, which needs to reflect the level of water in the bottle whenever the player types 'i'
Tell me honestly, am I trying to go to lengths that no one else would even think of doing, because I can see this taking me days to get right.
So this is what I have so far:
I created a room with an object called 'empty water bottle. I also unset the flag ('water') from the next room.
That room leads to another with a water source. In this room I set a flag to the 'player' called 'water'.
I then created two commands for 'drink' and 'fill bottle'. Under 'drink' I check for the flag. If the flag is present I grant water, if not I don't.
... and that's where my brain starts to freeze up.
On the command 'drink' I need to check for both a source and whether the bottle is full or not.
If the bottle contains any water AND there's a source, I need to grant water without taking it from the bottle.
If there's no source BUT the bottle contains water, I need to grant water AND reduce the supply.
If there's neither I need to deny water.
But then I need to handle the 'fill' command ramifications.
If there's a supply and the bottle is anything but full, then replenish on 'fill bottle'.
If there's a supply and the bottle is already full, print 'Already full'
If there isn't a supply, then print 'No supply'
And then there's the inventory, which needs to reflect the level of water in the bottle whenever the player types 'i'
Tell me honestly, am I trying to go to lengths that no one else would even think of doing, because I can see this taking me days to get right.

OurJud
07 Dec 2015, 10:08Why isn't this working? I start in a room without the flag, then I take the bottle and try to fill it. This should get the response "There is no water here", but I just get a blank response.
Edit.
Sorry, I know I do a lot of this (answering my own questions, I mean) but it's just the way I work.
The mistake I was making in the above script was having the second rule set as an 'else' when it should have been another 'if'.
I always wondered why there wasn't a way to say "If bla bla bla AND bla bla bla then print "bla bla bla". But now I think I understand that a series of simple ifs does this.
This is the modified script and covers all combinations concerning source and whether the player is carrying the bottle or not.
Just need to work out the script for the 'drink' command and how to diminish the supply on 'drink' so that it's reflected in the inventory. I don't know anything about Integers.
In fact... brainwave! I'm going to make the supply a simple 'one drink and it's gone' affair, rather than a fancy diminishing supply. Then I only need to handle whether the bottle is full or empty.
if (Got(empty water bottle)) {
if (GetBoolean(player, "water")) {
msg ("You fill the bottle.")
}
}
else {
if (Got(empty water bottle)) {
if (not GetBoolean(player, "water")) {
msg ("There is no water here.")
}
}
}
Edit.
Sorry, I know I do a lot of this (answering my own questions, I mean) but it's just the way I work.
The mistake I was making in the above script was having the second rule set as an 'else' when it should have been another 'if'.
I always wondered why there wasn't a way to say "If bla bla bla AND bla bla bla then print "bla bla bla". But now I think I understand that a series of simple ifs does this.
This is the modified script and covers all combinations concerning source and whether the player is carrying the bottle or not.
if (Got(empty water bottle)) {
if (GetBoolean(player, "water")) {
msg ("You fill the bottle.")
}
}
if (Got(empty water bottle)) {
if (not GetBoolean(player, "water")) {
msg ("There is no water here.")
}
}
if (not Got(empty water bottle)) {
if (GetBoolean(player, "water")) {
msg ("You don't have a bottle.")
}
}
Just need to work out the script for the 'drink' command and how to diminish the supply on 'drink' so that it's reflected in the inventory. I don't know anything about Integers.
In fact... brainwave! I'm going to make the supply a simple 'one drink and it's gone' affair, rather than a fancy diminishing supply. Then I only need to handle whether the bottle is full or empty.

OurJud
07 Dec 2015, 11:37I think I got there, and I'm so damn proud I'm going to add it to the Libraries section.
If someone competent in scripts could check it over to make sure it works as I think it does, I'd be grateful.
If someone competent in scripts could check it over to make sure it works as I think it does, I'd be grateful.
Marzipan
07 Dec 2015, 18:08Sounds like you've already got it sorted, but this is exactly the kind of thing I'm needing for my game. Going straight home now and I'll give it a go. I know I've done something similar in ADRIFT using tasks and object states, and I'm thinking theoretically this could use the same basic steps as a Quest file I already have with a rechargeable energy weapon. I'll see what I can do.
honestly I think I have more fun tackling little issues like this than writing any kind of game itself. Always gives a warm fuzzy feeling like successfully solving a puzzle.
honestly I think I have more fun tackling little issues like this than writing any kind of game itself. Always gives a warm fuzzy feeling like successfully solving a puzzle.


OurJud
07 Dec 2015, 18:13Marzipan wrote:honestly I think I have more fun tackling little issues like this than writing any kind of game itself. Always gives a warm fuzzy feeling like successfully solving a puzzle.
I know what you mean!
The 'finished' scripts in the library section are not perfect. I tested it to death and found a few issues, but these only arise if you do really illogical things.

Anonynn
07 Dec 2015, 20:08I left a reply in the Libraries section too if you care to look 


OurJud
07 Dec 2015, 21:55Neonayon wrote:I left a reply in the Libraries section too if you care to look
Replied

HegemonKhan
07 Dec 2015, 23:44@ OurJud:
I reduced (symplified) your code redundency:
I reduced (symplified) your code redundency:
if (Got(empty water bottle)) {
if (GetBoolean(player, "water")) {
msg ("You fill the bottle.")
}
else {
msg ("There is no water here.")
}
}
else {
if (GetBoolean(player, "water")) {
msg ("You don't have a bottle.")
}
else {
msg ("You don't have a bottle, and nor have any water, as well.")
}
}

OurJud
08 Dec 2015, 08:25Thanks very much, HK 
I have a couple of scripts from other members in the library, so I'm sure I can get it working perfect now. When I do, I'll update my original post in there.

I have a couple of scripts from other members in the library, so I'm sure I can get it working perfect now. When I do, I'll update my original post in there.