New account registration is temporarily disabled.

BATTLE EVENT IN RMXP

Posts

Pages: 1
I've created a battle event where when an enemy dies it drops an
item for a quest. the only problem is that it's not working at all.
I have it set up like this:

if enemy 1. is inflicted with dead then
show text: "received poison sac"
add 1 poison sac item to inventory
add 1 to poison sac variable
end branch

it will only work trigger if the switch Poison Sac is on. What is needed to get
this to work?
Marrend
Guardian of the Description Thread
21806
Why not just have the enemy drop the quest item normally with a 100% chance? I suppose using that would depend on how rare the critter is, though. If it's a fight that only happens once ever (a boss?), then you can totally make it a normal item drop. If it's a slightly more common enemy, then, my guess is that there's only one enemy in the troop where this code shows up, so it doesn't even run (the battle is over after all enemies are defeated).

That code you have might work if there are two or more enemies, but players can just as easily kill enemy in Slot 2, 3, or whatever, before killing enemy in Slot 1.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
Well he said he needs it to only drop if a switch is on. So in other words it only drops while you're on the quest; otherwise it doesn't drop. And the variable he's using suggests to me that the player needs to collect several of this item for the quest.

What you want to do is add the item to the player's inventory at the beginning of the battle instead of the end. Then make it impossible to run from the battle. You won't get a message this way, but you'll get the item. You can show a message on the field map after the battle if you want; make a common event that detects when the variable has increased, and shows a message if so.

The other option is to make it a normal drop like Marrend first suggested, but then use a script to make certain enemy item drops depend on certain switches. If you can't find a script to do this, it's probably a pretty easy one to make. Good way to learn scripting.
Well I changed how it works now. I changed the conditions to be when the enemy's hp hits 0% or below and when the switch is on then it triggers and for some odd reason that works. Although How do I get it so when the last monster of the group is killed that I still get the item?
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
Yes, just like Marrend said. The way you have it coded doesn't work when the enemy is killed last. You can fix it by... doing one of the two ideas I gave you yesterday?

Here's a third option. Make it be a normal 100% drop from the enemy, but create two versions of the enemy, one that drops the item and one that doesn't. And then make the player fight one version of the enemy or the other depending on whether the switch is on or not. If you've got a custom encounter system, this is super easy. If you're using RMXP's built in random encounter system, you'll need to make two copies of each map that the monster appears on, one with one version of the enemy and the other with the other version of the enemy. And then teleport the player to the correct version of the map depending on the switch.
So if I make it as a script I create a separate module for the code and say:
if this switch number is active then
this monster drops this item
place one in player's inventory
plus add on to the variable
end

Something like this? I'm not use to scripting though.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
Mmm. If you want to do it with scripts, I can definitely help you get it working. Sounds like it'll be something I can use in my own projects too, actually. It should be an easy script since all we're doing is adding a condition to something RMXP already does.

