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.

Player Sprite Change

How do I do this through RGSS? Thank you.
Fixed. See below for the script if you want it.
Code:
 

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

#  Player-Event Swap, Original By PK8, Edited and adapted to a script by Tempus

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

#  Details:

#       Swaps the players position, sprite and direction with an event

#       (default ID 10)

#       When the player is in control of the event, $player is set to 2.

#       for example, you can check if the player is currently controlling the

#       event by checking against $player. ($player == 2 in a call script 

#       conditional branch)

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

EVENTID = 10

 

class Game_Actor < Game_Battler

  attr_accessor   :character_name

  attr_accessor   :character_hue

end

 

class Game_Event < Game_Character

  attr_accessor   :character_name

  attr_accessor   :character_hue

end

 

class Game_Character

  attr_accessor   :direction

  attr_accessor   :through

end

 

class Scene_Map

  alias tsswap_main main

  def main

    tsswap_main

    if $game_variables[EVENTID] == 0

      $game_variables[EVENTID] = 1

    end

    @tsid = $game_variables[EVENTID]

    @ts_x = $game_player.x

    @ts_y = $game_player.y

    @ts_d = $game_player.direction

    @ts_s = $game_actors[1].character_name

    @ts_sv = $game_map.events[@tsid].character_name

    $player = 1

  end

  alias tsswap_update update

  def update

    tsswap_update

    if $game_variables[EVENTID] == 0

      $game_variables[EVENTID] = 1

    end

    @tsid = $game_variables[EVENTID]

    if Input.trigger?(Input::A)

      unless $game_system.map_interpreter.running?

        @ts_x = $game_player.x

        @ts_y = $game_player.y

        @ts_d = $game_player.direction

        @ts_s = $game_actors[1].character_name

        @ts_sv = $game_map.events[@tsid].character_name

        $game_player.moveto($game_map.events[@tsid].x, $game_map.events[@tsid].y)

        $game_actors[1].character_name = @ts_sv

        $game_player.direction = $game_map.events[@tsid].direction

        $game_map.events[@tsid].moveto(@ts_x, @ts_y)

        $game_map.events[@tsid].character_name = @ts_s

        $game_map.events[@tsid].direction = @ts_d

        if $player == 2

          $player = 1

        else

          $player = 2

        end

        $game_player.refresh

      end

    end

  end

end

 
 

Atoa

Member

You got this error because "character_name" is an "attr_reader"

Add this above main to solve that:
Code:
class Game_Actor < Game_Battler

  attr_accessor   :character_name

  attr_accessor   :character_hue

end

Remember that you still need to update the graphic on map, so you should also add to the "change graphic" script call this code
Code:
$game_player.refresh
 
Ah, thanks. That solved that problem.

I really know little to none about scripting, and I'm trying to learn by looking at other peoples scripts.

I found this Player Event Swap XP demo that swaps the player's X and Y with an events X and Y using common events and Call Scripts.

I tried to convert it into a full script, including sprite swap.
It's not working too well.
Here's what I've got so far. I realize there must be redundant/bad code in there.
Code:
 

class Game_Actor < Game_Battler

  attr_accessor   :character_name

  attr_accessor   :character_hue

end

 

class Scene_Map

  alias tsswap_main main

  def main

    tsswap_main

    if $game_variables[10] == 0

      $game_variables[10] = 1

    end

    @tsid = $game_variables[10]

    @tsswap_tx = $game_player.x

    @tsswap_ty = $game_player.y

    @tsswap_ts = $game_actors[1].character_name

    @tsswap_tsv = $game_map.events[@tsid].character_name

  end

  alias tsswap_update update

  def update

    tsswap_update

    if $game_variables[10] == 0

      $game_variables[10] = 1

    end

    @tsid = $game_variables[10]

    if Input.trigger?(Input::A)

      unless $game_system.map_interpreter.running?

        tsswap_swap

      end

    end

  end

  def tsswap_swap

    $game_player.moveto($game_map.events[@tsid].x, $game_map.events[@tsid].y)

    $game_actors[1].character_name = '@tsswap_tsv'

    $game_map.events[@tsid].moveto(@tsswap_tx, @tsswap_ty)

    $game_map.events[@tsid].character_name = '@tsswap_ts'

    $game_player.refresh

  end

end

 

The error I'm getting right now is
Script 'Game_Character 1' line 232: NoMethodError occurred.

undefined method `' for nil:NilClass

Which points to the moveto section of Game_Character 1

Help is much appreciated.
 

dricc

Member

It means that $game_map.events[@tsid] doesn't exists .

Well , if you want to make scripts , you have to learn how to make debugs . It is very simple : just put some "print" .
 

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