Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 14 posts ] 
    Glitchfinder
  Sat Jul 12, 2008 5:15 am
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
Randomized Stats on Level Up Version: 2.20
By: Glitchfinder


Introduction

Well, I finished an interesting script for a request a couple of hours ago, and the concept really intrigued me. So, I took that script, and I simplified it so that it is easier to use with the default database. (although it no longer fits the request) It is actually a script that will partially randomize a character's stat gains once they level up, or if they must level down. All of the instructions are included in the header. Anyway, on to the script!

Features

  • Adds variation to an otherwise dull portion of the game!
  • Allows the programmer to set how much the stats can vary!
  • takes the base values from the database!

Screenshots

Since this script has no visual elements, a screenshot cannot be taken.

Script

RMXP Edition
Expand to see the code.


RMVX Edition
Expand to see the code.


Instructions
(These are taken from the VX Version. Stat and Character names vary in the XP version.)

Place this script above Main, and below the default scripts. (I realize this is obvious to most, but some people don't get it.)

To modify the basic starting stats of a character, you must edit the Actor_Stats array in the Stats module, using the following rules:
  • Line 1 is the stats of the first actor in the database. (Ralph is the default) Line 2 is the second actor (Ulrika), etc.
  • The statistics are in order on each line, where the first entry is maximum HP, entry 2 is maximum MP, entry 3 is Attack, entry 4 is Defense, entry 5 is Spirit, and entry 6 is Agility.

To modify the variation of an actor's statistics upon changing levels, you must edit the Stats hash in the Stats module, using the following rules:
  • The value in each entry is the maximum that the new stat may vary from the default increase or decrease defined for that stat in the Database. (Calculated by subtracting the default value of the new level from the default value of the original level) In other words, if the default change is three, and you have the variation set to two, then the stat can go up anywhere between one and five points.
  • When leveling up, a stat cannot go down, although it may also remain unchanged. This is because if the random number chosen by the script is negative when leveling up, the stat is left unchaged instead of being changed in the opposite direction of that intended.

If you modify the default actors within the game, you must also modify this script, so that the actors will all have their correct stats. If you add actors, you must add new lines to this script, and vice-versa if you delete actors. These new lines should be in the Stats hash within the Stats module.

FAQ

Due to some misunderstandings on what I meant by "partially randomize", I will attempt to explain in a little more detail. What I meant is that this script will take the default amount that a stat will go up when you level up (as defined in the database), and it will then use another value (defined by the user within the script) to change the amount that stat will go up. To give an example, if the default increase for Ralph's HP when going to level 2 is 67, and you set the amount it can vary to 26, then his HP can go up by anywhere between 41 and 93 points. It can be anything between the default increase minus the variance to the default increase plus the variance.

Credits and Thanks

Thanks to psiclone for making the original request, because otherwise I wouldn't have a script to share.

Also, thanks to SephirothSpawn for helping me clean up this script and make it much more efficient. (Although a bit more complex...)

Author's Notes

Version 2.0 was released to make the script more efficient. It features some changes in the operation of the script, and thus is a little more complex. If anyone would like to see the original script for the request, they can look here. Be warned, as this version is actually more complex, and much less efficient.

Terms and Conditions

  • This script is free to use in any noncommercial project. If you wish to use this script in a commercial (paid) project, please contact Glitchfinder at his website.
  • This script may only be hosted at the following domains:
    http://www.glitchkey.com
    http://www.hbgames.org
  • If you wish to host this script elsewhere, please contact Glitchfinder.
  • If you wish to translate this script, please contact Glitchfinder. He will need the web address that you plan to host the script at, as well as the language this script is being translated to.
  • The script header must remain intact at all times.
  • Glitchfinder remains the sole owner of this code. He may modify or revoke this license at any time, for any reason.
  • Any code derived from code within this script is owned by Glitchfinder, and you must have his permission to publish, host, or distribute his code.
  • This license applies to all code derived from the code within this script.
  • If you use this script within your project, you must include visible credit to Glitchfinder, within reason.

_________________

Just call me Glitch.


Last edited by Glitchfinder on Fri Mar 18, 2011 2:37 am, edited 8 times in total.

Top Top
Profile      
 

    ikos
  Sun Jul 13, 2008 4:57 am
User avatar
Member


Location: In Ohio, missing England.
What do you mean by "partially randomize"?
It's a little distracting. Do you mean if follows some path from the database's assigned values? Please elaborate, I might be interested. :D


Top Top
Profile      
 

    SephirothSpawn
  Sun Jul 13, 2008 7:55 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
I went to post something last night, but never finished it. I have a few comments/suggestions to greatly improve the way this script works.

I could go through all your code, and comment about alot of things you have done, but that wouldn't be as helpful. I honestly hope you take the advice below and greatly revise your code. If you wish to here my thoughts on your original code, I can share a few thoughts over PM. I am not trying to be rude, but I see potential and would just like to help.



To start off, lets re-think the script. You are going to be randomizing stat gains each level, with the option to set the random values for each actor and each stat. Now, this is going to be very repetitive unless we use some quick code blocks to search through efficient organized data. First, since we will be customizing it for each actor for each stat, arrays really aren't the way to go. We should use a multi-dimension hash instead. I also created a constant to hold the each stat name we will be using in the script (this will later serve for loop patterns).

Expand to see the code.


Now, we might as well create a method in this module to get the random stat gain for each actor in each stat. This will simply code later.
Expand to see the code.

(The above begin, rescue code just is an error catcher in case someone defines something wrong)

Now, how about the stat gains per level. The best way for this is to create an instance variable in each Game_Actor class (in your previous version, you modified a constant, something you should never do mid-code. Plus, that would not have saved if your game was reloaded or reset). To add this instance, we will create it upon creation of all actors. I suggest a hash, with the keys being the stat names and values being an array of values gain each level. We can add and remove these values for each level up.

Expand to see the code.


Now, before we get to the stat reading, lets just finish the gaining stats when we level_up and level_down. We will use our module method here for adding a random value to our stat hash, and removing the last bonus of each array for each stat when leveling down. So our stat gains hash will look like:
Expand to see the code.



So here is our code:
Expand to see the code.


So now all we have to do for each stat is add our stat gain sum for each stat gain. Now, arrays don't have a sum method, so we have to create one. There is one in the MACL 2.3, so we can just use that.
Expand to see the code.



Ok, now, we just need to add these to each stat total. An example of the first one can be done below.
Expand to see the code.



Now put it all together, do that for each stat (or more if you wish). If you wish to do this and need any help, just ask.

I look forward to seeing a completed product. :)

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Glitchfinder
  Sun Jul 13, 2008 6:42 pm
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
Well, as you just proved, I am still learning to code. First off, I was never really sure what a hash is. Would you be able to explain that in easier terms than the help files do? Next, I greatly appreciate the help, and, as soon as I can figure out what all of your suggestions do, I'll try to incorporate them. Thanks! (I just realized that tutorials on hashes/arrays/other complicated and semi-complicated ruby would be helpful to new scripters...)

