Charas-Project

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

Login with username, password and session length
 

News:

New forum theme up and running!



  • Charas-Project »
  • Game Creation »
  • Requests »
  • Tutorials »
  • How to find the percentage of a variable.
« previous next »
  • Print
Pages: [1]

Author Topic: How to find the percentage of a variable.  (Read 4814 times)

Offline Rowan

  • ...
  • Zealot
  • *
  • Posts: 601
  • Charas arbitrary gay black guy.
How to find the percentage of a variable.
« on: November 09, 2009, 01:01:09 AM »
Have you ever been in a predicament where you wanted to increase something by a percentage or find the percent of a variable? Have you ever wanted to create a Demi Spell that deals damage based on 35% of the targets MAX HP? Well look no further as this VERY simple tutorial will teach you how to find those pesky percentages.

What you need to know:

Understanding Variables
Understanding Math

Required:

An event (of course)
1 Variable AND/OR 2 variables (depends on what you want to increase and how you want to increase it.)

For this tutorial I'm going to assume you know the inside and out on variables and what they can do.

For this lesson, Let's say your hero currently has 3973 STR (Strength Stat) and we equip a weapon that increases the heros STR by 58%. If we do this by calculator,
at the end the hero should have 6277 STR. RPG Maker rounds all variables down to the nearest whole. (In layman's terms, any numbers after the decimal will not register in the game.)

1. First you will need to create and assign the variable according to how much STR the hero has.
2. You will then need to multiply the variable by 100.
3. Next, multiply the variable by the percent, which in this case is .58 (.58 = 58%). As said before, RPG Maker will not register any number after the decimal, so to counter this we will need to multiply the percentage by 100, since any percent between 1-99% multiplied by 100 will equal a whole number. Doing this does not require any extra coding, and can be easily done within your head; just move the decimal to the right 2 times! 58.
4. Divide the variable by 10000. Voila your variable should now equal 2304! Which is 58% of 3973, rounded down.
5a. Since we are increasing the STR by 58% we will need to create a Change Statistic Event Command. Set the "Amount of points" to our above variable and you're done (Ignore step 6)! Your heros STR should now be 6277!
5b. You can also assign the value to another variable to increase it's own value.
6. Add the new variable to the first variable, and you're done! The first variable should now = 6277!

------------------------

Commands should like either like:

1.  Variable Oper: [####: NAME] Set, Hero Attack  
2.  Variable Oper: [####: NAME] *, 100
3.  Variable Oper: [####: NAME] *, 58
4.  Variable Oper: [####: NAME] /, 10000
5.  Change Statistics: Hero Attack v[####] Up

OR

1.  Variable Oper: [0001: NAME] Set, Hero Attack  
2.  Variable Oper: [0001: NAME] *, 100
3.  Variable Oper: [0001: NAME] *, 58
4.  Variable Oper: [0001: NAME] /, 10000
5.  Variable Oper: [0002: BOOBS] Set, Var [0001]'s value
6.  Variable Oper: [0001: NAME] +, Var [0002]'s value

--------------------------------

There are MANY ways in which you can play around with this. Try experimenting and see what you can come up with. :)

That's it for this tutorial for any questions, simply give me a reply or PM me.
« Last Edit: November 10, 2009, 05:00:51 PM by Rowan »
Logged


Offline Emerates

  • A. Hermit Esquire
  • Exemplar
  • *
  • Posts: 1,027
    • Emerates' Freewebs Site
Re: How to find a percentage of a variable.
« Reply #1 on: November 09, 2009, 01:23:11 AM »
Never thought of doing stats this way, but I can definitely see the practical applications in this.  Might come in handy with accessories.  Good job, guy!

However, how do you reverse it, if you unequip all your stuff?  That part's always given me problems.
Logged

Offline Rowan

  • ...
  • Zealot
  • *
  • Posts: 601
  • Charas arbitrary gay black guy.
Re: How to find a percentage of a variable.
« Reply #2 on: November 09, 2009, 05:09:38 AM »
Quote from: Emerates on November 09, 2009, 01:23:11 AM
Never thought of doing stats this way, but I can definitely see the practical applications in this.  Might come in handy with accessories.  Good job, guy!

However, how do you reverse it, if you unequip all your stuff?  That part's always given me problems.

This can be done (as its in my game), but I'm going to say now that the code is VERY complicated.

I'm not sure on the specifics on what to do in a DBS and/or DMS system, but what I have to do in my game is that I have to replace ALL the default maker stats with variables. I had to make variables of each players stat BEFORE they equip the items and a variable for each stat AFTER they equip the item. Basically in my CMS whenever they equip an item, I reset ALL the equipped heroes stats to the base then do the above percentage code. Whenever they de-equip it I again reset all their values to their base, but this time since the item is no longer equipped the percentage code won't go thru and thus the stats remain at base level (it will still recognize all other equipment and increase it properly).

I tried doing this with the default stat system but the code turned out to be pretty unorganized and vastly more complicated then it need to be. I just decided to just replace the default stat/equip system with all variables since I was creating a CMS/CBS anyways.

Sorry I couldn't be more of help since I don't use a DBS and/or DMS system =(.

P.S After thinking about it a little, this CAN be done with a DBS or DMS. It is MUCH more complicated and you will need to use your creativity a bit concerning weapons, but it definitely can be done. :) I'm DEFINATELY not going into detail, but the gist of it as that you will need to create an event that restricts all menu access accept with a certain key, apply what I said above (kinda) THEN let the command access the menu. Now when you leave the menu the event will go back to the command; this is where you input the rest of what I said above. If you did it right it SHOULD work, however when the player plays the game The player won't know how much it increases it by. P.P.S Believe or not I think this can be fixed to (somewhat) if you put in the effort :P. You will just need to play around with it and figure out what exactly you can do with variables in AND outside the game.
« Last Edit: November 09, 2009, 05:12:10 AM by Rowan »
Logged


Offline Emerates

  • A. Hermit Esquire
  • Exemplar
  • *
  • Posts: 1,027
    • Emerates' Freewebs Site
Re: How to find a percentage of a variable.
« Reply #3 on: November 09, 2009, 05:30:29 AM »
Well hell.  I had actually been considering making a weapons preference system, but then you say something like that...  I'm actually not that good at coding, so onto crushing the next dream... :P
Logged

Offline SaiKar

  • KOFFING!
  • Staff
  • Royal
  • *
  • Posts: 4,082
Re: How to find the percentage of a variable.
« Reply #4 on: November 12, 2009, 02:02:48 AM »
Man, Rowan being here and posting tutorials and drawing stuff and making a game... it's just like old times!

The math for reversing it isn't nearly as complicated as he's making it out to be though. It just requires a bit of algebra.

The first equation, the one that increases attack, can be written as:
X + 0.58X = Y ; or,
1.058X = Y
Where X is base strength, 0.58 is the percentage we're increasing strength by, and Y is the final value. Everything plugged in, this looks like:
3973 + (0.58*3973) = 6277 ; or,
1.58 * 3973 = 6277
Which is correct.

To reverse it, we simply solve for Y instead of X:
1.58X = Y
Y / 1.58 = X ; or, getting rid of the decimals that RPGMaker hates so much,
(Y * 100) / 158 = X

Plugging in all the numbers, this looks like,
(6277 * 100) / 158 = X
627700 / 158 = X
X = 3972
Give or take the starting value due to rounding error.

This formula gives the original X, which is the character's initial strength. To decrease the strength to that value, we have to decrease character strength by,
Y - X ;
6277 - 3972 = 2305

Using Rowan's script mockup, this would look something like:

1.  Variable Oper: [0001: NAME] Set, Hero Attack                      = 6277
2.  Variable Oper: [0002: BOOBS] Set, Hero Attack                   = 6722
3.  Variable Oper: [0001: NAME] *, 100                                    = 672200
4.  Variable Oper: [0001: NAME] /, 158                                     = 3922
6.  Variable Oper: [0002: BOOBS] -, Var [0001]'s value             = 2305
7.  Change Statistics: Hero Attack v[0002: NAME] Down             Strength decreases 2305 points from 6277 to 3922. Bang!

Sorry about the math; bet you blokes thought you'd never need that crap after you learned it! :badboy:
« Last Edit: November 12, 2009, 02:05:49 AM by SaiKar »
Logged

Offline Rowan

  • ...
  • Zealot
  • *
  • Posts: 601
  • Charas arbitrary gay black guy.
Re: How to find the percentage of a variable.
« Reply #5 on: November 12, 2009, 03:06:21 AM »
Quote from: SaiKar on November 12, 2009, 02:02:48 AM
Math

Hmm... I admit, I learned a lot after reading that. Doing it this way does make it a bit easier. I could use this for future systems, thanks. I might have to end up changing my own cipher system now lol.
« Last Edit: November 12, 2009, 03:08:45 AM by Rowan »
Logged


  • Print
Pages: [1]
« previous next »
  • Charas-Project »
  • Game Creation »
  • Requests »
  • Tutorials »
  • How to find the percentage of a variable.
 

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