(Answered) Need a cap on my variable attack power.

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
So I have a variety of weapons that increase stats based on things you do in the game. Saves, time, escapes, etc. How would I go about setting a cap to these stats?


Here's an example:


<Custom Parameters>


atk = $gameSystem.saveCount() / 3;


</Custom Parameters>


This takes the amount of times you saved, divides it by 3, and that's your attack power. Problem is someone could just sit there spamming save and get a bazillion attack power. How would I set a cap to this?
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,204
First Language
Binary
Primarily Uses
RMMZ
atk = ($gameSystem.saveCount()/3).clamp(1, 999);

// OR, to maintain easy readability:

atk = $gameSystem.saveCount() / 3;
atk = atk.clamp(1, 999);


This applies a minimum limit of 1, and maximum limit of 999 onto the value.
 

Heretic86

Veteran
Veteran
Joined
Nov 30, 2014
Messages
240
Reaction score
167
First Language
Engrish
Primarily Uses
Ruby version, use .min and .max, min limiting a higher number, and min for determining lowest allowed number.


# Ruby (RGSS) - Clamp values between 1 and 999


atk = [1, [$game_system.save_count / 3, 999].min].max


NOTE: The one you are looking for is posted above, which is the .js version.  The version I posted is for RPG Maker VX Ace and Lower, should anyone ever find a need for it...  Notice that $gameSystem and $game_system are not the same.
 

Servidion

Last Soul Keeper
Veteran
Joined
Mar 15, 2015
Messages
233
Reaction score
27
First Language
English
Primarily Uses
RMMV
Thank you very much, Dark! :D
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top