Edit: I think I'm figuring out the hashes. It looks similar to arrays, in that it stores data, just with a different format. (And it appears to store arrays as well...) I'm also not sure what your purpose was in keeping some of my old methods, like the levelup or leveldown ones. From what I can tell, you pretty much eliminated any need for them.

Edit2: I just tried to put it all together, and realized you were writing for RMXP. Also, when I modified the other parts to work with rmvx, the MACL's definition of a sum for arrays turned up with a nil:NilClass error.

_________________

Just call me Glitch.


Last edited by Glitchfinder on Sun Jul 13, 2008 7:21 pm, edited 1 time in total.

Top Top
Profile      
 

    SephirothSpawn
  Sun Jul 13, 2008 8:35 pm
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
A hash is just like an array, but instead of the indexing being based of integers that go from 0 to x, the indexing is based off any Ruby object.

Array = [object, object, object]
Hash = {object => object, object => object, object => object}

Array = [object1, object2, object3]
Hash = {0 => object1, 1 => object2, 2 => object3}

Hashes are extremely useful when creating data for existing objects like the $data and $game classes. Hashes also have a .default method, which instead of returning nil when you try to read from a non-defined index, it will return the default. For instance:
Expand to see the code.


Not sure what you mean by "I'm also not sure what your purpose was in keeping some of my old methods, like the levelup or leveldown ones. From what I can tell, you pretty much eliminated any need for them." We still need these methods to know when we level up and level down.

