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.

if [state is inflicted on actor[1] CONDITION

And I keep asking help on these forums(HBGAMES ROCKS :fap: )
=> sorry it's because I'm script-active and I'm learning :p

SO ON TO BUSINESS...
How do you set the condition for:
if [state is inflicted on actor 1]

This is for in scripts NOT FOR EVENTING CONDITIONAL BRANCHES
Thx
 

Atoa

Member

if actor.states.include?(state_id)

Where actor is an Game_Actor. (so it can be $game_party.actors[actor index] or $game_actors[actor id])

E.g.:
$game_party.actors[0].states.include?(2)
"if actor at index 0 states include state ID 2"
 
I don't know if I may post this here or in a new topic, but it's related with the same script so...
I'm making a simple little script which makes the player confused for real.
If you press left the character moves right, up => down, and so on...

problem is... when I press left the player moves left except when I hold left.
Heres my snippet:
class Game_Player
alias_method :confuse_walk_update, :update
def update
confuse_walk_update
last_moving = moving?
unless moving?
case Input.dir4
when 2
move_up
when 4
move_right
when 6
move_left
when 8
move_down
end
end
end
end
 
I don't know if I may post this here or in a new topic, but it's related with the same script so...
I'm making a simple little script which makes the player confused for real.
If you press left the character moves right, up => down, and so on...

problem is... when I press left the player moves left except when I hold left.
Heres my snippet:
class Game_Player
alias_method :confuse_walk_update, :update
def update
confuse_walk_update
last_moving = moving?
unless moving?
case Input.dir4
when 2
move_up
when 4
move_right
when 6
move_left
when 8
move_down
end
end
end
end
 

Atoa

Member

aliasing the game_player update method the way you did won't work since the original part of the code still being processed.

you could do something like this:

Code:
def update

  if $game_party.actors[0].states.include?(Confuse state ID)

   # an "new" update method, exactly like the orginial except by the directions.

  else

   # alias_update

  end

end
 

Atoa

Member

something like that:
Code:
class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  alias old_update_method update

  def update

    if $game_party.actors[0].states.include?(Confuse state ID)

      confused_update

    else

      old_update_method

    end

  end

  #--------------------------------------------------------------------------

  def confused_update

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      case Input.dir4

      when 2

        move_up

      when 4

        move_right

      when 6

        move_left

      when 8

        move_down

      end

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            @encounter_count -= 1 if @encounter_count > 0

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

end

 

as you can see the method "confused_update" are almost identical to the original update method, except by this part:

Code:
 

      case Input.dir4

      when 2

        move_up

      when 4

        move_right

      when 6

        move_left

      when 8

        move_down

      end

    end

 
 
Sorry if I'm just stupid but it gives me an error with "super" meaning no superclass method 'confused_update'. (which I don't get because there IS a superclass...)
Can you help me once more :smile:
 

Atoa

Member

Yeah i forgot about the super, so do this:

Code:
class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  alias old_update_method update

  def update

    if $game_party.actors[0].states.include?(Confuse state ID)

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      case Input.dir4

      when 2

        move_up

      when 4

        move_right

      when 6

        move_left

      when 8

        move_down

      end

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            @encounter_count -= 1 if @encounter_count > 0

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

    else

      old_update_method

    end

  end

end

 
 

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