Item use restricted by map/variable/switch

omega9380

Veteran
Veteran
Joined
Mar 24, 2013
Messages
68
Reaction score
9
First Language
English
Primarily Uses
I'm trying to create an item that heals the party for 50% of their HP and MP, and opens the save screen.  The item needs to be restricted to only be allowed use on the overworld map.  So, two questions.


1.  How best to restrict the item use?  I have tried using a Common Event, having the item call that event, and using a Conditional Branch restricted by a switch, but I would like the item to be greyed out in the menu unless the player is on a specific map (like the Overworld) or a specific switch is on (like a save point)


2.  How do I make the item heal 50% of the parties HP & MP?  If the item calls a Common Event, the Change MP or Change HP actions only allow changing via a constant number that doesn't allow decimals, and I don't know enough about RMMV code syntax to use the Script action and $game (A comprehensive code reference for RMMV would be REALLY nice...). I really would rather have a more elegant solution than 12+ Change Variable actions...


If the answer to #1 works, I can just use the Recover HP and Recover MP effects on the item itself to solve answer 2.  I have a sneaking suspicion that the Yanfly engine will be the answer (it seems to be the answer to life, the universe, and everything :) ), but I haven't figured out which plugin to use.  I await with baited breath the wisdom of the RMMV community!  Thanks!!
 
Last edited by a moderator:

omega9380

Veteran
Veteran
Joined
Mar 24, 2013
Messages
68
Reaction score
9
First Language
English
Primarily Uses
OK, using BOB_EnhancedRestrictions, I was able to restrict use of the item to only allow when a switch is on.  Cool!  Now, any help with item #2 above?  I tried just using the Recover effects, and it works, kinda.  I want to run an animation depicting the screen fading and the Inn music playing before the save screen pops open.  Setting the item scope to All Allies so the Recover effects work makes the game open the party screen to apply the effect before my common event runs that shows the fade out and save screen.  It works, but its not very visually appealing.  I really would like the recovery to happen during the common event.
 
Last edited by a moderator:

mrcopra

Veteran
Veteran
Joined
Jul 21, 2015
Messages
449
Reaction score
149
First Language
Not English
Primarily Uses
N/A
 make  variables with  a little math


maxHp * 0.5 and maxMp * 0.5 


and use recovery with variables option for every one 


Until you get a better solution ;)
 

omega9380

Veteran
Veteran
Joined
Mar 24, 2013
Messages
68
Reaction score
9
First Language
English
Primarily Uses
I was able to get it working.  It took 26 Control Variable calls, but it worked!
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
692
Reaction score
531
First Language
French
Primarily Uses
Congratulations on making it work by yourself! Doing things by yourself is the best way to learn.


It's also the way to realize some things are better handled with a tiny bit of script calls...


To answer your question: there's not really a more efficient way to do it with pure eventing than multiple conditionnals and control variables, because you cannot get an actor max hp/max mp by id.


If you're interested I'm going to show you how to automate the process for all your actors, using a loop and three simple script calls:

Script calls:



$gameVariable.value(id) //returns the value inside game variable [id]
$gameActors.actor(id).mhp //returns the max hp of actor [id]
$gameActors.actor(id).mmp //returns the max mp of actor [id]


How the common event looks:





What happens:

  1. We set variable 23 to 0.
  2. We start looping, and increase variable 23, it is now 1
  3. We set variable 24 to actor of id = variable 23 (1) max hp, divide it by 2 and then increase hp accordingly
  4. We do the same for mp
  5. We check if variable 23 is >= to the maximum number of actors in your game (in my example 4). If it is, we exit the loop.
  6. If it isn't we continue looping: Do steps 2-5 again. Variable 23 willl increase to 2,3,4 in order and thus we make the checks and the parameter increase for actors 2,3,4.

Change the 4 to your number of actors.


This example increases hp and mp for all actors in your game. Increasing only for current party members is definitely possible, it simply requires more script calls.