I didn't explain one thing, the alias_method. When you call alias_method, you are renaming an existing method.

alias_method :new_method_name, :old_method_name

This allows us to add processing before an existing method call and/or after an existing method call.

Lets say you write a method that returns a name that is passed:
Expand to see the code.


Well, what if we want to add () after it for whatever reason. We alias the method and proceed from there.
Expand to see the code.


Our return_string method will now be called as it always has, but the original return_string method will be called from our new method now.

When I did it with that level_up and level_down method, we want to keep everything that happens in the original level_up/down methods, just add to it. By using the alias_method, more scripts can work together without conflict.

Everything should work just fine in VX. Your code should look something like this:
Expand to see the code.


I have included everything you need right there. You just need to finish your remaining stats you wish to include. Just make sure you remember to alter your Stat_Names = ['hp', 'sp', 'str', 'dex', 'int', 'agi'] constant. Again, let me know if you need any help.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Glitchfinder
  Mon Jul 14, 2008 2:38 am
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
Well, I'm trying the script you gave me, and as soon as I entered the stats I wanted, it started to give me the nil:NilClass error for the sum method you added to the array class. I absolutely hate that error, as it never seems to mean what it actually says. Anyway, heres the modified version of the script you gave me. (Also, I already knew what aliasing was. I just wasn't sure exactly how the hashes functioned. I meant that it seemed like you were eliminating the need for most of the levelup and leveldown functions I had written, and that all you really needed were the changes to the level variable. I looked closer after you posted, and realized I had made some mistakes in my assumptions)

Modified version of your code.

_________________

Just call me Glitch.


Last edited by Glitchfinder on Mon Jul 14, 2008 4:25 am, edited 1 time in total.

Top Top
Profile      
 

    psiclone
  Mon Jul 14, 2008 5:19 am
User avatar
Member

Got a little slight problem with your modified version. I get an error that says "undefined method: 'sum' for nil class"

Any ideas?


Top Top
Profile      
 

    Glitchfinder
  Mon Jul 14, 2008 6:01 am
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
psiclone wrote:
Got a little slight problem with your modified version. I get an error that says "undefined method: 'sum' for nil class"

Any ideas?


That's what I was trying to figure out. That error is a catchall for other errors. It has even told me that things like +, -, * and / are undefinded. Once, it even told me that nil was undefined.

_________________

Just call me Glitch.


Top Top
Profile      
 

    SephirothSpawn
  Mon Jul 14, 2008 6:06 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
    n += @stat_gains[hp].sum
should be

    n += @stat_gains['hp'].sum

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Glitchfinder
  Mon Jul 14, 2008 6:11 am
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
Cool, thanks! I'll update the first post a little later with the newer version! (as well as a better description)

Edit: I'm trying to make the script take the default stat gain for the current level change (as specified by the game builder in the database), and then use that to modify the stat changes as you've defined them. I was hoping that it could use the following formula:

default_gain + Stats::Radom_Gain - Stats::Random_Gain, where there is no change if the random gain is <= 0, and the change is recorded as 0.

Unfortunately, I'm having quite a bit of trouble figuring out how to make it work in an even partially efficient manner.

_________________

Just call me Glitch.


Last edited by Glitchfinder on Mon Jul 14, 2008 6:44 am, edited 1 time in total.

