- Joined
- Feb 10, 2015
- Messages
- 123
- Reaction score
- 119
- First Language
- English
First, the problem. I have a bit of code that based on my thought process, with an MP cost of 10, should result in the user getting back 6 MP. The result though, is always just 5 MP. Here is the code:
If you're still looking at this, then here's the longer explanation. All mages (determined by a passive state, 11)have their MP set to 5 (first 0, then with 5 added, done this way as the 5 will later be a variable amount) at the start of battle. The idea is that then each mage party member has their MP stored in an array at the start of the turn. They cast their spells or attack or whatever, and at the end of the turn, they get back 5 MP + 10% of whatever MP they used during that turn. Unfortunately, if a party member uses a spell that costs 10 MP, instead of the 6 MP I want to be returned at the end of the turn, they only get 5 MP returned. I have the code for returning MP set to run at the end of turn. Any help with this would be great, as I've tried changing around multiple things, and I can't seem to get it to work how I want.
Quick note: I know I could return the MP directly through each magic skill in the damage formula, but I'm planning on adding more variance to this in the future, and eventually hoping to move it from the troop events to a plugin, so I'd like to get this to work, if at all possible. Also of note, I'm (probably obvious by how awful this code is) new to js, so please excuse any poor design in this.
Code in Troop Battle Event
Page: 1
Condition: Turn 0
Span: Battle
Page: 2
Condition: Turn 1*X
Span: Turn
Page: 3
Condition: End Turn, Turn 1+1*X
Code:
var tempMP = ($gameVariables.value(12[i]) - $gameVariables.value(11[i]) * -0.1) + 5;
$gameParty.members()[i].gainMp(tempMP);
Quick note: I know I could return the MP directly through each magic skill in the damage formula, but I'm planning on adding more variance to this in the future, and eventually hoping to move it from the troop events to a plugin, so I'd like to get this to work, if at all possible. Also of note, I'm (probably obvious by how awful this code is) new to js, so please excuse any poor design in this.
Code in Troop Battle Event
Page: 1
Condition: Turn 0
Span: Battle
Code:
function battleStartMP(){
for(var i = 0; i < $gameParty.members().length; i++){
if ($gameParty.members()[i].isStateAffected(11)){
$gameParty.members()[i].gainMp((-$gameParty.members()[i].mp) + 5);
}
}
return
}
battleStartMP();
Page: 2
Condition: Turn 1*X
Span: Turn
Code:
$gameVariables.setValue(11, []);
function setInitialBattleMP (){
for(var i = 0; i < $gameParty.members().length; i++){
if ($gameParty.members()[i].isStateAffected(11)){
$gameVariables.setValue(11[i], $gameParty.members()[i].mp);
}
}
return;
}
setInitialBattleMP();
Page: 3
Condition: End Turn, Turn 1+1*X
Code:
$gameVariables.setValue(12, [])
function setTurnEndBattleMP (){
for(var i = 0; i < $gameParty.members().length; i++){
if ($gameParty.members()[i].isStateAffected(11)){
$gameVariables.setValue(12[i], $gameParty.members()[i].mp);
var tempMP = ($gameVariables.value(12[i]) - $gameVariables.value(11[i]) * -0.1) + 5;
$gameParty.members()[i].gainMp(tempMP);
}
}
return;
}
setTurnEndBattleMP();

