Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Item Random Stat Error

Junior Spellweaver
Joined
Sep 2, 2016
Messages
102
Reaction score
2
Hello. I'm korean.
While granting random Watk to an order,An error has occurred.
The Watk is not rising.
Please see the source below to see what the problem is
Or can I add it randomly in different ways?
Please tell me how
help me!
Sorry for my bad English
Speak :(


ItemInformation.java

case 2047814:
nEquip.setStr((short) (nEquip.getStr() + 3));
nEquip.setInt((short) (nEquip.getInt() + 3));
nEquip.setDex((short) (nEquip.getDex() + 3));
nEquip.setLuk((short) (nEquip.getLuk() + 3));
nEquip.setWatk((short) (nEquip.getMatk() + Randomizer.ScrollRand(9, 11)));break;

Randomizer.java
public static int ScrollRand(int min, int max) {
int a = 0;
do {
a = nextInt(max + 1);
}
while (a >= min);
return a;
}
 
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
The Watk is not rising.
Please see the source below to see what the problem is
I bolded
Code:
[B]ItemInformation.java[/B]
case 2047814:
nEquip.setStr((short) (nEquip.getStr() + 3));
nEquip.setInt((short) (nEquip.getInt() + 3));
nEquip.setDex((short) (nEquip.getDex() + 3));
nEquip.setLuk((short) (nEquip.getLuk() + 3));
nEquip.setWatk((short) (nEquip.get[B]Matk()[/B] + Randomizer.ScrollRand(9, 11)));break;

[B]Randomizer.java
[/B]public static int ScrollRand(int min, int max) {
int a = 0;        
do {            
a = nextInt(max + 1);        
} 
while ([B]a >= min[/B]);
return a;
}
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
Unrelated to the working / not working, but,
public static int ScrollRand(int min, int max) {
int a = 0;
do {
a = nextInt(max + 1);
}
while (a >= min);
return a;
}
This function basically keeps rolling a random number, until the result is lower than a specific amount.
This is equivalent to just rolling once a random number that's lower than said amount: you could change this

nEquip.setWatk((short) (nEquip.getMatk() + Randomizer.ScrollRand(9, 11)));

to this

nEquip.setWatk((short) (nEquip.getWatk() + Randomizer.nextInt(9)));




On the other hand, if your intent is to generate a random number between two, I'd still suggest you avoid using a cycle like that, as you can't know for how long the random generator will keep running again and again.

You can still make it work without that cycling.

Considering that nextInt(y) gives you a number that's between 0 (included) and y (excluded), and if we consider x as your min and y as the max,

x + nextInt(y) will give you a number between x (included) and x+y (excluded).

At this point, to fix the max value,

x + nextInt(y - x) will give you the number between x and y (with y excluded. If you want it included, just change nextInt(y - x) to nextInt(y - x + 1) ).
 
Last edited:
Upvote 0
Junior Spellweaver
Joined
Sep 2, 2016
Messages
102
Reaction score
2
I bolded
Code:
[B]ItemInformation.java[/B]
case 2047814:
nEquip.setStr((short) (nEquip.getStr() + 3));
nEquip.setInt((short) (nEquip.getInt() + 3));
nEquip.setDex((short) (nEquip.getDex() + 3));
nEquip.setLuk((short) (nEquip.getLuk() + 3));
nEquip.setWatk((short) (nEquip.get[B]Matk()[/B] + Randomizer.ScrollRand(9, 11)));break;

[B]Randomizer.java
[/B]public static int ScrollRand(int min, int max) {
int a = 0;        
do {            
a = nextInt(max + 1);        
} 
while ([B]a >= min[/B]);
return a;
}
thank you :)



Unrelated to the working / not working, but,

This function basically keeps rolling a random number, until the result is lower than a specific amount.
This is equivalent to just rolling once a random number that's lower than said amount: you could change this

nEquip.setWatk((short) (nEquip.getMatk() + Randomizer.ScrollRand(9, 11)));

to this

nEquip.setWatk((short) (nEquip.getWatk() + Randomizer.nextInt(9)));




On the other hand, if your intent is to generate a random number between two, I'd still suggest you avoid using a cycle like that, as you can't know for how long the random generator will keep running again and again.

You can still make it work without that cycling.

Considering that nextInt(y) gives you a number that's between 0 (included) and y (excluded), and if we consider x as your min and y as the max,

x + nextInt(y) will give you a number between x (included) and x+y (excluded).

At this point, to fix the max value,

x + nextInt(y - x) will give you the number between x and y (with y excluded. If you want it included, just change nextInt(y - x) to nextInt(y - x + 1) ).

thank you :)
 
Upvote 0
Back
Top