Top Top
Profile      
 

    SephirothSpawn
  Mon Jul 14, 2008 9:24 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Not sure what you are asking...

Algebraically speaking... a + b - b = a

And the random gains are from 0 to your random game number you set. So it should never be less than 0, but the 0s will be required when leveling down.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    psiclone
  Mon Jul 14, 2008 2:20 pm
User avatar
Member

Heh, I've found the error about that 'sum'.. at:
Expand to see the code.


And at the beginning of the code, you've got:

Expand to see the code.


You don't have 'mp' defined or whatever it is. I changed the 'mp' to 'sp' in the first block, and it works just fine.. to a degree, unless I don't get the random part. It's not really doing the random within the number I specify, it seems to be adding it's own numbers different times. One point level 2 added 1 'hp', then level 3 added 23, then the next time I ran a test level 2 added 14 hp, level 3 added 1.. not sure what to do next, I can't write code to save my life, but I feel I can read it just fine.

I hope that finding that error in the 'mp' section helped you since I can't figure out the rest..

EDIT: Well, I figured out the 'random' part, I just put the random numbers in the wrong section, and it works just fine.

EDIT2: I don't get what 'default actor setup' is.. it doesn't seem to do anything, no matter what number(s) I put in there.

EDIT3: And.. random gains also seems to go backwards, too.. even on a level up. I started with 9 atk, but upon leveling, I had 7..


Last edited by psiclone on Mon Jul 14, 2008 2:52 pm, edited 1 time in total.

Top Top
Profile      
 

    Glitchfinder
  Mon Jul 14, 2008 5:36 pm
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
SephirothSpawn wrote:
Not sure what you are asking...

Algebraically speaking... a + b - b = a

And the random gains are from 0 to your random game number you set. So it should never be less than 0, but the 0s will be required when leveling down.


Since b is a random number, it is more likely to be a + b - c = d. What I was trying to do is calculate how much the predefined change was for that levelup, and then add that into the formula I just gave you as a. (I would also have an if statement thatr would catch it so that if a stat change would be negative, it is 0 instead)

psiclone wrote:
You don't have 'mp' defined or whatever it is. I changed the 'mp' to 'sp' in the first block, and it works just fine.. to a degree, unless I don't get the random part. It's not really doing the random within the number I specify, it seems to be adding it's own numbers different times. One point level 2 added 1 'hp', then level 3 added 23, then the next time I ran a test level 2 added 14 hp, level 3 added 1.. not sure what to do next, I can't write code to save my life, but I feel I can read it just fine.

I hope that finding that error in the 'mp' section helped you since I can't figure out the rest..

EDIT: Well, I figured out the 'random' part, I just put the random numbers in the wrong section, and it works just fine.

EDIT2: I don't get what 'default actor setup' is.. it doesn't seem to do anything, no matter what number(s) I put in there.

EDIT3: And.. random gains also seems to go backwards, too.. even on a level up. I started with 9 atk, but upon leveling, I had 7..


Well, the only code in this thread that functions at any level I like is the one in the first post. If I get these suggestions working, then I will add them into that code. And abbout the random portion, that is what I'm hoping to fix in the update I'm working on.

Edit: I've just updated the script with SephirothSpawn's suggestions, as well as an edit of my own. It should function properly again. It's all in the first post. Alos, SephirothSpawn, I would greatly appreciate your suggestions for the original script, as well. Finally, I'm planning to add a new version for RMXP, that uses the RMXP formulae.

_________________

Just call me Glitch.


Last edited by Glitchfinder on Tue Jul 15, 2008 7:19 pm, edited 1 time in total.

Top Top
Profile      
 

    Glitchfinder
  Thu Mar 17, 2011 2:40 am
BEWARE: Glitchfinder's sense of humor sucks.
User avatar
Staff

Party Mascot

Location: Approximately 93 million miles from Sol.
All right, so I just updated this script to a new version. Enjoy!

_________________

Just call me Glitch.


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 


Who is online

Users browsing this forum: No users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

cron
We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group