The first thing you want to do is find the function in the original scripts that handles item drops, and make a copy of it in a new script page. Off the top of my head, I'm not sure exactly where in the original scripts to tell you to look for that (at least not in a way that makes sense if you've never looked at the code before). But I can find it and explain what I mean when I get home late this evening.
Well I've looked in the code before when I was attempting to make a stealing skill, but I got a little confused where the item drops code might be. From what I saw in the code I think its mixed in with the enemies coding and some other parts of the code too, but I'm not sure though.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
OK! Starting on line 130 of the Scene_Battle 2 page of scripts, here's the function that hands out rewards after battle. This is the original one, which I haven't changed yet. (You'll notice one minor difference, which is the line "class Scene_Battle" before the function and the line "end" after it. But actually these two lines are present in the original script too, they're just at the very beginning and end of the page, not right before and after the function. They're important to include.)
#--------------------------------------------------------------------------
# * Start After Battle Phase
#--------------------------------------------------------------------------
class Scene_Battle
  def start_phase5
    # Shift to phase 5
    @phase = 5
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    gold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add EXP and amount of gold obtained
        exp += enemy.exp
        gold += enemy.gold
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end
end

Open your scripts and go down to the bottom. When creating a new script, it goes after all the built-in scripts, but before Main. Right-click on the last script before Main and choose Insert to create a new page of scripts. Then paste the original script in there.

Since our script is defined after the original one, but has the same class name and function name as it (the function start_phase5 in the class Scene_Battle), our script will override the original built-in script. Of course, currently it does exactly the same thing as the original built-in script, so that's not very interesting yet.

At this point, it's a good idea to load the game up and make sure it still works. If you didn't do anything wrong, you should still be able to open the game, win a battle, and get rewards like before.

To make enemy drops depend on switches, you need to create a mapping of which switch is required for which enemy. That mapping will be a variable at the top of the script. Add it like this:

#--------------------------------------------------------------------------
# * Start After Battle Phase
#--------------------------------------------------------------------------
class Scene_Battle
  Enemy_Drop_Condition_Switches = {
    12 => 230,
    28 => 231,
    29 => 232
  }

  def start_phase5
    # Shift to phase 5
    @phase = 5

...etc.
Leave everything below that the same for now. Concentrate on getting those variables right. I've set it up so that there are two numbers on each line. We'll make it so that the first number is the ID of a monster, and the second number is the number of the switch that needs to be turned on for that monster's item to drop. So in my example, monster #12 will only drop its item if switch 230 is turned on, monster #28 will only drop its item if switch 231 is turned on, and monster #29 will only drop its item if switch 232 is turned on. I just picked random numbers for the example; change it to whichever monsters and switches you actually want to use. My example has three lines, for three monsters, but you can add more lines; as many as you need.

At this point, it's a good idea to load the game up again and make sure it still works. We've created the variables we need, but we haven't actually changed the behavior of the function yet, so if everything's going smoothly the game should still seem unchanged when playing it.


Now that we've defined the variables, the last step is to change the behavior of the function to actually check those variables.

#--------------------------------------------------------------------------
# * Start After Battle Phase
#--------------------------------------------------------------------------
class Scene_Battle
  Enemy_Drop_Condition_Switches = {
    12 => 230,
    28 => 231,
    29 => 232
  }

  def start_phase5
    # Shift to phase 5
    @phase = 5
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    gold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add EXP and amount of gold obtained
        exp += enemy.exp
        gold += enemy.gold
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob and $game_switches[Enemy_Drop_Condition_Switches[enemy.id]] == true
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end
end

I only changed one line in the function's behavior. In the line where it checked the drop chance against a random number, I added a second condition, checking to see if the switch we defined for that monster was turned on.

With the code like this, the drop conditions should be working perfectly. Test your game out and make sure. Let me know if you have any problems, or if you're totally pro and get it working on the first try.
Yeah I've run into a problem where if I run into any of the other monsters the game crashes, is there some way they can still get through along with the monsters that have quest items?

EDIT: I should say is there any way to account for the monsters that don't have drops, and ones that do with out quests?

update: i'm getting a nomethod error on line 20 in the Game_Switches with '<=' when an enemy that dosen't have treasure to drop end the battle.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
Hmm okay. I think I see the problem. It tries to check whether the switch is turned on, even when there's no switch to check. Try changing that long line to:

if rand(100) < enemy.treasure_prob and Enemy_Drop_Condition_Switches.include?(enemy.id) and
        $game_switches[Enemy_Drop_Condition_Switches[enemy.id]] == true


See if that fixes it. Now it checks to see if the enemy ID is included in the stuff you defined at the top before it checks to see if the switch is turned on.

Yes, you can split that line of code into two lines like that, as long as you split it after the word "and".

If it still errors, copy and paste your entire script into the post so I can see it. When it tells you "error on line 20", that doesn't help me unless I know how many lines you've added to the top.
OH, one other question: I have a boss with some towers and I want to make so when the player attacks the boss with a skill that the skill attack is redirected to the tower instead of the boss. Can this be easily done using scripting or can I do it use the battle event?
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
This sounds pretty hard and I don't know where to begin. You might be able to find an add-on script that gives you the Cover ability from FF4, if you look around. And then you might be able to give that ability to enemies. Blizzard's Tons of Add-Ons is a good place to start.
Trihan
"It's more like a big ball of wibbly wobbly...timey wimey...stuff."
3359
You could hard-code that into the battle script if you only need it the one time. In the code where it first sets instance variables for the target, check if the target's ID is that of the boss, and if so change it to the tower (but you'd obviously have to check if there's still a tower alive in the battle by looping through the living enemies).

I would show you how to do this but I don't have RMXP any more and thus don't have access to the scripts for it.
I'm looking for a way to mimic Celes's Runic Skill for the towers.
Pages: 1