Jump to content
  • 0
nuna

Random item with chance request

Question

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

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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)

Edited by meko

Share this post


Link to post
Share on other sites
  • 0

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?

Share this post


Link to post
Share on other sites
  • 0

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);
}

Share this post


Link to post
Share on other sites
  • 0

 

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

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.