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.

[Resolved] my first script

RelWes

Member

Hi, can you please tell me what's worng with this script?
Code:
 

class Swap_EP

  

 def initialize (msID)

  

     $game_temp.player_new_x = $game_map.events[msID].x

     $game_temp.player_new_y =  $game_map.events[msID].y

     

      $game_map.events[msID].x = $game_player.x

      $game_map.events[msID].y = $game_player.y

      

    

     

 end

 

end

It is supposed to swap between the player's location and some event's loaction.
 
First off you don't need a class for this. You can actually just put the method in Game_Character.

Code:
class Game_Character

  def swap_position(event_id)

    character = event_id == 0 ? $game_player : $game_map.events[event_id]

    return if character == nil || character == self

    x, y = @x, @y

    moveto(character.x, character.y)

    character.moveto(x, y)

  end

end

Try that. To make something switch:
Code:
# Player with event

$game_player.swap_position(event_id)

 

# Event with event

$game_map.events[event_id].swap_position(event_id)

Just replace event_id in either case with the target event(s). Let me know how it works.


Errors with you code:
~ Event/Player (Game_Character objects) do not have access to the .x, .y variables.
~ You need to assign $game_temp..player_transferring must be set to true if you are planning on using the other $game_temp transfer flags.
 
This script is just what I needed, except is it possible to swap the player for an event on a different map?
I need to swap between players without losing position of either player, so I've been trying to make the player invisible, swap the player with a "hold" event, then transfer the player to the other map, then swap the player again with the other map's "hold" event, and then make the player reappear with the player 2 graphic.
Is there a script to swap player with event on another map to simplify this process?
 

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