Jump to content
  • 0
Sign in to follow this  
Yugosh

Req> NPC Gatcha

Question

a simple npc ex.

you give me Poring coin and the machine will random and give you anything

 

ex reward :

Apple , blue pot , red pot , or anything.

 

thanks for help master. +1 :wub:

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Here's a version that pulls a "rare" item from the array .rare_id and determines whether or not you have received it, defined by the chance allocated after it (format: <item constant/ID>, <chance>):

 

prontera,147,174,5	script	Odd Fellow::randomstuff	1_M_WIZARD,{	/*-----------------------------------------------------	Script	-----------------------------------------------------*/	mes .npc_name$;	mes "Hello there! For "+ .coin_amount +" "+ getitemname(.coin_id) +", I'll give you a random item!";	next;		mes .npc_name$;	if (countitem(.coin_id) < .coin_amount) {		mes "Come back when you have "+ .coin_amount +" "+ getitemname(.coin_id) +"!";		close;	}	mes "Would you like to give it a try?";	next;		if (select("Sure, why not!:No, thanks") == 2) {		mes .npc_name$;		mes "Okay, come back if you change your mind!";		close;	}		// Generate random prize ID	do {		.@prize_id = rand(.prize_min_id, .prize_max_id);	} while (getitemname(.@prize_id) == "null");		// Determine index location of rare item to randomly pick from	do {		.@rare_index = rand(getarraysize(.rare_id));	} while (.@rare_id % 2);		// Determine whether or not to change prize to rare item	if (!rand(.rare_id[.@rare_index + 1])) {		.@prize_id = .@rare_id;	}		mes .npc_name$;	mes "Here you go! You got "+ .prize_amount +" "+ getitemname(.@prize_id) +"!";		getitem .@prize_id, .prize_amount;	close;			/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.npc_name$ = "[Odd Fellow]";		.coin_id = Poring_Coin;	// Coin constant/ID		.coin_amount = 1;		// Count amount required		.prize_min_id = 501;	// Prize minimum ID		.prize_max_id = 30000;	// Prize maximum ID		.prize_amount = 1;		// Prize amount rewarded				// Rare item constants/IDs and chance in x to obtain rare item (default: 5 [20%])		setarray .rare_id[0], Apple, 10, Red_Potion, 20, Jellopy, 30, Fluff, 4, Clover, 5;		end;}

Share this post


Link to post
Share on other sites
  • 0
prontera,150,150,0	script	Sample	100,{	if ( !countitem( 7539 ) ) {		mes "You need 1 " +getitemname( 7539 )+ " in order to talk to me";		close;	}	if ( select( "Here have my " +getitemname( 7539 )+ ":Nevermind" ) - 1 ) close;	.@r = rand(501, 700);	if ( getitemname( .@r ) != "null" ) {		delitem 7539, 1;		getitem .@r, 1;	}	close;}

Share this post


Link to post
Share on other sites
  • 0

 

prontera,150,150,0	script	Sample	100,{	if ( !countitem( 7539 ) ) {		mes "You need 1 " +getitemname( 7539 )+ " in order to talk to me";		close;	}	if ( select( "Here have my " +getitemname( 7539 )+ ":Nevermind" ) - 1 ) close;	.@r = rand(501, 700);	if ( getitemname( .@r ) != "null" ) {		delitem 7539, 1;		getitem .@r, 1;	}	close;}

 

Might be a good idea to enclose that set for .@r in a do..while loop; if the item name does end up being "null", the user's item is taken and doesn't get anything lol.

 

 

do {	.@r = rand(501, 700);} while (getitemname(.@r) != "null");

Share this post


Link to post
Share on other sites
  • 0

 

 

prontera,150,150,0	script	Sample	100,{	if ( !countitem( 7539 ) ) {		mes "You need 1 " +getitemname( 7539 )+ " in order to talk to me";		close;	}	if ( select( "Here have my " +getitemname( 7539 )+ ":Nevermind" ) - 1 ) close;	.@r = rand(501, 700);	if ( getitemname( .@r ) != "null" ) {		delitem 7539, 1;		getitem .@r, 1;	}	close;}

 

Might be a good idea to enclose that set for .@r in a do..while loop; if the item name does end up being "null", the user's item is taken and doesn't get anything lol.

 

 

do {	.@r = rand(501, 700);} while (getitemname(.@r) != "null");

 

how about the chance?

rare item 5% like that?

 

EDIT :

not work perfectly

Edited by Yugosh

Share this post


Link to post
Share on other sites
  • 0

Here, give this a try:

 

prontera,147,174,5	script	Odd Fellow::randomstuff	1_M_WIZARD,{	/*-----------------------------------------------------	Script	-----------------------------------------------------*/	mes .npc_name$;	mes "Hello there! For "+ .coin_amount +" "+ getitemname(.coin_id) +", I'll give you a random item!";	next;		mes .npc_name$;	if (countitem(.coin_id) < .coin_amount) {		mes "Come back when you have "+ .coin_amount +" "+ getitemname(.coin_id) +"!";		close;	}	mes "Would you like to give it a try?";	next;		if (select("Sure, why not!:No, thanks") == 2) {		mes .npc_name$;		mes "Okay, come back if you change your mind!";		close;	}		do {		.@prize_id = rand(.prize_min_id, .prize_max_id);	} while (getitemname(.@prize_id) == "null");		mes .npc_name$;	mes "Here you go! You got "+ .prize_amount +" "+ getitemname(.@prize_id) +"!";			delitem .coin_id, .coin_amount;	getitem .@prize_id, .prize_amount;	close;			/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.npc_name$ = "[Odd Fellow]";		.coin_id = Poring_Coin;	// Coin ID		.coin_amount = 1;		// Count amount required		.prize_min_id = 501;	// Prize minimum ID		.prize_max_id = 30000;	// Prize maximum ID		.prize_amount = 1;		// Prize amount rewarded		end;}
Edited by Mumbles
Added missing 'delitem'.

Share this post


Link to post
Share on other sites
  • 0

 

Might be a good idea to enclose that set for .@r in a do..while loop; if the item name does end up being "null", the user's item is taken and doesn't get anything lol.

 

 

do {	.@r = rand(501, 700);} while (getitemname(.@r) != "null");

 

The delitem command is triggered when the item is not null otherwise it does nothing. though i can say a do while loop is a better approach :P

Share this post


Link to post
Share on other sites
  • 0

The delitem command is triggered when the item is not null otherwise it does nothing. though i can say a do while loop is a better approach :P

 

 

Ah, I didn't see that (I just skimmed tbh). But yeah, a do...while seemed more efficient, to me.

 


 

@@Yugosh:

After reviewing what I posted earlier, I realised I forgot to add a 'delitem' in there for the Poring Coin. Please refer to my previous post for an updated version.

 

Regarding a chance to get a rare item, you would need to create an array containing a set of rare items and add a randomizer for it.

Share this post


Link to post
Share on other sites
  • 0

 

Here, give this a try:

 

prontera,147,174,5	script	Odd Fellow::randomstuff	1_M_WIZARD,{	/*-----------------------------------------------------	Script	-----------------------------------------------------*/	mes .npc_name$;	mes "Hello there! For "+ .coin_amount +" "+ getitemname(.coin_id) +", I'll give you a random item!";	next;		mes .npc_name$;	if (countitem(.coin_id) < .coin_amount) {		mes "Come back when you have "+ .coin_amount +" "+ getitemname(.coin_id) +"!";		close;	}	mes "Would you like to give it a try?";	next;		if (select("Sure, why not!:No, thanks") == 2) {		mes .npc_name$;		mes "Okay, come back if you change your mind!";		close;	}		do {		.@prize_id = rand(.prize_min_id, .prize_max_id);	} while (getitemname(.@prize_id) == "null");		mes .npc_name$;	mes "Here you go! You got "+ .prize_amount +" "+ getitemname(.@prize_id) +"!";			delitem .coin_id, .coin_amount;	getitem .@prize_id, .prize_amount;	close;			/*-----------------------------------------------------	Configuration	-----------------------------------------------------*/	OnInit:		.npc_name$ = "[Odd Fellow]";		.coin_id = Poring_Coin;	// Coin ID		.coin_amount = 1;		// Count amount required		.prize_min_id = 501;	// Prize minimum ID		.prize_max_id = 30000;	// Prize maximum ID		.prize_amount = 1;		// Prize amount rewarded		end;}

 

Work Perfectly so how to set the custom prize?

in here have min and max

so ho how to change this prize apple chance 10%?

thanks master

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...
Sign in to follow this  

×
×
  • Create New...

Important Information

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