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.

Maplink Script - turning off maplink until switch/variable

EDIT: Actually, i believe i posted this in the wrong forum :S

Hey guys. I am using the maplink script by Wachunga, and I have been trying to make it so the maplink won't allow the player to move to the designated map until a switch or variable (whichever I use) has been set.

I have tried making it so the event only appears when a certain switch has been turned on, but that only gives me a syntax error in the maplink script.

I have also tried using conditional branches, however the maplink script doesn't see the conditional branch and still allows the player to go through.

Do you guys know of any way to help me with my problem?

I appreciate anyone's help =)

Wachunga's Maplink Script:
Code:
#==============================================================================

# ■ Maplinks

#------------------------------------------------------------------------------

# This is the script for Maplinks.

#==============================================================================

<span style="color:#000080; font-style:italic;">=begin

<span style="color:#000080; font-style:italic;">============

<span style="color:#000080; font-style:italic;">Maplinks - version 0.95 (2005-11-10)

<span style="color:#000080; font-style:italic;">============

<span style="color:#000080; font-style:italic;">by Wachunga

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">This script simplifies linking maps together: a single event sets up an

<span style="color:#000080; font-style:italic;">entire edge of the map as a teleport to another map. Players trying to

<span style="color:#000080; font-style:italic;">leave that edge of the current map are automatically teleported.

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">(This can also be achieved with many copies of teleport events along the edges

<span style="color:#000080; font-style:italic;">of a map or with a parallel-process event that sets variables and uses them to

<span style="color:#000080; font-style:italic;">teleport, but these methods are not optimal -- causing lag and/or inconvenience

<span style="color:#000080; font-style:italic;">for the mapper.)

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">To link a map with another on a specific edge (north, east, south or west),

<span style="color:#000080; font-style:italic;">create an event with <maplink> included in its name on the appropriate edge of

<span style="color:#000080; font-style:italic;">the map. (To avoid confusion, maplink events on corners of the map are

<span style="color:#000080; font-style:italic;">not valid.) Then, add a teleport ("Transfer Player") command to the event

<span style="color:#000080; font-style:italic;">to specify the destination map and other details (e.g. player direction,

<span style="color:#000080; font-style:italic;">fading on/off). If the destination is an east or west edge, then the Y

<span style="color:#000080; font-style:italic;">coordinate is calculated based on the player's Y coordinate when

<span style="color:#000080; font-style:italic;">teleporting; likewise, the X coordinate is calculated automatically when

<span style="color:#000080; font-style:italic;">the destination is a north or south edge.

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">Note: unlike normal teleport events, maplinks are activated when the player

<span style="color:#000080; font-style:italic;">tries to leave the screen instead of when stepping on the last tile. This

<span style="color:#000080; font-style:italic;">behaviour could be changed, but I feel that it's more natural this way:

<span style="color:#000080; font-style:italic;">it leaves the whole map open for actual exploration, instead of "wasting"

<span style="color:#000080; font-style:italic;">the outer tiles of a map.

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">=end

 

#-------------------------------------------------------------------------------

 

class Game_Event < Game_Character

alias ml_ge_init initialize

def initialize(map_id, event)

ml_ge_init(map_id, event)

if @event.name.upcase.include?('<MAPLINK>')

dir = nil

if @event.y == $game_map.height-1

dir = 2 unless @event.x == 0 or @event.x == $game_map.width-1

elsif @event.x == 0

dir = 4 unless @event.y == 0 or @event.y == $game_map.height-1

elsif @event.x == $game_map.width-1

dir = 6 unless @event.y == 0 or @event.y == $game_map.height-1

elsif @event.y == 0

dir = 8 unless @event.x == 0 or @event.x == $game_map.width-1

end

if dir != nil

@list.each { |command|

if command.code == 201

# make sure new location isn't be specified by variables

if command.parameters[0] == 0

$game_map.maplinks[dir] = Maplink.new(command.parameters)

break

end

end

}

end

end

end

end

 

#-------------------------------------------------------------------------------

 

class Game_Map

attr_accessor :maplinks

 

alias ml_gm_setup setup

def setup(map_id)

@maplinks = {}

