Changing Character on the Map

Scubidubi

Villager
Member
Joined
Jun 27, 2016
Messages
10
Reaction score
1
First Language
German
Primarily Uses
Hello Community! I am new to all the wonderful features of MV and wondering if anyone knows a method to cycle the leader though your party with a button press while on the map. I am thinking about the mechanic as used in BOF3. Where only a big character could push something heavy.


ty


the dubi
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
I've moved this thread to Javascript/Plugin Support . Please be sure to post your threads in the correct forum next time. Thank you.
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
106
Reaction score
20
First Language
Italian
I know for sure that is possible but it requires some times to understand/execute. My suggestion is that if you plan to make a very customized game you should start to learn scripting by yourself. It's a very steep learning curve at first (expecially if you never programmed) and the documentation reguarding the source code is lacking (to be generous), but in the end it's worth it. The first days could be very frustrating, expecially because you have to reverse engeneer the source code to have an idea of how the vanilla game works.


If you want to do that start downloading Sublime text 3 or Notepad++ (i suggest the first one) and read some brief javascript tutorial, at that point if you have some general questions like where to find fucntions or variables that handle special thing i can point you in the right direction
 

Scubidubi

Villager
Member
Joined
Jun 27, 2016
Messages
10
Reaction score
1
First Language
German
Primarily Uses
ok yeah, sounds like some work. but I will have to look into it at some point.
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
106
Reaction score
20
First Language
Italian
I though a bit more about your specific problem and I inderstood that if i could find where the party order is stored doing what u want would have been really easy


So, i came up with a working easy solution but to earn at least you have to understad how it works :)


1. the party order


Party order is stored inside the $gameParty Object (which is an istance of the class Game_Party, basically Game_Party is like a blueprint while $gameParty is the proptotype build and which "lives" when you run the game, so since Game_Party is just a blueprint you can't use it directly (at least not in this case) but instead you have to use the prototype because it can actually do things). The party order is a propery of $gameParty named _actors and is an array (a list of variables),


We can access it by typing 


 in the console for example (to open it press F8 while running the game, try it maybe)


2. cicling the party order


So we found where the party order is stored, now we have to find a way to rotate the members.


EXAMPLE: from [char1, char2, char3] to [char2, char3, char1]


Luckily for us the order is an Array type Object and in Javascript this class is already plenty of usefull methods and tools because is one of the more used. You can look them up in the internet o like here ARRAY_METHODS, i program a lot but i consult the internet constantly.


We will be using 2 these array methods: push() and shift()


push() add an element at the end of an array, an undefined one if not specified what should be added READ_EXAMPLE_HERE


shift() removes the first element of an array and returns it, so it like gives you this removed element to store it somewhere if you want


So to what we can do is:


$gameParty._actors.push($gameParty._actors.shift());


This is a little bit tricky to understand... $gameParty._actors.shift() remove the first element and it returns it as a value, this value is given directly to .push(value to add at the end of the arrayso is given specificately to $gameParty._actors.push().


Conclusions this line right here is what you where looking for, it cicles the party characters, you just have to add $gamePlayer.refresh(); to make the change effective (don't ask me why i don't know every in and out of the source code). So it becomes:


$gameParty._actors.push($gameParty._actors.shift());
$gamePlayer.refresh();






3. Making the code accessible


Now we just have to make the code more accessible/clean.


If you want to modify other things later i suggest you to create you own plugin using sublime text 3 or notepad++


Make sure you save it as ".js" and store it in game_folder \js \plugins


If you want to know how to add description, guide and parametner to plugin i suggest you to look up a tutoria in internet or download a template but for now you dont' need to do that it work nevertheless, so you have just to add it in rpg maker and enable it.


If you dove everythign i said you should have your plugin named as u want, whith a .js extention sitting in  game_folder \js \plugins


and added+enabled in the project editor


Now we get to tranforming the 2 lines of code we created in a usefull tool. We will store these line in a function, a chunk of code which upon calling does things and or gives back a value.


Example of a function who takes a argument (an input value) and returns a value


// returns the given value elevated to the power of 2
power_of_2 = function(value) {
return value * value;
};


In our case though we don't need to have a value back or to give an input value either, we just need the function to cicle the party upon calling. The struction for this "simple" kind of fucntions is:


Funtion_Name = function() {
//code to execute
};




now we put the 2 lines inside


Funtion_Name = function() {
$gameParty._actors.push($gameParty._actors.shift());
$gamePlayer.refresh();
};




At this point the function already works, you can just save the plugin and typing in the console or in a script of an event this


Funciton_Name();


Is not very beautiful though.. and it still doesnt' have a proper name.


Let's start with the name, i would call it rotateParty (or cicleParty if you rpefer, but to cicle has kinda a different meaning in programing, anyway you can call it how you want just be sure there isn't another function with the same name or you will override it)


rotateParty = function() {
$gameParty._actors.push($gameParty._actors.shift());
$gamePlayer.refresh();
};




Already better, but usually every function is sorted inside big containers called classes (classes are collection of properties (variables) and funcitons/methods).


Since we are modifiyng values reguarding the class Game_Party i think we should store the function in there


Game_Party.prototype.rotateParty = function() {
$gameParty._actors.push($gameParty._actors.shift());
$gamePlayer.refresh();
};




If you are wondering what prototype is it basically means that this fucntion exists only on a protoype of the class ($gameParty in our case) and not on the blue print Game_Party


(basically we can call $gameParty.rotateParty() but not Game_Party.rotateParty() which would be useless for us 'cause it doens't store the party order)


Anyway the code as we have it for now will give error, because we are calling $gameParty._actors from within $gameParty and the code thinks we are trying to call a different class since we are specifying the name of the class. He's like inside a care calle $gameParty and looking around for a car named $gameParty but he can't find it because he's inside it.


In these cases we have to use this, which automatically refers to class the code is into at the moment.


So we finally get:


Game_Party.prototype.rotateParty = function() {
this._actors.push($gameParty._actors.shift());
this.refresh();
};




3. Putting the code to use


We just need to call the code when we want it.


The line we have to use is


$gameParty.rotateParty();


the brackets say the code to run the funciton otherwise it just gives back all the code inside the function.


You can call this as i already said in the console (F8 during test run) for testing, or putting it into the event command "Script"


That's it, i hope it's all clear :)


Read it patiently  ;)
 
Last edited by a moderator:

Punamaagi

Hero on their own terms
Veteran
Joined
Jan 23, 2016
Messages
211
Reaction score
313
First Language
Finnish
Primarily Uses
RMMV
Yanfly has a plugin called Button Common Events which could suit your purpose quite well. With it, you could do something along these lines:

  • Make a variable called 'Party Leader' or something similar.
  • Make a Common Event called 'Party Leader' or something similar. Its trigger should be set to 'None'.
  • Make the Common Event increase the value of the Party Leader variable by 1. You should probably also make a Conditional Branch to check the value of the variable and reset it to 1 if the value exceeds the number of your party members.
  • Add another Conditional Branch to check the value of the variable and make it change player graphic for each value (in other words, if the value is 1 the player graphic would look like character A, if it's 2 the player would look like character B etc.)
  • Go the Button Common Event settings and assign the 'Party Leader' Common Event to the key of your liking.

Here's an example of what I mean:





I added a one-frame Wait between the two Conditional Branches just to be safe, but I'm not sure if it's necessary. It's also worth noting that the Conditional Branch might get a bit more complex if your game has characters who aren't always in the party as you'd then have to check the current story progression or members of the party.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top