Jump to content
Sign in to follow this  

Simple 2 Player script development

Recommended Posts

I found a 2-player script written for VX

2-player as in, two people controlling separate characters in the same game.




But I think it can be written much simpler, so I wrote my own.

You should combine 2-player scripts with Full Input so that you actually have a realistic number of keys to work with.




Here's a proof-of-concept. You can see that the actual code itself is like 20 lines, while the other 20 lines is for all that aliasing and stuff.


module DataManager

 class << self
   alias :th_multiplayer_create_game_objects :create_game_objects
   alias :th_multiplayer_make_save_contents :make_save_contents
   alias :th_multiplayer_extract_save_contents :extract_save_contents

 def self.create_game_objects
   $game_player2 = Game_Multiplayer.new


 def self.make_save_contents
   contents = th_multiplayer_make_save_contents
   contents[:player2] = $game_player2

 def self.extract_save_contents(contents)
   $game_player2 = contents[:player2]

 def self.setup_new_game
   $game_player.moveto($data_system.start_x, $data_system.start_y)
   $game_player2.moveto($data_system.start_x, $data_system.start_y)
   Graphics.frame_count = 0

class Game_Multiplayer < Game_Player

 DOWN = Input::Y # S in Keyboard
 LEFT = Input::X # A in Keyboard
 RIGHT = Input::Z # D in Keyboard
 UP = Input::R # W in Keyboard
 ENTER = Input::L # Q in Keyboard
 RUN = Input::A # Shift in Keyboard

 def move_by_input
   return unless movable?
   return if $game_map.interpreter.running?
   if Input.press?(DOWN)
   elsif Input.press?(LEFT)
   elsif Input.press?(RIGHT)
   elsif Input.press?(UP)

 def update_nonmoving(last_moving)
   return if $game_map.interpreter.running?
   if last_moving
     return if check_touch_event
   if movable? && Input.trigger?(ENTER)
     return if get_on_off_vehicle
     return if check_action_event
   update_encounter if last_moving

class Spriteset_Map
 alias :th_multiplayer_create_characters :create_characters

 def create_characters
   @character_sprites.push(Sprite_Character.new(@viewport1, $game_player2))

class Scene_Map < Scene_Base
 alias :th_multiplayer_map_update :update
 def update
   $game_player2.update if $game_player2


With a single screen, you can't really do much in terms of actual multiplayer support (if one guy goes into battle, so does everyone else), but at the very least, you can split yourself into two separately controllable players. You can collect treasure faster, flip more switches faster, ...


I will likely be using the full input script to bind a bunch of keys for the second player since it makes more sense that way.


Maybe I will add this to my player-switch to see if people can control two players at the same time traversing a simple maze LOL

Edited by Tsukihime

Share this post

Link to post
Share on other sites

The link to rpg revolution doesn't work for me :(


I wrote a 2 players script... could it be mine?


Well, it works still with little code, and it has more compatibility, but like you said it handles less things.

It depends on what the user want to do ^^


By the way I wanna see the one in the first link xD

Share this post

Link to post
Share on other sites

It's woratana's 2-player script.


I would like to extend it to n-player script, but I would need to abstract the controls. For example, if you had gamepads, I could assign different controllers to each player and then check for input that way.


But with a single keyboard it's pretty limited.

I guess if you had two keyboards you might get somewhere as well.

Share this post

Link to post
Share on other sites

Yeah, n-player sounds nice!


You could use an already made script for gamepads, I suppose... I saw them here or in the rpgmakerweb, not sure.


Two keyboards look difficult to have xD


And you should make it work with XAS or something like that... everyone asks for this when hearing "2 players" xD

Share this post

Link to post
Share on other sites

Maybe add support for one player with the keyboard and the other can use a gamepad ...

Share this post

Link to post
Share on other sites

Amazing. There is one for XAS already, but its still on XP. Now that Hime created one for Ace, you can surely use it for XAS as well.


Great work, Hime :) Amazing as always.

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

Top ArrowTop Arrow Highlighted