ml_gm_setup(map_id)

end

 

def width(map_id = @map_id)

if map_id == @map_id

return @map.width

else

return load_data(sprintf("Data/Map%03d.rxdata", map_id)).width

end

end

 

def height(map_id = @map_id)

if map_id == @map_id

return @map.height

else

return load_data(sprintf("Data/Map%03d.rxdata", map_id)).height

end

end

 

end

 

#-------------------------------------------------------------------------------

 

class Maplink

 

def initialize(parameters)

@param = parameters

end

 

def activate

width = $game_map.width(@param[1])

height = $game_map.height(@param[1])

# modify x (p[2]) or y (p[3]) coordinates appropriately

if @param[2] == 0 or @param[2] == width-1

@param[3] = $game_player.y

elsif @param[3] == 0 or @param[3] == height-1

@param[2] = $game_player.x

end

# set up a dummy interpreter just for teleport

interpreter = Interpreter.new

interpreter.parameters = @param

interpreter.index = 0

interpreter.command_201

end

 

end

 

#-------------------------------------------------------------------------------

 

class Game_Player

 

alias ml_cett check_event_trigger_touch

def check_event_trigger_touch(x, y)

check_maplinks(x,y)

ml_cett(x,y)

end

 

def check_maplinks(x,y)

if $game_map.valid?(x, y) then return end

dir = nil

if y == $game_map.height then dir = 2

elsif x == -1 then dir = 4

elsif x == $game_map.width then dir = 6

elsif y == -1 then dir = 8

end

if dir != nil

if $game_map.maplinks[dir] != nil

$game_map.maplinks[dir].activate

end

end

end

 

end

 

#-------------------------------------------------------------------------------

 

class Interpreter

attr_accessor :parameters

attr_accessor :index

end
 

Baffou

Member

Hello Sir Ver, i have the same problem, i'm using Maplink script vers.0.95, and i want to activate a switch directly in the event, but the event doesn't recognize,
if a switch, variable, conditionnal branch is actived, i'm afraid the only solution is to contact wachunga or someone who can modifie the script.
(sorry for my bad english) -baffou-
 
@Baffou

Hey thanks for taking the time to reply mate. Yeah I slowly came to that conclusion. For now I've done away with it until such a time comes where I can edit it myself, or someone sees this and edits it. But, until then, it's kind of useless to me
 

Baffou

Member

Regi, i have tested with conditional branch, i don' t see any syntax error, the problem is, in the Maplink event, i want to execute some command like:
activate a switch, a step forward or a variable before the transfer player, but the script execute directly the teleportation without taking into account
the other commands. I don't know the rgss language, i will be glad if someone can fix it.
 
@regi
"Script 'Map Links' Line 57:NoMethodError
undefined method 'each' for nil:NilClass"

That is the error i get when i start a new game, but only if a maplink has a condition switch to turn the event on.
I hope that helps
 
@Sir Ver, try changing line 45 to:
if @event.name.upcase.include?('<MAPLINK>') and @page != nil


@Baffou: try switching the order of lines 132-133, so ml_cett(x,y) is above check_maplinks(x,y). This may cause problems with the trigger, though, I haven't tested it out.

Let me know if problems persist!
 

Baffou

Member

Thanks regi for the quick answer.
I have switched the orders of the lines, but nothing have changed.
my teleports events are like this :
==================================
conditional branch : player is facing right
set move route : player
:$Turn right
control switches :[23 :door] = OFF
Transfer Player :[014 :Shop],(000,001)
=================================
It recognize only the transfer player. I really need to execute the commands before the map transfer.
 
It seems like the new method (check_maplinks) overrides the event and just skips directly to the teleport event. Unfortunately, I know of no way to prevent this except for rewriting part of the script in a different section (Interpreter, def command_201). If no one else can find an easy fix I'll come back later when I have more time and give it a shot.
 

Baffou

Member

Thanks you regi for all the help !
i will continue to use this script because i have done 324 Maps,
all use the maplinks script and it's a good script.
I will continue my game normally,
and hope you will be able to fix it.
Thanks again.
 
