Charas-Project

  • Home
  • Help
  • Search
  • Calendar
  • Login
  • Register
*
Please login or register.

Login with username, password and session length
 

News:

Click here to join us on IRC (#charas on irc.freenode.net)!



  • Charas-Project »
  • Game Creation »
  • Requests »
  • RPG Maker Programming »
  • Tutorial: How to Detect which Hero is Displayed on the Map
« previous next »
  • Print
Pages: [1]

Author Topic: Tutorial: How to Detect which Hero is Displayed on the Map  (Read 4535 times)

Offline Visulth

  • Member
  • Initiate
  • *
  • Posts: 3
Tutorial: How to Detect which Hero is Displayed on the Map
« on: January 25, 2009, 06:06:37 PM »
(Tutorial for RPG Maker 2K3)

Ever wanted to have NPCs respond differently depending which character was being used? Well, this tutorial tells you how!

Here's a basic summary of what your final product will do: upon pressing a button, the party will cycle to the next person making them the lead. The person at the top will be cycled to the bottom. You will be able to tell which character is leading by way of the variable "currHero" and can make specialized responses from NPCs depending on the Hero. I use it myself for my real-time battler so the stats change when you change character.

First off, these are the variables you'll need to make:
Key Input
currHero
partySize

These are the Common Events you'll need to make (Database -> Common Event, for those who don't know)
Key Input (Parallel process)
Char Switch (Call)

Inside the "Key Input" event, add the command "Key Input Processing" and store the key code in "Key Input". In 'Keys to Process', checkmark whichever button you want to assign to switching characters. An example would be the asterisk (*), in which case you would check the very bottom box.

Enter the command "Conditional Branch". Use 'variable', and select "Key Input" and check to see if it is "Equal to" the button you assigned earlier. Continuing with the asterisk, you would check if Key Input was equal to 22.

Enter the command "Call Event", and select the common event "Char Switch". Some of you may be wondering why you would call the event rather than just put the code here--the reason is because you want to decrease the burden on the computer. The computer would have been checking the bulk of code many times every second and if there's too much code it could really lag your game.

Enter the command "Variable Operations" and set "Key Input" to 0.

This is what the Key Input event should look like:
Code: [Select]
<>Key Input Proc: [0018:COMMON: Key Inp]
<>Branch if Var [0018:COMMON:Key Inp] is 22
     <>Call Event: Switch Char
     <>
: End
<>Variable Oper: [0018:COMMON: Key Inp] Set, 0
<>

Now for the second common event, "Char Switch." First, enter the "Variable Operations" command, and set the variable "partySize" to the size of the party (under the "Other" option button).

Enter the 'Change Party' command and remove the party member stored in the variable "currHero". Next, add the party member stored in the variable "currHero". This effectively moved the current hero from the top of the list, to the bottom.

Add a conditional branch that checks if "partySize" is greater than "currHero". If it is, add the 'Variable Operations' command adding 1 to the variable "currHero". Under 'else' add the variable operations command that subtracts 1 from the variable "currHero". I have trouble explaining what this does in words, but here's the example:
[spoiler]
     Vlad the Impaler (Hero 1)
     Van Helsing (Hero 2)
          At that point in time, currHero=1, partySize = 2. If we change the order:
     Van Helsing (Hero 2)
     Vlad the Impaler (Hero 1)
          currHero = 2, partySize = 2. Now if you notice, if you change the order, you need to get back to currHero = 1, so you subtract instead of adding.
[/spoiler]

Lastly, enter the command "Variable Operations" and set "Key Input" to 0.

This is what your switch char event should look like:
Code: [Select]
<>Variable Oper: [0025:COMMON: Party Size] Set, Party Size
<>Change Party Members: V[0019] Remove
<>Change Party Members: V[0019] Add
<>Branch if Var [0025: COMMON: Party Size] is V[0019] Greater
     <>Variable Oper: [0019:COMMON: Curr Hero] +, 1
     <>
: Else Handler
     <>Variable Oper: [0019:COMMON: Curr Hero] -, 1
     <>
: End
<>Variable Oper: [0018:COMMON: Key Inp] Set, 0

