• 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 [email protected],  607, 60,
						612, 10,
						611, 10,
						608, 10,
						678, 5,
						675, 5;
	set [email protected], getarraysize( [email protected] );
	for( set [email protected], 1; [email protected] < [email protected]; [email protected] += 2 ) {
		[email protected][[email protected]] = [email protected] + [email protected][[email protected]];
		[email protected] += [email protected][[email protected]];
	}
	[email protected] = rand( [email protected] +1 );
	for( set [email protected], 1; [email protected] < [email protected]; [email protected] += 2 )
		if( [email protected][[email protected]] > [email protected] )
			break;
	getitem [email protected][ [email protected] ], 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

  • 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now