Black Pagan

Veteran
Veteran
Joined
Feb 21, 2017
Messages
350
Reaction score
272
First Language
English
Primarily Uses
RMMV
I am making a Survival game. In it, I plan to define Mana as Energy. Every 3 Hours, Player loses "10%" of Energy so you have to constantly eat and drink to recover Energy, Every day. How do I declare this through events on Main Map ?

From what i notice, I can only remove a set amount of HP/MP from Event Commands, This is not helpful at all since i also plan to have Gear that add or remove Energy (Mana) so a "Flat" amount won't work, I need a way to "Remove % of MP".

I'll just note the Length of a Day & Night Cycle in my Game and make sure I get the timing right for every 3 Hours, So all I'm asking for is help with just "Removing % of MP" through events, Not asking for help with synchronizing Day and Night cycle with this event.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,850
Reaction score
5,417
First Language
English
Primarily Uses
RMVXA
Set a variable to the character's Current MP (or to the character's Maximum MP if you are actually trying to remove a % of their Max MP, which makes more sense to me if you are trying to encourage consistent consumption of food). Divide that variable by 10. Then, remove that much MP from the character by choosing Lose MP -> choose that Variable.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
168
First Language
English
Primarily Uses
RMMV
@Wavelength That's not a percentage, it happens to work for 10% but nothing else.
To decrease by a percentage do Number * (1 - Decimal)

100 * (1 - .1) = 90 => 10% decrease
80 * (1 - .5) = 40 => 50% decrease
390 * (1 - .05) = 370.5 => 5% decrease
 

Black Pagan

Veteran
Veteran
Joined
Feb 21, 2017
Messages
350
Reaction score
272
First Language
English
Primarily Uses
RMMV
Um... Can you guys show me an example with a line or two of the code if possible ? I'm sorry I'm a beginner when it comes to event-ing and I'm not so good with math or declaring variables linked to a math function.

I just know the basics of declaring a Variable, That's about it :rswt
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,074
Reaction score
7,983
First Language
German
Primarily Uses
RMMV
OK, then to the basics.
First you need to keep in mind that the engine always cuts of partial numbers, so any mathematical operation has to have the division or decimal multiplication last to keep the error from growing.

That said, it is a relatively simple series of control variable commands - which is an extremely versatile command.
It is also good to reserve some variables for temporary operations, never storing a value there long-term.

control variable HPcost = actorXY's HP (can be selected under game data, the line that defaults to map id but has a lot more behind it)

control variable HPcost *= 0.10 (multiply by 0.10, this would give 10% of the original value, and this is where you have to know percentage mathematics - as ozubon said above you need to know what to multiply the value with to get the correct other value)

change HP: actorXY (or possible "entire party" for your game), decrease, variable HPcost

That is a series of three event commands that in combination do what you want.
If you have problems with percentage mathematics you can ask us here for help, but I strongly advice to brush up on your schoolbooks in such a case as a "survival" type game will require the developer to know his mathematics for balancing.

I also suggest you follow the link to the "starting point" in my signature. It lists a lot of tutorials and specifically a tutorial game called "variables gude" that you should play before going on with game development
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
168
First Language
English
Primarily Uses
RMMV
Using a script call you can do:
JavaScript:
$gameActors.actor(1)._mp = Math.round($gameActors.actor(1).mmp * (1 - 0.1))
Replace the 1 in $gameActors.actor(1) with another number if you want it to affect another actor. the 0.1 part means 10%, if you didn't know. 1.0 is 100% so 0.2 is 20% and 0.03 is 3% and so on.

Turns out this works aswell:
JavaScript:
$gameActors.actor(1)._mp -= Math.round($gameActors.actor(1).mmp * 0.1)


Please don't say sorry for being a beginner, we've all been there at some point, and there's no shame in asking for clarity. People who make you feel small for that can go stub a toe.
 
Last edited:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,850
Reaction score
5,417
First Language
English
Primarily Uses
RMVXA
@Wavelength That's not a percentage, it happens to work for 10% but nothing else.
To decrease by a percentage do Number * (1 - Decimal)

100 * (1 - .1) = 90 => 10% decrease
80 * (1 - .5) = 40 => 50% decrease
390 * (1 - .05) = 370.5 => 5% decrease
Except that you can't do that as easily using eventing. (With code, I agree it's not that hard.)

