Jump to content
  • 0
nuna

Add announce on random box

Question

hello how can i add announce on specific item if get and make it have amount value?

function	script	boxrandom	{
	setarray .@reward,  607, 60,
						612, 10,
						611, 10,
						608, 10,
						678, 5,
						675, 5;
	set .@size, getarraysize( .@reward );
	for( set .@i, 1; .@i < .@size; .@i += 2 ) {
		.@percent[.@i] = .@total + .@reward[.@i];
		.@total += .@reward[.@i];
	}
	.@r = rand( .@total +1 );
	for( set .@i, 1; .@i < .@size; .@i += 2 )
		if( .@percent[.@i] > .@r )
			break;
	getitem .@reward[ .@i-1 ], 1;
	end;
}

how can i add also on what amount per item? example since 612 - id name and 10 is the chance. please help me to make it 612,1->amount,10->chance

Example i want the id number 678 if get to be announce" char name got 1x Poison bottle "

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Try this:

function	script	loot_crate	{
	.@index = getarrayindex(getarg(0));
	.@size = getarraysize(getarg(0));

	for (.@i = .@index; .@i < .@size - .@index; .@i += 3) {
		for (.@e = 0; .@e < getelementofarray(getarg(0), .@i + 2); ++.@e) {
			.@loot[.@count++] = .@i;
		}
	}

	.@rand = .@loot[rand(.@count)];
	getitem(getelementofarray(getarg(0), .@rand), getelementofarray(getarg(0), .@rand + 1));

	announce(sprintf("Player %s obtained %ix %s from a loot crate!"
			strcharinfo(PC_NAME),
			getelementofarray(getarg(0), .@rand + 1),
			getitemname(getelementofarray(getarg(0), .@rand))),
		getarg(1, bc_all));

	return true;
}

 

And in your NPC do something like this:

MAP,X,Y,DIR	script	NAME	SPRITE,{

	mes("Hello");
	next();
	loot_crate(.rewards, bc_all);
	mes("Goodbye!");
	close;

OnInit:
	setarray(.rewards,
		// Item,           Amount, Chance
		Yggdrasilberry,    1,      60,
		Portable_Furnace,  1,      10,
		Spectacles,        1,      10,
		Seed_Of_Yggdrasil, 1,      10,
		Poison_Bottle,     1,      5,
		Silver_Coin,       1,      5);
}

 

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.