After further perusal, I've found that the script creates its own object (maplinks) and uses that to run the player transfer, apart from the actual event. This is why putting commands in the event will be useless. Unfortunately I don't know any efficient ways to fix this, but I have come up with an alternative solution: you could put the commands in the new map (014: Shop) in a Parallel Process that runs once and erases (or goes to a new page). Sorry if it's not what you wanted, but I'm afraid that's the best I can do.
 

Baffou

Member

@Regi,
for the parallel process event, that was i have done for some map,
but the parallel process begin once you have entered the map, that why
is a problem, the command must be actived before the teleporting transition
like the door switch[23], maybe if you know a way in the script itself,
mabe something like an array: (idea based on Ambient SFX script, Author: ForeverZer0)
========================================================
when 26, 27, 3, 12, 6, 8, 19, 10 #Map ID
[23, 40, 50] #Switch ID to activate before entering the map
=======================================================
-Thanks-
 

Baffou

Member

Sorry for double posting,
like i said earlier i don't know RGSS language, but all that things make me want to learn the language,
i that case i can make modification on my own.
Regi , do you know some good tutorials to learn RGSS ?
Also, i would like to apologize for my bad english cause i'm French.
-Thanks-
 
Not the cleanest method, but try it out:
Code:
#==============================================================================

# ■ Maplinks

#------------------------------------------------------------------------------

# This is the script for Maplinks.

#==============================================================================

<span style="color:#000080; font-style:italic;">=begin

<span style="color:#000080; font-style:italic;">============

<span style="color:#000080; font-style:italic;">Maplinks - version 0.95 (2005-11-10)

<span style="color:#000080; font-style:italic;">============

<span style="color:#000080; font-style:italic;">by Wachunga

 

<span style="color:#000080; font-style:italic;">This script simplifies linking maps together: a single event sets up an

<span style="color:#000080; font-style:italic;">entire edge of the map as a teleport to another map. Players trying to

<span style="color:#000080; font-style:italic;">leave that edge of the current map are automatically teleported.

 

<span style="color:#000080; font-style:italic;">(This can also be achieved with many copies of teleport events along the edges

<span style="color:#000080; font-style:italic;">of a map or with a parallel-process event that sets variables and uses them to

<span style="color:#000080; font-style:italic;">teleport, but these methods are not optimal -- causing lag and/or inconvenience

<span style="color:#000080; font-style:italic;">for the mapper.)

 

<span style="color:#000080; font-style:italic;">To link a map with another on a specific edge (north, east, south or west),

<span style="color:#000080; font-style:italic;">create an event with <maplink> included in its name on the appropriate edge of

<span style="color:#000080; font-style:italic;">the map. (To avoid confusion, maplink events on corners of the map are

<span style="color:#000080; font-style:italic;">not valid.) Then, add a teleport ("Transfer Player") command to the event

<span style="color:#000080; font-style:italic;">to specify the destination map and other details (e.g. player direction,

<span style="color:#000080; font-style:italic;">fading on/off). If the destination is an east or west edge, then the Y

<span style="color:#000080; font-style:italic;">coordinate is calculated based on the player's Y coordinate when

<span style="color:#000080; font-style:italic;">teleporting; likewise, the X coordinate is calculated automatically when

<span style="color:#000080; font-style:italic;">the destination is a north or south edge.

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">Note: unlike normal teleport events, maplinks are activated when the player

<span style="color:#000080; font-style:italic;">tries to leave the screen instead of when stepping on the last tile. This

<span style="color:#000080; font-style:italic;">behaviour could be changed, but I feel that it's more natural this way:

<span style="color:#000080; font-style:italic;">it leaves the whole map open for actual exploration, instead of "wasting"

<span style="color:#000080; font-style:italic;">the outer tiles of a map.

 

<span style="color:#000080; font-style:italic;">=end

 

#-------------------------------------------------------------------------------

 