The script calls here allowed us to bypass the limitation of the event command, to be able to get the maximum hp of an actor by its id instead of selecting from a drop down menu.


If you don't use script calls. You have to do the checks manually, and the amount of actions needed increase rapidly (and you lose the point of using a loop).



If you just want to see how it can be done and automated for all party members with a script call:

var actor, i, mhp, mmp, id; //declaring variables
i = 0 //setting up the loop
while (i < $gameParty.members().length) { //looping until we reach the amount of party members
actor = $gameParty.members(); //retrieving the actor currently checked
id = actor._actorId //getting the actor id
mhp = actor.mhp; mmp = actor.mmp; //setting variables to its mhp and mmp
$gameActors.actor(id).gainHp(Math.floor(mhp/2)) //increasing hp
$gameActors.actor(id).gainMp(Math.floor(mhp/2)) //increasing mp
i++; //increase loop count
}


As you can see, it works in the same way as the mostly evented example above.


It's fully functional, use it if you want.


Using this code snippet you could modify the evented example to apply only to current party members, not all actors. I leave that to you as an exercise.


You can get a list of script call equivalent of event commands in this thread if you're interested:






I hope you liked these examples and maybe learned something. Have a nice day!
 

omega9380

Veteran
Veteran
Joined
Mar 24, 2013
Messages
68
Reaction score
9
First Language
English
Primarily Uses
Thanks!  I appreciate the streamlining of what I am looking.  I probably could have figured that out, if I could find a code reference that explains what you can do with that magic "$game".  Do you have an idea where I might find something like that?  I'm not a coder.  I have dabbled a bit with Visual Basic, played around with Ruby Script in RMVXAce.  I can usually figure out how to make something work, if i have a reference to look at.  Everyone puts examples in the forums like "use $gameActors.actor(id).gainHp(Math.floor(mhp/2))".  What else can I call with $gameActors?  What else can I get with $gameActors.actor(id)?  I just need a reference and I am tearing my hair out trying to find one!!
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
692
Reaction score
531
First Language
French
Primarily Uses
Sadly such a list doesn't exist. I would have liked one too when I started using javascript but you'll have to read the .js files yourself.


I recommend grabbing the separated .js files, here:





There in Game_Actor.js you can see some built in functions related to $gameActors.actor(id). 


The next step would be checking Game_Interpreter.js because it's what handles event commands, it allows you to see how the game interprets your event commands and thus replicate them in script calls.


Also: the thread containing the list of script call equivalent of event commands (in my first post spoilers) is a huge help for this too.


Once you get a bit familiar with how things works in javascript you can make the console appear (F8), enter "window" without the quotes. There you'll see a list of everything in your game and by going through it gradually you'll be able to know how to refer to it.


For example try inputting "$gameActors.actor(1)" in the console and you'll see a list of that actor object properties. You can then call then at your leisure.
 
Last edited by a moderator:

omega9380

Veteran
Veteran
Joined
Mar 24, 2013
Messages
68
Reaction score
9
First Language
English
Primarily Uses
You would think that with a tool as powerful as this the developer would have better documentation.  I know the tagline is "SIMPLE ENOUGH FOR A CHILD. POWERFUL ENOUGH FOR A DEVELOPER.", and the biggest draw is creating a game without coding, but when they implement a plugin system like they have, it would be nice to have a code reference of some kind.  Oh, well, I'm probably just preaching to the choir here.   Thanks for the link, these will help!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

I got a new computer and can't find my product activation key for MV, what do I do ;-;
buinguyenhoangtho wrote on fizzly's profile.
Hello @fizzly, i would like to use your asset/ resource for my project ( is maybe commercial ). May i have your permission? Thanks you !
Working on breaking the limits of RPGMaker! :cool:
I have 470+ hours on RMMV but have only made a demo game, is this normal? :kaoswt: (I lose motivation a lot plus I use a 32gb laptop, so..)

Forum statistics

Threads
95,431
Messages
929,110
Members
125,668
Latest member
djsete
Top