Author Topic: [RESOLVED] Help with Tsukihime's 2 Player Script  (Read 643 times)

Offline Paladin

  • Total Beginner
  • Posts: 5
  • LV: 0
    • View Profile
[RESOLVED] Help with Tsukihime's 2 Player Script
« on: January 06, 2017, 07:19:16 PM »
Greetings,

I am using RPG Maker Ace, and it's very fun to use. I am trying to implement local two player capability. I've searched the web and it appears the only option right now is this script from Tsukihime:
 
http://www.rpgmakercentral.com/topic/4128-simple-2-player-script-development/
 
I followed his instructions, and it works just as he described; However, it has limitations. It creates a copy of the player sprite and allows you to control that as a second player, but you can't make the two players have separate sprites (as far as I am aware!).
 
Now despite knowing practically nothing about script programming, I really wanted to try and solve this myself. So I spent a long while modifying things in the script editor, deleting and testing, modifying script (don't worry, I ensured to undo any of the damage I caused after I tested).
 
My tampering was not altogether useless however. I discovered the following:
 
In "Spriteset_Map" in the script editor, go to about line 60, and you'll see the "Create Character Sprite" section. At the bottom of that small section there is the following code:

@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    @map_id = $game_map.map_id
 
When I saw 'game_player' at the end, I decided to try and change it to 'game_player2' like in Tsukihime's script. The results were exciting.   :)
 
The first actor of the initial party could be controlled with the multiplayer script (w,a,s,d keys), and second actor in the initial party could be controlled with the default keys.
 
In Database on the System tab you can change the sprite of both characters to whatever you wanted.
 
But there is one catch. The movement of the default keys player is now delayed. To change direction, you have to press the key 2-3 times, and the player will move in it's initial direction one tile before moving correctly. Very odd. It reminded me of followers.
 
My theory is that if the follower movement delay was gone, the movement of the default keys player would be normal.
 
But alas, I know nothing of scripting. So while I'm suspecting this to be the culprit:

Script Editor > Game_Follower, at about line 55 there is a section called "Pursue Preceding Character"
 
....I really have not the slightest idea on how to fix it. I could be way off base. Sorry for the lengthy description, it all seems so complicated.  :???:  Any help is appreciated!
 
« Last Edit: January 09, 2017, 04:18:33 AM by Paladin »

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2854
  • LV: 364
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #1 on: January 07, 2017, 09:08:12 AM »
I'm not sure I understand what you mean by your edit to Spriteset_Map; doing so just only shows one actor on the map: $game_player2. In fact, you would be drawing him twice because the 2-player script already adds $game_player2 in, as seen:
Code: [Select]
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
If all you want is to make the second party member be drawn for $game_player2, you can just add this method inside class Game_Multiplayer
Code: [Select]
  def actor
    $game_party.battle_members[1]
  end
This was taken from the Game_Player class:
Code: [Select]
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    @character_name = actor ? actor.character_name : ""
    @character_index = actor ? actor.character_index : 0
    @followers.refresh
  end
  #--------------------------------------------------------------------------
  # * Get Corresponding Actor
  #--------------------------------------------------------------------------
  def actor
    $game_party.battle_members[0]
  end
If you define the actor the player is supposed to represent, the game will set the graphic for you automatically in refresh.



(click to show/hide)
NNID: KK20-CP

Offline Paladin

  • Total Beginner
  • Posts: 5
  • LV: 0
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #2 on: January 07, 2017, 09:15:25 PM »

If all you want is to make the second party member be drawn for $game_player2, you can just add this method inside class Game_Multiplayer
Code: [Select]
  def actor
    $game_party.battle_members[1]
  end

Thank you KK20, you're a genius!  :D That explanation makes total sense. I undid my modification to the Spriteset_Map, and followed your instructions. This mod to the script resolved the lag issue.

But there is another problem. Since the whole setup makes a follower become a second player, I went ahead and tested to see if I could gain a follower with both of the players. It appears this two player setup disables the ability to have followers at all. Is this script simply incompatible with the follower function?

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2854
  • LV: 364
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #3 on: January 07, 2017, 11:58:22 PM »
If you have "Show Player Followers" enabled in the System tab, then only $game_player will have followers; $game_player2 will not. (If it's not doing this, you must have another script that's causing issues)
But I don't know why you would want to do that since your "party" must consist of two actors: one for $game_player and one for $game_player2. Followers are just party members that are not in the first slot. In this case, $game_player will have an actor that looks like $game_player2 follow them around.

If you can explain what it is that you want, I can probably point you in the right direction.



(click to show/hide)
NNID: KK20-CP

Offline Paladin

  • Total Beginner
  • Posts: 5
  • LV: 0
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #4 on: January 08, 2017, 01:09:23 AM »
Show Player Followers was enabled, so it must be script like you said.

I started a fresh project and copied over the fullkeyboard and multiplayer scripts only. I added the other player in the system tab, and ran the game. It appeared just like your screenshot - Player1 and Player2 with another Player2 sprite following Player1. I must have forgot to undo some code adding/deleting during my initial haphazard 'troubleshooting'.  :facepalm:

It makes sense. If "Show Player Followers" is disabled, then it shows up just like I want it but without the ability to see followers I actually want to add.

I obviously can't have another player 2 sprite following player 1 around.

To answer your question, I'm trying to make the game two player with the ability for a player to walk up to an NPC and trigger an event that adds that NPC to the party. I don't mind if it only can follow Player1.

I really appreciate your help, thank you!

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2854
  • LV: 364
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #5 on: January 08, 2017, 09:31:52 AM »
I found this script that can help with making events follow the player: http://himeworks.com/2013/03/event-followers/
In order to make it work for two players, I had to do some slight edits.
(click to show/hide)
(click to show/hide)
With the "Show Player Followers" disabled, you can create an event on the map with a Script command
Code: [Select]
followand this will automatically follow the player that talked to it. To remove the event from following, the command is
Code: [Select]
$game_map.events[ID].stop_followwhere ID is the event ID that is following a player.

You can specify a specific player to follow using the following:
Code: [Select]
follow(-1) # Follows player 1
follow(-2) # Follows player 2



(click to show/hide)
NNID: KK20-CP

Offline Paladin

  • Total Beginner
  • Posts: 5
  • LV: 0
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #6 on: January 08, 2017, 10:49:47 PM »
KK20,

This works great!  :) I've had that "Event Followers" page open on my browser for a few days, but hadn't looked at. With your mods, it's perfect!

