Hello, guys.
I'm struggling with making a script that lets basic attack execute common event like skill ,because it's my first time to edit script... :(. None the less, I made something.
if @active_battler.is_a?(Game_Actor)
@common_event_id = 1
end
for target in @target_battlers
target.attack_effect(@active_battler)
end
Honestly, In Scene_Battle 4, I just added this
if @active_battler.is_a?(Game_Actor)
@common_event_id = 1
end
above 'for target ~ end' on 212 line.
Anyway, it works. But what I want is for example, when 1st enemy was hit by basic attack, 1st common event is called, and when 2nd was hit, 2nd common event is called. But there's a problem that 1st common event is always called whenever my party try basic attack to enemies not even 1st enemy. I know I should do more something to make it happen.. But, above all things, I don't know how to make a difference between enemies as a target. I hope one of you guys knows about this.
P.S- I'm not an English speaker. Sorry for my terrible writing filled with grammatical errors and awkward expressions.
Why does each enemy have to trigger a different common event? What do your common events do?
There are a few reasons. I can do many thing if this works. I made some shots for this.
(https://i.imgur.com/NcTOgBc.png)
I made a 1st common event (it can be any number) that if 1st enemy is in 'Stun' state , when it is hit, it will get extra damage '100'. In first image, '308' on 1st ghost is basic attack damage, and in second one, '100' is damage triggered by common event. It doesn't matter when I only have one party member.
(https://i.imgur.com/FdgATOU.png)
But, when I have more party members like 3rd screenshot, what I intend is 1st common event triggered only by Jax's basic attack does damage to 1st enemy 'Ghost'. However, as you can see in the last one, common event activated by Lilith's basic attack also does damage to 1st ghost although Lilith targets 2nd Ghost because I didn't differentiate common events in script. And I thought if I made 1st common event, 2nd, 3rd... 8th according to each enemy's number, I could control damages applied on enemies. So I want to make script happen differently.
if @active_battler.is_a?(Game_Actor)
@common_event_id = 1
end
I just thought above this code, if I put proper condition like 'if 1st enemy is targeted (of course, this is not even a script)', '@common_event_id = 1' happens and 'if 2nd enemy is targeted', '@common_event_id = 2' does,...,up to 8th, that would work. Can this be done? or is there more effective way to do this? Sorry for bothering you and thank you for watching this.
I think I have an idea. This is your code.
if @active_battler.is_a?(Game_Actor)
@common_event_id = 1
end
for target in @target_battlers
target.attack_effect(@active_battler)
end
Right now, the event id is hardcoded to 1, so obviously it will always use the first common event. So we need to define which enemy was targetted.
There is a property for each enemy called
index. This property tells us what position the enemy has inside the enemy group. So, this actually tells us if it is the 1st, 2nd, 3rd, and so on.
Now, in order to be able to access the
index, since is a property of the enemy object, we need a reference to that enemy object.
Luckily for me (?), you've actually shared a place that includes a reference to that object!
for target in @target_battlers
target.attack_effect(@active_battler)
end
And this is the new code:
for target in @target_battlers
if @active_battler.is_a?(Game_Actor)
@common_event_id = target.index if target.is_a?(Game_Enemy) ########
end
target.attack_effect(@active_battler)
end
The important line is the one marked with the #s. The for cycle iterates between all targets. We now check if the attacking battler is an actor (like in your code), and if it is, we set the common event ID to the target index if target is an enemy.
And voilĂ ! It should activate a common event depending on the targetted enemy index. Only thing is, if your attack affects all enemies, it will only run the last common event.
But I'm lazy today so I leave this here xD. Salut!
Personally, I would try to come up with some kind of script call that gets the last target index, so instead of dealing with 8 common events, we only need one.
In actuality, I'd just write another method directly in Scene_Battle and process everything there.
I recommend looking into class Game_BattleAction and calling the variable Game_Actor/Game_Enemy#current_action to get its reference.
orochi, I tried putting your code in script but it did't seem to work.. In my opinion, enemy's index doesn't seem as simple as I think... I just guessed it would be just number such as 1, 2, 3. But maybe there is more complex components I don't know exactly.
and KK20, thank you so much for your attention. Before coming here, I did asked to many users about this, but in my country there are few users using rpg maker xp... So, I couldn't get any feedback.
I clung to coding long script. However, I need not have had it with script. I found more effective way to do this not using script. I made only one common event and added some conditions referring orochi's and KK20's ideas without adding redundant scripts. As a result, it works well. Thank you guys. :haha: