NPC - Random item

Alexandria

New member
Messages
341
Points
0
Location
localhost
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.

 
@@Alexandria

How about something like this:

Code:
.@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;
 
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.

 
@@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;

.

 
Thank you! It's working.

Just last question.

If I want to add more items to 60% categorie, 30%  and 10% categorie, what do I have to do?

 
Code:
	.@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;
 
.@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;

 
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.

 
Oops yes, missing getarraysize

 
Code:
.@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;
 
Back
Top