Jump to content
Sign in to follow this  
Tsukihime

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.

 

http://www.rpgrevolution.com/forums/?showtopic=10516

 

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.

 

http://www.rpgmakervxace.net/topic/2551-rgss3-input-full-utf8input-error-found-and-fixed/

 

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
 end

 def self.create_game_objects
   th_multiplayer_create_game_objects
   $game_player2 = Game_Multiplayer.new

 end

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

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

 def self.setup_new_game
   create_game_objects
   $game_party.setup_starting_members
   $game_map.setup($data_system.start_map_id)
   $game_player.moveto($data_system.start_x, $data_system.start_y)
   $game_player.refresh
   $game_player2.moveto($data_system.start_x, $data_system.start_y)
   $game_player2.refresh
   Graphics.frame_count = 0
 end
end

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)
     move_straight(2)
   elsif Input.press?(LEFT)
     move_straight(4)
   elsif Input.press?(RIGHT)
     move_straight(6)
   elsif Input.press?(UP)
     move_straight(8)
   end
 end

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

class Spriteset_Map
 alias :th_multiplayer_create_characters :create_characters

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


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

 

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
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×