How to make a stamina system?
Weiyu
Member Posts: 216
Hello everyone, I have a problem about make a stamina system.
I want to every time play game, the stamina bar will lose a few stamina.
If stamina is 0, player will not play.
And the stamina bar will get 1 point every 5min.(Limit is 30 point)
If player want to get stamina too fast, he/she can look advertisement.(every time look it can let stamina bake 2 point.)
How to make it? please tell me><"
Thank you.
Comments
Create a game integer attribute call it stamina set it to the number you want , put a timer every few seconds change attribute game.stamina to game.stamina - 2
Create a rule if game.stamina = 0 then game over or change scene or pause game whatever you want
Create a rule if game.stamina is less than your limit points
Put a timer every 300 seconds change attribute game.stamina to game.stamina +1
You can see this video tutorial by @Lost_Oasis_Games it will give you an idea on how to make that
You have all the logic ready you know exactly what you want to do and you broke it into different parts now its just translating that into GS to make it understand.
Ok, so the above refill stamina rule works if there is only one scene.
If there is more than one scene, you must have this refill stamina rule in every scene.
I just come up with below idea, I think it should work (It does not need every timer or constrain actor, it should use less resources):
Create actor and put this rule inside:
If "game.time" is equal to "game.#ofStamina" *300,
then
change attribute "game.#of Stamina" +1.
if "game.stamina" is <30 change attribute "game.stamina"+1"
Remember to put this actor in every scene. This will ensure stamina is refilled even you are playing.
you will need to reset "game.#ofStamina" to 1 whenever the game is open.
So as long as the game is open, it will refill stamina. If the game is close, and you want to refill stamina, then you will need to do timestamp, which is a lot more tricky.
what would happen when he looses stamina ? and it becomes 1 or 2 instead of 6 , then your condition wont work, game time might be at 30 minutes and game.stamina * 300 wont be true and he wont be able to add more stamina (if game.time = game.stamina*300 change attribute stamina to stamina +1) , and he wants to loose few stamina points every few seconds , how do you want him to start with 1 ? Im just asking so that it doesnt mess his logic up.
Oh, I might have confused you a little bit.
For now we know that he want to lose stamina when he play a game. So, whenever he plays a game just change "game.stamina" to "game.stamina-1", assume is 1 at this point.
This will not affect the refill rules.
The "game.#ofStamina" attribute is just a time/number reference for next stamina refill. Initially we set this at 1. And when "game.time" is equal to "game.#ofStamina"*300, we will change "game.stamina" to "game.stamina+1" if "game.stamina" is not 30; this means that when game.time is at 300seconds then we will add 1 stamina if stamina is not at max (30). We also change "game.#ofstamina" to "game.#ofstamina"+1 at the end of the rule because we need to set up for next refill.
So now, "game.#ofstamina" is at 2, which means that the refill rule will fire again when "game.time" is equal to 600 ["game.#ofstamina", which is now 2, multiply by 300].
I am not confused , your method works if you dont want to loose stamina but think about it , if i play the game , and i start it with my stamina 1
it will change to 2 when time is 300 it will change to 3 when time is 600 , now if i loose my stamina at this point and it becomes 1 again
1(stamina)*300 = 300 is not = to game time(900) anymore so your condition wont trigger , and change attribute stamina to stamina + 1 wont work . You will cause him issues later on this way.
You are definitely confused. game.#ofstamina is not the same as game.stamina.
1. game.#ofstamina is use as number reference to trigger every 300s. Perhaps, I should name this "game.#ofstamina" as "game.refillnumber".
2. game.stamina is the stamina
3. game.refillnumber is to reset to 1 whenever game is launch.
4. These are two different attributes; refilling or using stamina will only affect "game.stamina".
I hope this make sense now.
Your right i was confused I can't believe i read it couple of times and couldnt notice that my bad
You even mentioned it earlier lol sorry about that
I appreciated your time and effort. Thank both answer my problem.
Words are not enough to express my gratitude.
Thank you♪(o=゜▽゜)