11-17-2015, 11:40 AM
(This post was last modified: 01-24-2019, 08:05 AM by kyonides.
Edit Reason: Updated Terms!
)
RandomEnkounters XP
by Kyonides-Arkanthes
Introduction
This scriptlet adds a very simple but curious feature to your game mechanics, it shows one of the semi-randomly generated monsters that could emerge out of the blue every other hero's step. Once this happens the hero can't do much about it but turn around in desperation possibly. Later on the player would listen to some "I'm here" or "Come and get me" or any similar (customizable) sound effect just a few moments before the battle starts.
After a short discussion about my script I added a new feature that allows the game dev to set a custom animation when the enemy trooper shows up. (I haven't tested it yet, though.) Let's say DerV convinced me to add it. Honestly I think I'm kind of spoiling forum members or visitors lately by adding more and more features to scripts. I hope interested people really appreciate it.
SCRIPT
Code:
# * RandomEnkounter XP
# Plug & Play Script & Configurable
# Scripter : Kyonides-Arkanthes
# 2019-01-20
module RandomEnkounter
ENEMY_APPEARS = '018-Teleport01'
WAIT_COUNT = Graphics.frame_rate * 3
ANIME_POPUP = {} # Do Not Edit This Line
# Animation on Enemy Trooper on Map [Troop ID] = Animation ID
ANIME_POPUP.default = 0
ANIME_POPUP[1] = 14
ANIME_POPUP[2] = 20
MESSAGE = {} # Do Not Edit This Line
# Options: "Any text" or nil if you don't want to show any message if that
# Troop ID is randomly picked by the system. Include \n for line breaks to
# be displayed on the dialogue window.
MESSAGE.default = "Default Message"
MESSAGE[1] = "Enjoy the cold embrace of death!"
MESSAGE[2] = "Halt right there, you pathetic fools!"
def self.enemy() @enemy end
def self.enemy=(new_enemy) @enemy = new_enemy end
def self.enemy_appears() RPG::AudioFile.new(ENEMY_APPEARS,100,350) end
end
class Game_RandomEnemy < Game_Enemy
attr_reader :character_name, :character_hue, :tile_id, :pattern, :direction
attr_reader :opacity, :blend_type, :x, :y, :through, :step_anime
attr_accessor :transparent
def refresh
@character_name = @battler_name
@character_hue = @battler_hue
dir = $game_player.direction
@x = $game_player.x + (dir == 6 ? 1 : dir == 4 ? -1 : 0)
@y = $game_player.y + (dir == 2 ? 1 : dir == 8 ? -1 : 0)
@direction = 10 - dir
valid_coord = $game_map.valid?(@x, @y)
result = false
if valid_coord
$game_map.events.values.each {|event| through = event.through
(result = true; break) if event.x == @x and event.y == @y and !through }
end
if !valid_coord or result
@x = $game_player.x + (dir == 6 ? -1 : dir == 4 ? 1 : 0)
@y = $game_player.y + (dir == 2 ? -1 : dir == 8 ? 1 : 0)
@direction = dir
end
@real_x = @x * 128
@real_y = @y * 128
@opacity = 255
@blend_type = 0
@tile_id = 0
@pattern = 0
@anime_count = 0
@stop_count = 0
@through = false
@transparent = false
@move_speed = 4
@move_frequency = 6
@step_anime = true
@animation_id = RandomEnkounter::ANIME_POPUP[@troop_id]
end
def screen_x() (@real_x - $game_map.display_x + 3) / 4 + 16 end
def screen_y() (@real_y - $game_map.display_y + 3) / 4 + 32 end
def screen_z(height = 0)
return 999 if @always_on_top
z = (@real_y - $game_map.display_y + 3) / 4 + 32
return z + ((height > 32) ? 31 : 0) # If height exceeds 32, then add 31
end
def bush_depth
return 0 if @tile_id > 0 or @always_on_top
(@jump_count == 0 and $game_map.bush?(@x, @y))? 12 : 0
end
def update
@anime_count += 1# if @step_anime
if @anime_count > 18 - @move_speed * 2
if !@step_anime and @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % 4
end
@anime_count = 0
end#@stop_count += 1
end
end
class Game_Player
alias kyon_enkounters_gm_player_up update
attr_writer :halt
def update
return if @halt
kyon_enkounters_gm_player_up
end
end
class Game_Map
alias kyon_enkounters_gm_map_setup setup
alias kyon_enkounters_gm_map_passable? passable?
def setup(map_id)
kyon_enkounters_gm_map_setup(map_id)
RandomEnkounter.enemy = nil
end
def passable?(x, y, d, self_event=nil)
enemy = RandomEnkounter.enemy
return false if enemy != nil and !enemy.through
kyon_enkounters_gm_map_passable?(x, y, d, self_event)
end
end
class Sprite_RandomCharacter < Sprite_Character
def update
return if @character == nil
super
end
end
class Spriteset_Map
alias kyon_enkounters_sprite_map_init initialize
alias kyon_enkounters_sprite_map_up update
alias kyon_enkounters_sprite_map_dispose dispose
def initialize
character = Game_Character.new
character.transparent = true
@random_sprite = Sprite_RandomCharacter.new(nil, character)
kyon_enkounters_sprite_map_init
@random_sprite = Sprite_RandomCharacter.new(@viewport1, character)
end
def random_enemy=(new_enemy)
new_enemy.transparent = false
@random_sprite.character = new_enemy
end
def update
kyon_enkounters_sprite_map_up
@random_sprite.update
end
def dispose
kyon_enkounters_sprite_map_dispose
@random_sprite.dispose
end
end
class Scene_Map
@@wait_count = 0
alias kyon_enkounters_scn_map_up update
alias kyon_enkounters_scn_map_call_battle call_battle
def call_battle
$game_temp.battle_calling = false
if $game_player.encounter_count == 0 and $game_map.encounter_list.size > 0
@wait_for_battle = true
$game_system.se_play(RandomEnkounter.enemy_appears)
$game_player.halt = true
$game_player.straighten
tid = $game_temp.battle_troop_id
enemies_size = $data_troops[tid].members.size
enemy = Game_RandomEnemy.new(tid, rand(enemies_size))
RandomEnkounter.enemy = enemy
RandomEnkounter.enemy.refresh
@spriteset.random_enemy = enemy
@spriteset.update
if (message = RandomEnkounter::MESSAGE[tid])
$game_temp.message_text = message.dup
@last_message_position = $game_system.message_position
$game_system.message_position = $game_player.screen_y > 320 ? 0 : 2
end
@@wait_count = RandomEnkounter::WAIT_COUNT
end
end
def update
if @wait_for_battle
RandomEnkounter.enemy.update
@spriteset.update
@message_window.update
@@wait_count -= 1
return if @@wait_count > 0
@wait_for_battle = nil
$game_system.message_position = @last_message_position
return kyon_enkounters_scn_map_call_battle
end
kyon_enkounters_scn_map_up
end
end
class Scene_Battle
alias kyon_enkounters_scn_battle_battle_end battle_end
def battle_end(result)
$game_player.halt = false
RandomEnkounter.enemy = nil
kyon_enkounters_scn_battle_battle_end(result)
end
end
Credits
To me, Kyonides-Arkanthes, your dark scripter.

Terms of Use
It's free for use in any kind of game, but I will request a small payment from you if you include it in a commercial game. Just don't forget to add me to your credits list.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX