Alexandria 53 Posted October 5, 2015 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. Quote Share this post Link to post Share on other sites
0 Winterfox 83 Posted October 5, 2015 @@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; 1 Alexandria reacted to this Quote Share this post Link to post Share on other sites
0 Alexandria 53 Posted October 6, 2015 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. Quote Share this post Link to post Share on other sites
1 Winterfox 83 Posted October 7, 2015 @@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; . 1 Alexandria reacted to this Quote Share this post Link to post Share on other sites
0 Alexandria 53 Posted October 7, 2015 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? Quote Share this post Link to post Share on other sites
0 Gerz 7 Posted October 7, 2015 (edited) :v edit! Edited October 7, 2015 by Gerz Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted October 7, 2015 .@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; Quote Share this post Link to post Share on other sites
0 Alexandria 53 Posted October 7, 2015 .@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; Quote Share this post Link to post Share on other sites
0 Garr 117 Posted October 7, 2015 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. Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted October 8, 2015 Oops yes, missing getarraysize Quote Share this post Link to post Share on other sites
0 Emistry 145 Posted October 8, 2015 .@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; 1 AnnieRuru reacted to this Quote Share this post Link to post Share on other sites
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