Save-Point
KRandomTeleport XP - 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 XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: KRandomTeleport XP (/thread-8330.html)



KRandomTeleport XP - kyonides - 08-03-2021

KRandomTeleport XP

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 XP
#   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
    $game_temp.player_transferring = true
    $game_temp.player_new_x = rand(max_x + 1 - min_x) + min_x
    $game_temp.player_new_y = rand(max_y + 1 - min_y) + min_y
    $game_temp.player_new_map_id = map_id
  end

  def undo_random_transfer
    return unless @tp_x
    $game_temp.player_transferring = true
    $game_temp.player_new_x = @tp_x
    $game_temp.player_new_y = @tp_y
    $game_temp.player_new_map_id = @tp_map_id
    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


RE: KRandomTeleport - kyonides - 08-24-2021

Maintenance Update

I had to edit the script above to get rid of a minor bug that went unnoticed till a few minutes ago. Laughing + Tongue sticking out


RE: KRandomTeleport - kyonides - 11-14-2022

Some VX and ACE Bump

From now on you can also get a script that will smoothly run in RMVX and RMVX ACE.
I also noticed that there was a method name that needed to be fixed in RMXP so Oops! I have updated it as well.