Random item with chance request

nuna

New member
Messages
136
Points
0
Emulator
Hello may i request for some script like

for example

npc to claim item but in random chance.

list of items,qty / Chance

607,5         50%

608,6         52%

678,4         50%

672,1         2%

something like that.

Thank you in advance

 
here, I made this for you:

<map>,<x>,<y>,<dir> script <name> <sprite>,{

mes("Hi there.");
mes("Can I help you?");
next();

select("claim reward");

mes("...");
next();

for (.@i = 0; .@i < .reward_len; .@i += 3) {
if (rand(100) < .reward[.@i + 2]) {
getitem(.reward[.@i], .reward[.@i + 1]);
mesf("You obtained %i %s.", .reward[.@i + 1], getitemname(.reward[.@i]));
.@reward = true; // got at least one reward
next();
}
}

if (.@reward != true) {
mes("It seems you're out of luck.");
next();
}

mes("Come back anytime!");
close;

OnInit:
setarray(.reward[0],
//ID,QTY,%
607, 5, 50,
608, 6, 52,
678, 4, 50,
672, 1, 2);

.reward_len = getarraysize(.reward);
}


hope it helps

UPDATE: added reward_len (sorry, forgot that)

 
Last edited by a moderator:
here, I made this for you:

<map>,<x>,<y>,<dir> script <name> <sprite>,{

mes("Hi there.");
mes("Can I help you?");
next();

select("claim reward");

mes("...");
next();

for (.@i = 0; .@i < .reward_len; .@i += 3) {
if (rand(100) < .reward[.@i + 2]) {
getitem(.reward[.@i], .reward[.@i + 1]);
mesf("You obtained %i %s.", .reward[.@i + 1], getitemname(.reward[.@i]));
.@reward = true; // got at least one reward
next();
}
}

if (.@reward != true) {
mes("It seems you're out of luck.");
next();
}

mes("Come back anytime!");
close;

OnInit:
setarray(.reward[0],
//ID,QTY,%
607, 5, 50,
608, 6, 52,
678, 4, 50,
672, 1, 2);

.reward_len = getarraysize(.reward);
}


hope it helps

UPDATE: added reward_len (sorry, forgot that)

Hello sir thank you but how can i make it only 1 can get?

 
You want the player to get only one item? Your percents make a total of 154% ...

list of items,qty / Chance

607,5         50%

608,6         52%

678,4         50%

672,1         2%

Try this:

Code:
.@rnd = rand(154);

if (.@rnd < 50) {
	getitem(607, 5);
} else if (.@rnd < 102) {
	getitem(608, 6);
} else if (.@rnd < 152) {
	getitem(678, 4);
} else {
	getitem(672, 1);
}
 
You want the player to get only one item? Your percents make a total of 154% ...

list of items,qty / Chance

607,5         50%

608,6         52%

678,4         50%

672,1         2%

Try this:

.@rnd = rand(154);

if (.@rnd < 50) {
getitem(607, 5);
} else if (.@rnd < 102) {
getitem(608, 6);
} else if (.@rnd < 152) {
getitem(678, 4);
} else {
getitem(672, 1);
}
Yes i only want player to get any 1 items of the list with chance sir thanks a lot

 
well I assumed it was more than one because your percentage exceeds 100%, which implies you want to give 1~2 (154% ➜ 1.54) items

 
Back
Top