Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Setting preemptive/surprise based on switch state

ooryl2

Member

Howdy

I'm trying to set the preemptive or surprise attack status based on the state of a switch. I'm using chasing/fleeing events for my monsters instead of random encounters. I'm using default scripts/battle system except for the variable fix script and Yanfly's event chase script.

I have the event set up so that when it touches the player, it looks at the direction both the event and the player are looking. If they are looking the same way, and the event is behind the player (in effect the event is touching the back of the player), it turns on Switch 0100: Enemy attacks first. If they are looking the same way, and the event is in front of the player (in effect the player is touching the back of the event), it turns on Switch 0099: Player attacks first

In my Scene_map script I have the following for determining Preemptive/Surprise instead of the random number default:



Code:
def preemptive_or_surprise

    if $game_switches[99] = true

      $game_troop.preemptive = true

    elsif $game_switches[100] = true

      $game_troop.surprise = true

    end

  end


The switches turn on properly, but I don't get the appropriate Preemptive or Surprise attack in the battle processing. As I have no real experience with Ruby, I'm sure I'm missing something super simple. What am I missing?

Thanks!
 
I've noticed the issue.
'if $game_switches[XXX] = true' has the problem.

You need to swap the '=' to '==' if you're running a comparison.
I accidentally make this mistake sometimes too xD
 

ooryl2

Member

ZenVirZan":1uqkrygz said:
I've noticed the issue.
'if $game_switches[XXX] = true' has the problem.

You need to swap the '=' to '==' if you're running a comparison.
I accidentally make this mistake sometimes too xD

Thank you for noticing that! It solves half of my problem. The switches for preemptive/surprise now work.

However, it will only work in random battles. It does not work in Battle Processing initiated by an event. That Battle Processing command seems to ignore the preemptive/surprise status.
 

ooryl2

Member

I found a bit of a work around, but I doubt it's the optimal path.

I edited the Troop Battle Event to add two pages, one for each of the above switches. If the Enemy attack first switch is on, I added the following:

Code:
 

@>Script: $game_troop.surprise = true

@>Script: text = sprintf(Vocab::Surprise,

             : $game_party.name)

             : $game_message.texts.push(text)


and the corresponding one for Preemptive. This does create the appropriate preemptive/surprise in the battle. One issue though is that in the random encounters the text that pops up says

"Slime emerged!
Ralph's party was surprised!"

all in the same window.

With the above in the Troop Battle Event pages, the Event Battle Processing says that Slime emerged in one window and then that the party was surprised in the next window.

There must be a better way of doing this than adding in the above Troop Battle Event pages for every single troop the game will have.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top