Jump to content
  • 0
Alexandria

NPC - Random item

Question

Hello there.

 

I made a quest npc but I'm missing the last code.

 

The npc will give you 1 item of follow items: 5474, 5137, 5766, 5786, 5074 and 5132

 

But the player will have 60% to get: 5474 or 5137

 

30% to get: 5766 or 5786

 

and 10% to get: 5074 and 5132

 

with a broadcast: announce "PLAYERNAME has been rewarded with ITEMXname;bc_all;"

 

Any help would be awesome! Thank you.

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

@@Alexandria

 

How about something like this:

 

.@chance = rand( 1,100 );if( .@chance <= 60 ) {	.@reward = 0;} else if( .@chance <= 90 ) {	.@reward = 2;} else {	.@reward = 4;}.@reward = .rewardIds[ ( .@reward + rand( 2 ) ) ];getitem .@reward, 1; announce strcharinfo( PC_NAME ) + " has been rewarded with " + getitemname( .@reward ) + "!", bc_all; end; OnInit:.rewardIds = 5474, 5137, 5766, 5786, 5074, 5132;

Share this post


Link to post
Share on other sites
  • 0

Thank you for helping me but I am having this error in console:

 

 

    line 20 column 18 parse_line: need ';'    17:		 end;    18:    19: OnInit:*   20: .rewardIds = 5474, 5137, 5766, 5786, 5074, 5132;	    ~~~~~~~~~~~~~~~~~^ 


Do you know how can I fix it? Thank you.

Share this post


Link to post
Share on other sites
  • 1

@@Alexandria

 

Sure, just a stupid mistake i made

	.@chance = rand( 1,100 );	if( .@chance <= 60 ) {		.@reward = 0;	} else if( .@chance <= 90 ) {		.@reward = 2;	} else {		.@reward = 4;	}	.@reward = .rewardIds[ ( .@reward + rand( 2 ) ) ];	getitem .@reward, 1;	announce strcharinfo( PC_NAME ) + " has been rewarded with " + getitemname( .@reward ) + "!", bc_all;	end; OnInit:	setarray .rewardIds, 5474, 5137, 5766, 5786, 5074, 5132;

 

.

Share this post


Link to post
Share on other sites
  • 0
	.@chance = rand( 1,100 );	for (.@i=0; .@i < getarraysize(.chances); .@i++)		if (.chances[.@i] <= .@chance)			break;	if (.@i == getarraysize(.chances))		end;			.@reward = getd(".rewardIds_"+.chances[.@i]+"["+rand(getd(".rewardIds_"+.chances[.@i]))+"]");	getitem .@reward, 1;	announce strcharinfo( PC_NAME ) + " has been rewarded with " + getitemname( .@reward ) + "!", bc_all;	end; OnInit:	setarray .chances, 1, 60, 90, 100;	//Arranged in Ascending Order	setarray .rewardIds_1, 7227;	setarray .rewardIds_60, 5474, 5137;	setarray .rewardIds_100, 5766, 5786;	setarray .rewardIds_90, 5074, 5132;	end;

Share this post


Link to post
Share on other sites
  • 0

 

	.@chance = rand( 1,100 );	for (.@i=0; .@i < getarraysize(.chances); .@i++)		if (.chances[.@i] <= .@chance)			break;	if (.@i == getarraysize(.chances))		end;			.@reward = getd(".rewardIds_"+.chances[.@i]+"["+rand(getd(".rewardIds_"+.chances[.@i]))+"]");	getitem .@reward, 1;	announce strcharinfo( PC_NAME ) + " has been rewarded with " + getitemname( .@reward ) + "!", bc_all;	end; OnInit:	setarray .chances, 1, 60, 90, 100;	//Arranged in Ascending Order	setarray .rewardIds_1, 7227;	setarray .rewardIds_60, 5474, 5137;	setarray .rewardIds_100, 5766, 5786;	setarray .rewardIds_90, 5074, 5132;	end;

 

Thank you, I'm wondering why did you add this line: setarray .rewardIds_1, 7227;

Share this post


Link to post
Share on other sites
  • 0

Hmm, wouldn't this part

.@reward = getd(".rewardIds_"+.chances[.@i]+"["+rand(getd(".rewardIds_"+.chances[.@i]))+"]");

in case of, let's say, 59, return

.@reward = getd(".rewardIds_60["+rand(5474)+"]");

Seems to miss getarraysize, even though I'm not really sure if it'll work with getd.

Share this post


Link to post
Share on other sites
  • 0
.@rate = rand( 100 );if ( .@rate <= 10 ) {	.@item = F_Rand( 5074,5132 );}else if ( .@rate <= 40 ) {	.@item = F_Rand( 5766,5786 );}else else {	.@item = F_Rand( 5474,5137 );}getitem .@item,1;announce strcharinfo(0)+" has been rewarded with "+getitemname( .@item )+";bc_all;

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.