Alright, now at the start of your game somewhere, simply add the 'variable operation' setting "currHero" = 1, and you're all set to go. It could be in the first cut scene of your game, or where ever.

TIPS OF ADVICE:

You may want to add conditional branches before the key input in the common event 'Key Input' with switches like "Cinematic" to prevent users from swithcing characters when you're in a cutscene. (I.e., if cinematic = ON, then don't run the key input code).

Secondly, now that your player can switch characters at will, it might mess up your cutscenes because if you have other party members as events during your cutscene, well, there could be two of them! Easy solution--at the start of the cutscene, simply call the event "Char Switch" if the hero you want isn't selected (i.e. currHero = 2, rather than 1, which you want.)

Thirdly, and this is more of a preference issue, if the player simply holds the button you've mapped (i.e. asterisk), the characters will cycle through really fast. It doesn't cause a glitch or anything, but if you want to slow that down simply add a "wait" command for x number of seconds at the end of the 'char switch' event.

That is all. Happy RPG making.
« Last Edit: January 25, 2009, 06:37:43 PM by Visulth »
Logged

Offline wella

  • You WILL Caramelldansen!
  • Initiate
  • *
  • Posts: 70
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #1 on: January 26, 2009, 01:23:42 AM »
Good job. Well explained. The only thing I'd recommend is 'translating', if you like, the RM code into plain English, e.g.:
Code: [Select]
<>Key Input Proc: [0018:COMMON: Key Inp]
<>Branch if Var [0018:COMMON:Key Inp] is 22
     <>Call Event: Switch Char
     <>
: End
<>Variable Oper: [0018:COMMON: Key Inp] Set, 0
<>
Code: [Select]
<>Check for key inputs in the variable 'COMMON: Key Inp'
<>If the * key is pressed, call the 'Switch Char' event
<>Set the 'COMMON: Key Inp' variable to 0
Not only does this sort of thing benefit noobs, it also helps anyone who wants to skim read the code and get the jist of what's going on without having to read the whole thing to understand which variables are which and what-not.
Logged

Tip: Imageshack is gay.

Offline HobomasterXXX

  • Your eyes. Are an ocean. Your breasts. Are also an ocean.
  • Leader
  • *
  • Posts: 2,700
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #2 on: January 26, 2009, 02:05:24 AM »
Also, tutorials generally go in the tutorials section of the forum. >_>

Cool tutorial anyway.
Logged

1:24 PM - [Razor]: I think
1:24 PM - [Razor]: I almost fell off my chair
1:24 PM - [Razor]: in anticipation for DICK

Offline wella

  • You WILL Caramelldansen!
  • Initiate
  • *
  • Posts: 70
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #3 on: January 26, 2009, 02:53:10 AM »
AKSHULLY.

I has a Lucas.
Logged

Tip: Imageshack is gay.

Offline wella

  • You WILL Caramelldansen!
  • Initiate
  • *
  • Posts: 70
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #4 on: January 26, 2009, 06:03:47 PM »
Yes. He's right here ^. In fact, I do believe that you are said Lucas. By Jove.
Logged

Tip: Imageshack is gay.

Offline wella

  • You WILL Caramelldansen!
  • Initiate
  • *
  • Posts: 70
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #5 on: January 26, 2009, 08:33:37 PM »
(Warning: bikini)
http://www1.istockphoto.com/file_thumbview_approve/3094748/2/istockphoto_3094748_sexy_bikini_girl.jpg

Now can I have you?
Logged

Tip: Imageshack is gay.

Offline wella

  • You WILL Caramelldansen!
  • Initiate
  • *
  • Posts: 70
Re: Tutorial: How to Detect which Hero is Displayed on the Map
« Reply #6 on: January 27, 2009, 05:27:44 PM »
Wait, I have an alternative.

Caramelldansen?
Logged

Tip: Imageshack is gay.

  • Print
Pages: [1]
« previous next »
  • Charas-Project »
  • Game Creation »
  • Requests »
  • RPG Maker Programming »
  • Tutorial: How to Detect which Hero is Displayed on the Map
 

  • SMF 2.0.10 | SMF © 2015, Simple Machines
  • XHTML
  • 2O11
  • RSS
  • WAP2
  • Simple Machines Forum