My way actually works fine. For a 10% decrease, you divide by 10 then subtract it from the current amount. For a 20% decrease, you can divide by 5 then subtract. If it's a non-round percentage, such as 13%, you can multiply by 13, divide by 100, and then subtract.

Um... Can you guys show me an example with a line or two of the code if possible ? I'm sorry I'm a beginner when it comes to event-ing and I'm not so good with math or declaring variables linked to a math function.

I just know the basics of declaring a Variable, That's about it :rswt
Control Variables: Set Variable 28 "Energy Loss" to Harold's Max MP
Control Variables: Divide Variable 28 by 10
Lose MP: Harold, Variable 28

That's all you need to do. You will need to do it for each character you want to remove energy from.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
168
First Language
English
Primarily Uses
RMMV
Except that you can't do that as easily using eventing. (With code, I agree it's not that hard.)

My way actually works fine. For a 10% decrease, you divide by 10 then subtract it from the current amount. For a 20% decrease, you can divide by 5 then subtract. If it's a non-round percentage, such as 13%, you can multiply by 13, divide by 100, and then subtract.
Sure whatever floats your boat but that is a convoluted solution to a well tried problem. One could use control variables, use multiply and simply put (1-.13) into the script box (in control variables) and it's immediate, no additional calculations needed.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,850
Reaction score
5,417
First Language
English
Primarily Uses
RMVXA
Sure whatever floats your boat but that is a convoluted solution to a well tried problem. One could use control variables, use multiply and simply put (1-.13) into the script box (in control variables) and it's immediate, no additional calculations needed.
Doesn't the Control Variables field round script entries to the nearest whole number before operating on the variable, though? I'm almost sure that it did in XP/VX/Ace, though I'm less sure about MV which tends to be more comfortable with floats.

(Additionally, even if it does work and allow a decimal, couldn't the result also be an unrounded decimal? Surely the OP doesn't want a character's MP to be 36.7358761!)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,074
Reaction score
7,983
First Language
German
Primarily Uses
RMMV
@Wavelength yes, it does cut all numbers to integers - which is why I specifically pointed out the importance of the order of operations in my answer above

@ozubon you're forgetting that a lot of game developers (especially with RMs as it is targeted at a younger audience in addition to professional developers) are not as comfortable with mathematics and programming as others are. They have to use the event commands instead of script mathematics whereever possible, and for an event that is the quickest way and not convoluted.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
168
First Language
English
Primarily Uses
RMMV
@Wavelength You're totally right, I'll modify the script call answer to account for rounding!

But! Using control variable's script box it does round, so using the Mul operation and putting (1-.1) or (1-.10) in the script operand I think still is the easiest and most straightforward solution. It's not like that is asking someone do to coding, that's the same math you'd do on paper, and all you have to do is change the decimal.

@Andar I think that's unfair given the context, if you're interested in percentage change and understand why a flat amount would be a problem then you are comfortable to some degree with math imo. Is separating it into steps of division and multiplication really any easier to follow than an instant copy and paste calculation?

Like there's a difference between telling a younger audience "solve this by writing your own code" and "here's a snippet you can use" because I'm positive the latter isn't any harder to use than calculating in steps. Like both depend on how well they're explained and neither is more programming or mathematical than the other.
 

Latest Threads

Latest Posts

Latest Profile Posts

unnamed_image.jpg
SOMEONE'S SINGLE! HE DOES LIKE LONG WALKS IN THE IN THE SHADOWS AND THE SMELL OF DECAY. SADLY, HE HAS NO NUMBER TO NOTE OF BECAUSE HE HAS NO USE FOR A PHONE, BECUASE SUMMONING WORKS MUCH BETTER AND DOES NOT COME WITH AN ITEMISED BILL. REMEMBER TO TREAT HIM GOOD ON THE FIRST DATE!
I just found out that MZ regional price on Steam in my place is much cheaper than MV.
Our water started to work again, now i don't have to fill up our toilet with water again.
Finally able to return to work after months of lockdown. My poor feet are hurting :( I need to get used to working again haha

Forum statistics

Threads
108,883
Messages
1,040,262
Members
141,317
Latest member
BuddhaXD
Top