class Game_Event < Game_Character

  alias ml_ge_init initialize

  def initialize(map_id, event)

    ml_ge_init(map_id, event)

    if @event.name.upcase.include?('<MAPLINK>') and @page != nil

      dir = nil

      if @event.y == $game_map.height-1

        dir = 2 unless @event.x == 0 or @event.x == $game_map.width-1

      elsif @event.x == 0

        dir = 4 unless @event.y == 0 or @event.y == $game_map.height-1

      elsif @event.x == $game_map.width-1

        dir = 6 unless @event.y == 0 or @event.y == $game_map.height-1

      elsif @event.y == 0

        dir = 8 unless @event.x == 0 or @event.x == $game_map.width-1

      end

      if dir != nil

        @list.each { |command|

        if command.code == 201

          # make sure new location isn't be specified by variables

          if command.parameters[0] == 0

            $game_map.maplinks[dir] = Maplink.new(command.parameters)

            break

          end

        end

        }

      end

    end

  end

end

 

#-------------------------------------------------------------------------------

 

class Game_Map

  attr_accessor :maplinks

  

  def get_map_switches(map_id)

    return case map_id

    #-------------------------------------------------------------------------

    # BEGIN CONFIGURATION

    #-------------------------------------------------------------------------

    when 1, 3, 5 # new map IDs

      [2, 4]     # turn on switches 2 and 4

    when 2

      [3]

    #-------------------------------------------------------------------------

    # END CONFIGURATION

    #-------------------------------------------------------------------------

    end

  end

  

  alias ml_gm_setup setup

  def setup(map_id)

    @maplinks = {}

    ml_gm_setup(map_id)

  end

  

  def width(map_id = @map_id)

    if map_id == @map_id

      return @map.width

    else

      return load_data(sprintf("Data/Map%03d.rxdata", map_id)).width

    end

  end

  

  def height(map_id = @map_id)

    if map_id == @map_id

      return @map.height

    else

      return load_data(sprintf("Data/Map%03d.rxdata", map_id)).height

    end

  end

  

end

 

#-------------------------------------------------------------------------------

 

class Maplink

  

  def initialize(parameters)

    @param = parameters

  end

  

  def activate

    width = $game_map.width(@param[1])

    height = $game_map.height(@param[1])

    # modify x (p[2]) or y (p[3]) coordinates appropriately

    if @param[2] == 0 or @param[2] == width-1

      @param[3] = $game_player.y

    elsif @param[3] == 0 or @param[3] == height-1

      @param[2] = $game_player.x

    end

    # set switches

    ids = $game_map.get_map_switches(@param[1])

    unless ids == nil

      ids.each { |i| $game_map.switches[i] = true }

    end

    # set up a dummy interpreter just for teleport

    interpreter = Interpreter.new

    interpreter.parameters = @param

    interpreter.index = 0

    interpreter.command_201

  end

  

end

 

#-------------------------------------------------------------------------------

 

class Game_Player

  

  alias ml_cett check_event_trigger_touch

  def check_event_trigger_touch(x, y)

    check_maplinks(x,y)

    ml_cett(x,y)

  end

  

  def check_maplinks(x,y)

    return if $game_map.valid?(x, y)

    dir = nil

    if y == $game_map.height then dir = 2

    elsif x == -1 then dir = 4

    elsif x == $game_map.width then dir = 6

    elsif y == -1 then dir = 8

    end

    if dir != nil

      if $game_map.maplinks[dir] != nil

        $game_map.maplinks[dir].activate

      end

    end

  end

  

end

 

#-------------------------------------------------------------------------------

 

class Interpreter

  attr_accessor :parameters

  attr_accessor :index

end
To configure maps and switches, go to line 81. The first line (when #) is for new map IDs; in the array [#] specify the switch IDs you want to turn on. Haven't tested it, but hope it works out!
 
Oops, sorry, that was for Baffou's request. Sir Ver, check a few posts up for my tentative fix and let me know if it works!



@Baffou: An example: if you want to turn on switch #24 before you transfer to map #5, you would use:

when 5
[24]


If you want to read up on some RGSS tutorials, try the links here. And no worries about your English, you're quite understandable.
 
@regi
Oh right, I forgot about that fix, I'm sorry. I've been all over the RPG making place :down:
I'll check it out now

EDIT: Ok, It works and doesn't let the player transfer until the switch is on.. But it completely takes away what maplink does, it turns into a regular teleport event, and only for where the event is, not all along that side of the map
 

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