I went ahead and did another test involving transferring players from one map to the next. While the follower did not show up on the other map, I simply copied the event to the new map and ran it as a parallel process so he would automatically be following once they transferred. I read some of the comments at the bottom of the website link you sent me and it appears that events are not transferable, so my workaround will suffice quite well.

It did bring up another issue with the multiplayer script though - when you transfer the players to a new map, player2 shows up just a few tiles away. The big problem is if the location is really small, like a path only one map tile in width, then player 2 is not visible in the new location. I would like either to have player2 land on the same tile as player1, or maybe on a specified tile. I've looked at the multiplayer script, Scene_Map, Game_Follower, and Game_Party, but I don't see anything obvious.

Of course, I know hardly anything concerning script, so maybe the solution was right in front of me.

Also, when I set an event's move route to approach player, it goes toward player1. My idea for fixing that was to go to Script Editor > 'Game_Character' and add this:

def move_toward_player2
    move_toward_character($game_player2)
  end

Then, go to 'Game_Event' and modify the 'random' script in the "Move Type : Approach" section. I'm not sure if I'm on the right track, but I want an NPC to approach either of the two players (who ever is closest) and trigger with event touch.

Thanks again!

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2854
  • LV: 364
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #7 on: January 09, 2017, 03:45:44 AM »
(click to show/hide)
(click to show/hide)
Noticed a bug in the script I posted yesterday; no idea how that passed by me before.
Transfer event will now put the second player in the specified teleport spot.
An event with an Autonomous Movement type Approach will generally move towards the closest player.

But you will soon see that event touch trigger won't work and will phase through the second player. There's a lot of other issues like this when you add another player entity that the game has no idea of. That's the reason why that script was only a Proof of Concept--there's just so much more that needs to be done.

This is pretty much the extent of all I can help you with. If you're still serious with this, I advise getting a full-time scripter who is willing to rewrite the default scripts for you.
« Last Edit: January 09, 2017, 04:31:42 AM by KK20 »



(click to show/hide)
NNID: KK20-CP

Offline Paladin

  • Total Beginner
  • Posts: 5
  • LV: 0
    • View Profile
Re: Help with Tsukihime's 2 Player Script
« Reply #8 on: January 09, 2017, 04:18:03 AM »
The transfer now works flawlessly! KK20, you have gone above and beyond my expectations help-wise. I understand that rpg-maker wasn't designed to have 2 player ability to start with, but with Tsukihime's script and all your mods here, I think this is fantastic.

Thank you for spending your time and effort in getting this sorted out. I'm going to mark this topic as resolved as this final solution is at present satisfactory for me. As you said, this would need much more work in order to make it fully ingrained into the system.

If this little project gets to a reasonable size, I will do just as you suggest.  :)