The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: The Mormegil on August 26, 2010, 02:27:22 PM

Title: [SOLVED] Yanfly Engine Melody and requiring target states
Post by: The Mormegil on August 26, 2010, 02:27:22 PM
I encountered a problem creating skills with Yanfly's Engine Melody. The problem is that I want to make a skill that require certain states to be upon the target in order to be used. The script allows me to require states on the user, but I found no way to requiring statuses on the target.

The skill I want to create is "Backstab", and I want it to check, once initiated, if the target is afflicted by statuses 6,8,10..16,21 or 30 (using IDs from my game). If any of these states is on the target, the skill works and deals great damage. If there are none of these states the player just wasted a turn.

The only way I can think of to accomplish this with the YEM scripts is by making three skills: "Backstab", to be used by the player, that just moves him foward and forces the target to use "Check Backstab", a skill with the <require any state: 6,8,10..16,21,30> tag that goes back and forces the player to use "Backstab!" that actually deals damage.  ??? This is just overcomplicated, and uses up three skill slots to make one attack. I was wondering if anyone could find a better way to do this, either using YEM's functions, creating new YEM "melodies" or scripting a compatible script (I don't think that's strictly required but I may be wrong).

Anyone can help me?  :-\
Title: Re: Yanfly Engine Melody and requiring target states
Post by: Terra-chan on August 26, 2010, 08:42:41 PM
Can't you just have the skill call a common event that does all of the checking before accomplishing the skill in one skill? I'm not really experienced in that area yet though.

I think wasting the turn is pretty lame, you should at least do normal damage imo, but that's my opinion :P
Title: Re: Yanfly Engine Melody and requiring target states
Post by: The Mormegil on August 26, 2010, 09:07:59 PM
I could, if I knew how to script well enough. But I don't know how to check enemies' statuses. If I did, I could use the IF melody function to check it, then proceed.


In fact, I tried to make a new target option (target: Backstab) that checked for the status, but well, it didn't. Here's what I tried, if anyone is intrested...

when "BACKSTAB"
   target = opponents_unit.smooth_target(@target_index)
   if target.states.include?(6||8||10||11||12||13||14||15||16||21||30)
      targets.push(target)
   end


It works... to a point. It lets me choose the target (so the first line is good. Well, that's copied and pasted from another target option so yeah), then when it needs to add it to the targets array it does not. It doesn't report errors though, so I'm a bit confused.
Title: Re: Yanfly Engine Melody and requiring target states
Post by: The Mormegil on August 26, 2010, 09:09:49 PM
Also, since enemy statuses are displayed on help window and Backstab has NO cost whatsoever, if the player doesn't check to see if the status is altered it's his fault and wasting a turn seems appropriate... Otherwise it would have been easier to just add it to actor's normal attack as a damage boost, right?
Title: Re: Yanfly Engine Melody and requiring target states
Post by: Shinami on August 27, 2010, 04:41:48 PM
Within conditional branches(event command) on page 3, you can check to see if an enemy has been inflicted with a status condition, if you feel like using common events for backstab.


When debugging scripts, it's best to get a look at the information being handled. Do you know what information "target" holds? Do you know how "targets" gets used in deciding what gets hit? That's why you use the "p" command to print out the contents of things or script your own method that dumps information into text files for you to look at while the game is running in test mode.
Title: Re: Yanfly Engine Melody and requiring target states
Post by: The Mormegil on August 27, 2010, 05:59:12 PM
Shinami, THANK YOU. The tip on the p function was really helpful (I didn't know, or rather, didn't realize it could be used mid-game). I tried a couple things and even if what I wrote isn't the best of solutions it gets the job done! Thank you again, and I mean it!

(If anyone is intrested, what I wrote is this:

when "BACKSTAB"
  target = opponents_unit.smooth_target(@target_index)    # to select the target
  backstab_check = false
  for key in target.state_turns.keys
    if key == 6
         backstab_check = true
      elsif key == 8
         backstab_check = true
      elsif key == 10
         backstab_check = true
      elsif key == 11
         backstab_check = true
      elsif key == 12
         backstab_check = true
      elsif key == 13
         backstab_check = true
      elsif key == 14
         backstab_check = true
      elsif key == 15
         backstab_check = true
      elsif key == 16
         backstab_check = true
      elsif key == 21
         backstab_check = true
      elsif key == 30
         backstab_check = true
     end
    end
    if backstab_check
       targets.push(target)
    end
)
Title: Re: [SOLVED] Yanfly Engine Melody and requiring target states
Post by: Shinami on August 27, 2010, 07:09:58 PM
There should be a better way you can write that check with the any? method from Enumerable.


  target = opponents_unit.smooth_target(@target_index)    # to select the target
  backstab_check = false
  for key in target.state_turns.keys
    backstab_check = [6,8,10,11,12,13,14,15,16,21,30].any? {|v| v == key}
  end
  if backstab_check
    targets.push(target)
  end

any? is a method from the module Enumerable. any? will evaluate if target.state_turns.keys matches any of the specified values(hence "v" being used) and will return TRUE if any of them match. If none of them match, it'll return FALSE.

It's my first time using a built in module so if what I wrote above doesn't work, you can reference this example.

Returns FALSE when all items are false. If any item is true, immediately returns TRUE.

When using a block, evaluates the block against each item and returns FALSE if all outcomes are false.
If the block returns TRUE at any time, immediately returns TRUE.

Shinami: FYI, "block" refers to the [1,2,3] being checked since it's a "block" of data. I think. >.>
p [1,2,3].any? {|v| v > 3}   # => false
p [1,2,3].any? {|v| v > 1}   # => true


Title: Re: [SOLVED] Yanfly Engine Melody and requiring target states
Post by: The Mormegil on August 28, 2010, 07:19:16 AM
It works! Thank you again! :D