KRandomTeleport - kyonides - 08-03-2021
KRandomTeleport
XP + VX + ACE
by Kyonides Arkanthes
Introduction
Did you ever feel like you wanted your character to randomly teleport to another location?
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!
Don't worry! You might only need one or two script calls at any given time.
XP 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
VX & ACE 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.
I just can't bear those guys.
Include me in your game credits!
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.
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 I have updated it as well.
|