- Joined
- Mar 28, 2023
- Messages
- 21
- Reaction score
- 1
- First Language
- Polish
- Primarily Uses
- RMMZ
Hi!
I've been creating an easy Stamina System that subtracts one point every single time that player make a move on map. If stamine reach 0 playar cannot move anymore. Every 5min stamina is regenereting by 20 points. Everything is based on Veriables and already had few bug that i solved. Buy i can't solve this one, so if someone may help me?
Script:
And here is error massage:

I've been creating an easy Stamina System that subtracts one point every single time that player make a move on map. If stamine reach 0 playar cannot move anymore. Every 5min stamina is regenereting by 20 points. Everything is based on Veriables and already had few bug that i solved. Buy i can't solve this one, so if someone may help me?
Script:
JavaScript:
// Stamina System
// Default values
$gameVariables.setValue(298, 100); // Max Stamina
$gameVariables.setValue(299, 300); // Time to regenerate stamina (in seconds)
$gameVariables.setValue(300, 20); // Amount of stamina regenerated
class MyGame_Player extends Game_Character {
constructor() {
super();
this._stamina = $gameVariables.value(1);
this._lastRegenerateTime = Date.now();
}
update() {
super.update();
this.updateStamina();
}
updateStamina() {
if (this._stamina > 0) {
this._stamina--;
} else {
this._moveSpeed = 0;
}
if (this._stamina < $gameVariables.value(298) && Date.now() - this._lastRegenerateTime > $gameVariables.value(299) * 1000) {
this._stamina += $gameVariables.value(300);
this._lastRegenerateTime = Date.now();
}
this._stamina = $gameVariables.value(298) > this._stamina ? $gameVariables.value(298) : this._stamina;
}
}
class MyGame_Interpreter {
changeMaxStamina(value) {
$gameVariables.setValue(298, value);
}
changeStaminaRegenerationTime(value) {
$gameVariables.setValue(299, value);
}
changeStaminaRegenerationAmount(value) {
$gameVariables.setValue(300, value);
}
}
class Window_Stamina extends Window_Base {
constructor() {
super(Graphics.width - 160, 0, 160, this.fittingHeight(1));
this.opacity = 0;
this.contents = new Bitmap(this.width - 32, this.height - 32);
this.refresh();
}
refresh() {
this.contents.clear();
this.contents.drawText(`Stamina: ${$gamePlayer._stamina}/${$gameVariables.value(298)}`, 0, 0, this.contentsWidth(), this.lineHeight());
}
updateStamina(stamina) {
this._stamina = stamina;
this.refresh();
}
}
class MyScene_Map extends Scene_Base {
constructor() {
super();
this.createStaminaWindow();
}
start() {
super.start();
}
createStaminaWindow() {
this._staminaWindow = new Window_Stamina();
}
update() {
this._staminaWindow.updateStamina($gamePlayer._stamina);
super.update();
}
}
And here is error massage:
