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.

Aggro Script?

Status
Not open for further replies.

kujo

Member

Hi there!

New poster, here. But not totally new to RMXP. ;)
(Let me first say this site is AWSOME!! And everyone should keep up the stellar work) :D

Anyhow, to the question at hand:
Does anyone know of a script that can change a sprite's movement on the map; mimicking 'aggro' toward a player on that map, in relation to the player's distance between his/herself and the mob?

Ok...that sentence might be a tad strange to chew on.
Basically what I'm looking for is:

- The player enters the map...there are sprites walking around (Movement set to random)
- If the player gets too close to a sprite, that sprite will try to move toward the player until it touches and BOOM! Combat screen pops up.

I like the style of having battle screens. I know most (if not all) 'Zelda'-style ATBs can allow for the sort of reaction from sprites that I'm looking for. However, they all employ battle done on the map. Which I do not want.

I've been all through the downloads section, and even the Lost Scripts thingie, but have had no luck finding something. ':|

I am, admittedly, a total noob at scripting. Otherwise I would have attempted it myself. So I'm hoping theres someone here that might be able to point me in the right direction.

Thanks in advance. Any help is appreciated! :D
 

Rare

Member

This might work:
Code:
#==============================================================================
#   View Range Script
#------------------------------------------------------------------------------
#    By: Near Fantastica
#    Date: 07/04/05
#==============================================================================

class View_Range
 #--------------------------------------------------------------------------
 # ? Range system works by sereching the area of a circle for the Player's xy
 #    The Veiw is set in each event and is the radius of the circle
 #    The Eaquation used is (Px-EX)^2 + (Py-Ey)^2 = radius^2
 #    If the Radius is less than or equal to the View the Player is inside the circle
 #--------------------------------------------------------------------------
 def initialize
   @playing_bgs = []
   @bgs = BGS.new
   @bgs.pitch = 100
   @event_id = 0
   @event_locial_switch = ""
   @view_range = 0
   @playerx = 0
   @playery = 0
   @eventx = 0
   @eventy = 0
   @event_direction = 0
 end
 #--------------------------------------------------------------------------
 #     Max Sound Effect Range is 8 units DO NOT OVER LAP
 #     or it will go into super lag mode you have been warned
 #     This is because you are trying to play 2 different sound
 #     effects and will cycles between them
 #
 #     Note : This overrides the maps default sound effect
 #--------------------------------------------------------------------------
 def event_sound(event_id, bgs_name)
   @bgs.name = bgs_name
   @event_id = event_id
   @playerx = $game_player.x
   @playery = $game_player.y
   @eventx = $game_map.events[@event_id].x
   @eventy = $game_map.events[@event_id].y
   @event_direction = $game_map.events[@event_id].direction
   radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
   if radius > 64
     if @playing_bgs[event_id] != nil
       @playing_bgs[event_id] = nil
       $game_system.bgs_fade(1)
       return
     end
   elsif radius <= 64 and radius > 49
     if @playing_bgs[event_id] == nil
       @bgs.volume = 30
       @playing_bgs[event_id] = @bgs
       $game_system.bgs_play(@bgs)
       return
     end
     @bgs.volume = 30
     if @bgs.volume != @playing_bgs[event_id].volume or
         @bgs.name != @playing_bgs[event_id].name
       @playing_bgs[event_id] = @bgs
       $game_system.bgs_play(@bgs)
       return
     end
   elsif radius <= 49 and radius > 36
     @bgs.volume = 40
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 36 and radius > 25
     @bgs.volume = 50
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 25 and radius > 16
     @bgs.volume = 60
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 16 and radius > 9
     @bgs.volume = 70
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 9 and radius > 4
     @bgs.volume = 80
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 4 and radius > 1
     @bgs.volume = 90
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius = 1
     @bgs.volume = 100
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   end
 end
 #--------------------------------------------------------------------------
 def enemies_view(event_id, view_range, els)
   @event_id = event_id
   @view_range = view_range
   @event_locial_switch = els
   @playerx = $game_player.x
   @playery = $game_player.y
   @eventx = $game_map.events[@event_id].x
   @eventy = $game_map.events[@event_id].y
   @event_direction = $game_map.events[@event_id].direction
   if @event_direction == 2
     if @playery >= @eventy
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true
       end
     end
   end
   if @event_direction == 4
     if @playerx <= @eventx
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true
       end
     end
   end
   if @event_direction == 6
     if @playerx >= @eventx
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true
       end
     end
   end
   if @event_direction == 8
     if @playery <= @eventy
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true
       end
     end
   end
 end
end
#======================================================
class Scene_Title
 #--------------------------------------------------------------------------
 alias vr_scene_title_update update
 #--------------------------------------------------------------------------
def update
  $view_range = View_Range.new
  vr_scene_title_update
end
end
#======================================================
class Game_System
   attr_accessor :playing_bgs
end
#======================================================
class BGS
 #--------------------------------------------------------------------------
 attr_accessor :name
 attr_accessor :volume
 attr_accessor :pitch
 #--------------------------------------------------------------------------
 def initialize
   @name
   @volume
   @pitch
 end
end
#======================================================
class Game_Map
 #--------------------------------------------------------------------------
 attr_accessor :map
end

Not sure. Also, I posted it since people have a hard time finding it. Don't ask me how to use it, since I'm not the creator of the script.
 

kujo

Member

Thank you Elias!

This was exactly what I had in mind. And now that I know a name for the script, and an author...I've found the same script but with instructions.

Code:
#==============================================================================
#   Veiw Range Script
#    VERSION 2
#    By: Near Fantastica
#    Date: 07/04/05
#==============================================================================
# HOW TO GIVE EVENTS A SIGHT RANGE:
#1. Make an event with 2 pages
#2. Make page 1 a Parallel Process
#3. Make a New page
#4. Make Page 2 have Local Switch "A"
#5. Then Just insert the following into the First page with Call Script
#       $view_range.enemies_view(EVENT ID, VIEW RANGE, "LOCAL SWITCH TO TURN ON")
# EX: $view_range.enemies_view(1, 8, "A")
#==============================================================================
#==============================================================================
# HOW TO GIVE EVENTS A SOUND RADIUS:
#1. Make an event
#2. Make it a Parallel Process
#3. Then Just insert the following into the event with Call Script
#       $view_range.event_sound(EVENT_ID, "BGS_FILENAME.EXTENTION")
# EX: $view_range.event_sound(1, "011-Waterfall01.ogg")
#
# NOTE: BGS File must be in "/Audio/BGS/"
#
#==============================================================================
class View_Range
 #--------------------------------------------------------------------------
 #    Range system works by sereching the area of a circle for the Player's xy
 #    The Veiw is set in each event and is the radius of the circle
 #    The Eaquation used is (Px-EX)^2 + (Py-Ey)^2 = radius^2
 #    If the Radius is less than or equal to the View the Player is inside the circle
 #--------------------------------------------------------------------------
 def initialize
   @playing_bgs = []
   @bgs = BGS.new
   @bgs.pitch = 100
   @event_id = 0
   @event_locial_switch = ""
   @view_range = 0
   @playerx = 0
   @playery = 0
   @eventx = 0
   @eventy = 0
   @event_direction = 0
 end
 #--------------------------------------------------------------------------
 #     Max Sound Effect Range is 8 units DO NOT OVER LAP 
 #     or it will go into super lag mode you have been warned
 #     This is because you are trying to play 2 different sound 
 #     effects and will cycles between them
 #
 #     Note : This overrides the maps default sound effect
 #--------------------------------------------------------------------------
 def event_sound(event_id, bgs_name)
   @bgs.name = bgs_name
   @event_id = event_id
   @playerx = $game_player.x
   @playery = $game_player.y
   @eventx = $game_map.events[@event_id].x
   @eventy = $game_map.events[@event_id].y
   @event_direction = $game_map.events[@event_id].direction
   radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
   if radius > 64
     if @playing_bgs[event_id] != nil
       @playing_bgs[event_id] = nil
       $game_system.bgs_fade(1)
       return
     end
   elsif radius <= 64 and radius > 49
     if @playing_bgs[event_id] == nil
       @bgs.volume = 30
       @playing_bgs[event_id] = @bgs
       $game_system.bgs_play(@bgs)
       return
     end
     @bgs.volume = 30
     if @bgs.volume != @playing_bgs[event_id].volume or 
         @bgs.name != @playing_bgs[event_id].name
       @playing_bgs[event_id] = @bgs
       $game_system.bgs_play(@bgs)
       return
     end
   elsif radius <= 49 and radius > 36
     @bgs.volume = 40
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 36 and radius > 25
     @bgs.volume = 50
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 25 and radius > 16
     @bgs.volume = 60
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 16 and radius > 9
     @bgs.volume = 70
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 9 and radius > 4
     @bgs.volume = 80
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius <= 4 and radius > 1
     @bgs.volume = 90
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   elsif radius = 1
     @bgs.volume = 100
     @playing_bgs[event_id] = @bgs
     $game_system.bgs_play(@bgs)
     return
   end
 end
 #--------------------------------------------------------------------------
 def enemies_view(event_id, view_range, els)
   @event_id = event_id
   @view_range = view_range
   @event_locial_switch = els
   @playerx = $game_player.x
   @playery = $game_player.y
   @eventx = $game_map.events[@event_id].x
   @eventy = $game_map.events[@event_id].y
   @event_direction = $game_map.events[@event_id].direction
   if @event_direction == 2
     if @playery >= @eventy
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true 
       end
     end
   end
   if @event_direction == 4
     if @playerx <= @eventx
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true 
       end
     end
   end
   if @event_direction == 6
     if @playerx >= @eventx
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true 
       end
     end
   end
   if @event_direction == 8
     if @playery <= @eventy
       radius = (@playerx-@eventx)*(@playerx-@eventx) + (@playery-@eventy)*(@playery-@eventy)
       if radius <= @view_range
         key=[$game_map.map_id, @event_id, @event_locial_switch]
         $game_self_switches[key] = true
         $game_map.need_refresh = true 
       end
     end
   end
 end
end
#======================================================
class Scene_Title
 #--------------------------------------------------------------------------
 alias vr_scene_title_update update
 #--------------------------------------------------------------------------
def update
  $view_range = View_Range.new
  vr_scene_title_update
end
end
#======================================================
class Game_System
   attr_accessor :playing_bgs
end
#======================================================
class BGS
 #--------------------------------------------------------------------------
 attr_accessor :name
 attr_accessor :volume
 attr_accessor :pitch
 #--------------------------------------------------------------------------
 def initialize
   @name
   @volume
   @pitch
 end
end
#======================================================
class Game_Map
 #--------------------------------------------------------------------------
 attr_accessor :map
end

Thanks again! :D
 
Status
Not open for further replies.

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