![]() |
item generator with percentage variable
I want learn how to make a javascript for an RPG where it generates and display a specific item, but the generation process is controlled by the percentage variable for items in certain category.
also, aside from the quality, and item type, it'd be nice if you could input a number in and it will also generate the item level from 3- to +3 (controlled by percentage) and display the number at the end modified by the aforementioned modifiers For example, it might look something like Enter 53, hit generate Common: .30 Rare: .10 Armor Category (gloves, shoes, chest): .50 Weapon Category (sword, shield): .49 -3: .60 0: .40 +3: .30 Generated item: Common Glove ilvl. 50 (53-3) Edit: Could anyone point me to where I might be able to learn how to make this? |
These forums are generally for helping to troubleshoot problematic code, not for freebies.
|
Quote:
|
You tell us the mathematical formulas you will use and we can tell you how to convert them into JavaScript code.
But without the math, there is no possible way for us to guess what you are trying to do. |
Code:
<script type = "text/javascript">like the probability of generating common is 60% or the probability of generating sword is 50% I want to add the probability to both rarity and weapon var also, is it possible to assign a universal probability of being generated to a group of items? |
Quote:
I will show you *one* example: Code:
var rarityNum = Math.floor( 1 + Math.random() * 100 );Code:
var rarityNum = Math.floor( 1 + Math.random() * 100 );rarityNum, as I coded it, will be a number form 1 to 100. So also as coded, there is a 5% chance you will get "rare", 30% chance for "uncommon", and 65% chance for "common". |
Quote:
Code:
<script type="text/javascript"> |
I will blame it on my eyes. Better than blaming it on my old brain. (Never mind that the eyes are roughly the same age as the brain.)
|
Quote:
Code:
// helper function: random slot from array grabber:EDIT: we can indeed calculate many-item probabilities using existing data and a little math. buckle your seatbelt: Code:
Array.prototype.random=function random(){edit2: if you are using it a lot (hundreds of times or more) it might be worth it to pre-calc all the combined probabilities for instant lookup instead of on-demand calculation: Code:
Array.prototype.counts=function(name){ |
But a big problem with this approach is the *granularity*.
Just to pick the example you used, if we wanted "rare" to be 1%, and still assuming the same 3 weapons (4 occurrences), we would need 20 values in the rarity array. And *still* combined.rare.sword would be 2% instead of 1%. And so on. I think I would opt for a much simpler yet more flexible system: Code:
var weapons = {Completely flexible: You can decide what "rare" means on a per-weapon basis *and* you can easily see the distribution *and* you can easily change it. Changing the distribution with RndMe's dual array system might turn into a real challenge to get the numbers you actually want. |
Quote:
you can easily get to the single-percent level. if you want 1% rare and the rest to be the same, the only piece you need to touch is the rarity array. i'd imagine you want 75 common, 24 uncommon, and 1 rare: Code:
rarity= String([ |
And you really thing that is simpler and easier to understand than my table-based scheme?
Hmmm...maybe now I understand some of your coding better. No, that was a joke. Your coding is top notch. But I do think that, in this case, your solution is too esoteric. Ehhh...one man's meat is another man's poisson distribution. |
Quote:
with an iterative counter, you let the JS do the work. i admit the tokens are a little simplistic for precise or complex calculations, but for many simple problems, it's a workable design pattern. you can use an object instead of an array, you would have to sum all the values in the object, and then you have the same info as my item counter: Code:
|
I like this better.
Code:
//new data structure:But it still requires the user to understand the combinatorial math. Not at all difficult, but probably too much for a lot of the newbies we get here. |
A simple remark for @rnd me : Array(75).join("common,") build a string with 74 (and not 75 !) common, in the intervals of the 75 leer array's elements !
|
| All times are GMT +1. The time now is 03:15 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.