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.

Follow Event script request

Hi :D
Im looking for a script that makes the player or an event make this simple things:
- Move toward/away from an Event.
- Turn toward/away from an Event.

if someone knows of a script that makes this things tell me pls

~Thx!
 
I have it... tough i made some modifications so it could be not right as before...

Code:
#==============================================================================
# Event dependent Movement Script v. 1.03
# by Caldaron (8.10.2006)
#==============================================================================
SDK.log('Event dependent Movement', 'Caldaron', 1.03, '2006-10-8')

if SDK.state('Event dependent Movement')
#==============================================================================
Eight_Way = false
#==============================================================================
class Game_Character
  #--------------------------------------------------------------------------
  def move_toward_event(id)
    turn_toward_event(id)
    move_forward
    if not moving?
      move_random
    end
  end
  #--------------------------------------------------------------------------
  def move_away_from_event(id)
    turn_away_from_event(id)
    move_forward
    if not moving?
      move_random
    end
  end
  #--------------------------------------------------------------------------
  def turn_toward_event(id)
    sx = @x - $game_map.events[id].x
    sy = @y - $game_map.events[id].y
    if sx == 0 and sy == 0
      return
    end
    if sx.abs == sy.abs and Eight_Way
      sx > 0 ? sy > 0 ? turn_upper_left : turn_lower_left : sy > 0 ? turn_upper_right : turn_lower_right
    elsif sx.abs > sy.abs
      sx > 0 ? turn_left : turn_right
    else
      sy > 0 ? turn_up : turn_down
    end
  end
  #--------------------------------------------------------------------------
  def turn_away_from_event(id)
    sx = $game_map.events[id].x - @x
    sy = $game_map.events[id].y - @y
    if sx == 0 and sy == 0
      return
    end
    if sx.abs == sy.abs and Eight_Way
      sx > 0 ? sy > 0 ? turn_upper_left : turn_lower_left : sy > 0 ? turn_upper_right : turn_lower_right
    elsif sx.abs > sy.abs
      sx > 0 ? turn_left : turn_right
    else
      sy > 0 ? turn_up : turn_down
    end
  end
  #--------------------------------------------------------------------------
  def turn_upper_left
    unless @direction_fix
      @direction = 4 #era 4
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  def turn_lower_left
    unless @direction_fix
      @direction = 4 # era 4
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  def turn_upper_right
    unless @direction_fix
      @direction =6 # era 6
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  def turn_lower_right
    unless @direction_fix
      @direction = 6 # era 6
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  def move_forward
    case @direction
    when 1
      move_left (false) #era lower_left
    when 2
      move_down(false)
    when 3
      move_down (false) #era lower_right
    when 4
      move_left(false)
    when 6
      move_right(false)
    when 7
      move_up(false) #era upper left
    when 8
      move_up(false)
    when 9
      move_right(false) #era upper_right
    end
  end
  #--------------------------------------------------------------------------
  def move_random
    case rand(8)
    when 0
      move_down(false) #era lower_left
    when 1
      move_down(false)
    when 2
      move_right(false) #era lower_right
    when 3
      move_left(false)
    when 4
      move_right(false)
    when 5
      move_left(false) #era upper left
    when 6
      move_up(false)
    when 7
      move_up(false) #era upper_right
    end
  end
  #--------------------------------------------------------------------------
end
#==============================================================================
end

You can see inside it the functions... you just have to write in the move event funtciont the call script "move_toward_event(id)" and the other similar ones.
 

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