_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,088
Reaction score
2,681
First Language
Greek
Primarily Uses
RMMZ
So I was wondering... we can call a Common event from a Skill. Let's say we want to refer to a targeted enemy inside the common event of that skill and make a conditional branches and do stuff by probabilities and stuff.

How can I set a variable to contain the targeted enemy?

I know how to set a value to a specific variable, referring to it by its #id on the database (var).

$gameVariables.setValue(var, value);

What I don't know is how to set on value this:

value should be 0 if no enemy is selected or battle occurs (by default).
else
value becomes 1,2,3,4,5,or 6 according to the currently targeted enemy.

Remember, this script command will execute while a spell is cast thus the spell already has a target.
I WANT THAT TARGET VALUE! :p
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,373
Reaction score
1,404
First Language
Spanish
Primarily Uses
RMVXA
Scene_Battle.prototype.onEnemyOk()

I think your answer lays there.
in Ace, it is
Code:
BattleManager.actor.input.target_index = @enemy_window.enemy.index.
"enemy_window" being a window_selectable from Scene_Battle, "enemy" being one enemy object from the Troop object used to fill the window.
remember that everything is cross-referenced and linked together, everywhere, so you'll have to do some tracking.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,479
Reaction score
1,870
First Language
EN
Primarily Uses
RMMZ
:kaohi: I've just realised that this approach has a flaw: the damage formula is only calculated on hit, so unless it's a Certain Hit skill you have to be very careful with how you use your variable! :kaoback:

What do I mean by "be very careful"? We just want to ensure that the variable is always set to some "empty"/"miss" value before the skill executes. Pick a value that you'd never expect otherwise, e.g. 9001. If the variable is checked and it's this value, that means it wasn't set in the skill formula (i.e. the skill missed). This should be initialised once at some point before you can use the skill (e.g. at game start), and then at the end of the common event you're going to run after the skill use. :kaophew: I think it's safe now! Just be sure not to use this variable elsewhere (or at least, not without resetting its value afterwards). :kaoswt2:

So, the damage formula. Here's an example I tried out:
Code:
v[1] = b.isEnemy() ? b.index() : -1; a.atk * 4 - b.def * 2
Whoa, slow down. OK, so, this splits into two lines, separated by the semicolon:
  • Set variable #1 to the target's index if they're an Enemy, or -1 if they aren't (i.e. if they're an Actor...Enemies make terrible thespians). Note that index is 0-based, i.e. the first enemy in a troop (or first actor in the party) has index = 0. Hence my choice of -1 for actors! :kaoswt:
  • Calculate the skill damage as a.atk * 4 - b.def * 2. It's just the boring old attack formula.
Change these values as you like. If you'd like the index to start from 1 rather than zero, just swap the b.index() for b.index()+1. Or adjust its value in your event! :kaopride:

Finally, make sure your common event is attached to the skill and edit it as appropriate. Note that MV's "Enemy" event commands don't seem to provide a variable option for index, so you'll have to either work with scripts or lots of Conditional Branches. :kaosigh:
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,088
Reaction score
2,681
First Language
Greek
Primarily Uses
RMMZ
Thanks for the reply but I don't want a formula.
I want a javascript command to be used in eventing.


$gameVariables.setValue(var, value);

Give me a command that will give to the value argument, the id of the enemy (1 to 6) if it is on battle, otherwise it will be set to 0 if no enemy exists. The spell is calling a COMMON EVENT that will use a script command in it.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,479
Reaction score
1,870
First Language
EN
Primarily Uses
RMMZ
To clarify: enemyId is set in the database, index is the ordering of the Enemies in the current Troop. I assume you want the index, though, given your stated range of 1~6? :kaoswt2:

Here's a script-call version that (I think) checks the last action's target regardless of hit or miss. It'll store 0 in variable #1 if the target was an actor, or one plus the target's index (i.e. a value 1~8) if they were an Enemy:
Code:
$gameVariables.setValue(1, BattleManager._action ? 1 + BattleManager._action._targetIndex : -999)
I've set it to store a value of -999 if there's not been an action yet this battle; feel free to edit it all as you like. :kaoslp:
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,088
Reaction score
2,681
First Language
Greek
Primarily Uses
RMMZ
So this:

Code:
$gameVariables.setValue(40, BattleManager._action ? 1 + BattleManager._action._targetIndex : -999)

inside the formula works like a charm.
I stored the value to the 40th variable.
IS this the only way to run code through battle?
I mean, can you get the current move's targetIndex using the Common Event?
The real question is, what the scope of targetIndex is. Can it be reached from the common event and what the variable would be?


Case is solved, on my behalf, but I am curious to know if you can use a script command from common event and do the same thing.
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,373
Reaction score
1,404
First Language
Spanish
Primarily Uses
RMVXA
BattleManager._action._targetIndex

just that.
BattleManager stores all the data prior to processing the turn, and then processes the turn.
once you set the turn to run, the current *action* is performed over Troop[*targetindex*], and then cleared.
*calling the common event* is also part of *the action*, so at the time of calling the common event the target is still the same target selected to perform *the action*
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,479
Reaction score
1,870
First Language
EN
Primarily Uses
RMMZ
I mean, can you get the current move's targetIndex using the Common Event?
My first method does exactly that: the formula directly references the index of the action's target as it is established. As @gstv87 says, my second method works in retrospect, checking the last action performed and extracting the index of its target; both should work fine so long as you're in battle! ^_^

The battle-based event interpreter is a member of $gameTroop (_interpreter property), whereas _targetIndex is a property of the Game_Action object being processed. Incidentally, I'm more confident of the first method I suggested. _targetIndex returning -1 regardless of which actor was targetted makes me think I'm missing something... :kaoswt:

If checked too early in the battle, no action exists, hence the check for BattleManager._action's existence before returning the _targetIndex value.

I feel I should also mention that the only real difference in output between the two methods I described is that the second ignores misses/evasions. Re variable assignment, all of the following are totally equivalent:
  • Valid shorthand for skill/item formulae:
    Code:
    v[1] = 5
  • Valid everywhere:
    Code:
    $gameVariables.setValue(1, 5)
  • Valid everywhere:
    Code:
    $gameVariables._data[1] = 5
 

Latest Threads

Latest Profile Posts

Playing my game to improve my game. (Totally not procrastinating)
Hope he recovers fast :|
Looks like it's functional:
It's a common thing to forget eating &drinking while you are working concentrated, right?
If I had discovered RPG-Maker before moving together with my girlfriend, I'd have died of dehydration a long time ago.
Ami
trying to change my picture & got screwed up...

Forum statistics

Threads
112,497
Messages
1,068,688
Members
146,165
Latest member
mad_maniac
Top