Save-Point
KRandomTeleport VX + ACE - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker VX/VXAce (RGSS2/3) Engines (https://www.save-point.org/forum-117.html)
+---- Thread: KRandomTeleport VX + ACE (/thread-9480.html)



KRandomTeleport VX + ACE - kyonides - 09-19-2024

KRandomTeleport VX + ACE

by Kyonides

Introduction

Thinking Did you ever feel like you wanted your character to randomly teleport to another location?
Feeling sick Are you sick of manually setting up such an event at every single open space in a given area?
Well, now you can just use some useful script calls to let it handle the teleportation for you! Shocked
Winking Don't worry! You might only need one or two script calls at any given time.

The  Script

Code:
# * KRandomTeleport VX & ACE
#  Scripter : Kyonides Arkanthes
#  v0.2.0 - 2022-11-13
#  v0.1.0 - 2021-08-22

# This scriptlet allows you to transfer a player to a random location on a given
# map. The condition is that you need to define a rectangular area first.
# You would no longer need to setup several event commands in a row there.

# * Script Calls * #
# - Send to Same Map -
# $game_player.random_transfer(MIN_X, MAX_X, MIN_Y, MAX_Y)
# - Send to Another Map -
# $game_player.random_transfer(MIN_X, MAX_X, MIN_Y, MAX_Y, MAPID)
# - Undo Random Transfer (Clears Transfer Data)
# $game_player.undo_random_transfer
# - Clear Random Transfer Data Manually!
# $game_player.clear_pre_teleport_coords

class Game_Player
  def clear_pre_teleport_coords
    @tp_x = nil
    @tp_y = nil
    @tp_map_id = nil
  end

  def save_last_xy_map
    @tp_x = @x
    @tp_y = @y
    @tp_map_id = $game_map.map_id
  end

  def random_transfer(min_x, max_x, min_y, max_y, map_id=$game_map.map_id)
    save_last_xy_map
    new_x = rand(max_x + 1 - min_x) + min_x
    new_y = rand(max_y + 1 - min_y) + min_y
    reserve_transfer(map_id, new_x, new_y, @direction)
  end

  def undo_random_transfer
    return unless @tp_x
    reserve_transfer(@tp_map_id, @tp_x, @tp_y, @direction)
    clear_pre_teleport_coords
  end
end

Terms & Conditions

You can freely use this script, even if you are called Silly or Joe Biden, a werewolf or even Count Dracula.
Nope, Jack Dorsey, Miguel Díaz-Canel, Xi Jinping and Kim Jong-un are not allowed to even take a look at it. Laughing + Tongue sticking out 
I just can't bear those guys. Laughing
Include me in your game credits! Winking