<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Random_item_reward</title><link>https://sourceforge.net/p/rathena/wiki/Random_item_reward/</link><description>Recent changes to Random_item_reward</description><atom:link href="https://sourceforge.net/p/rathena/wiki/Random_item_reward/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 20 Feb 2023 05:00:11 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/rathena/wiki/Random_item_reward/feed" rel="self" type="application/rss+xml"/><item><title>Random_item_reward modified by Brynner</title><link>https://sourceforge.net/p/rathena/wiki/Random_item_reward/</link><description>&lt;div class="markdown_content"&gt;&lt;hr/&gt;
&lt;p&gt;title: Random item reward&lt;br/&gt;
permalink: /Random_item_reward/&lt;/p&gt;
&lt;hr/&gt;
&lt;h2 id="description"&gt;Description&lt;/h2&gt;
&lt;p&gt;Rewards the player with a random item from a list.&lt;/p&gt;
&lt;h2 id="examples"&gt;Examples&lt;/h2&gt;
&lt;h3 id="method-1-item-group"&gt;Method 1: Item Group&lt;/h3&gt;
&lt;p&gt;By using item group, item chance to be gained can be decided. First, must decide ID for item group, edit the &lt;a class="" href="https://github.com/rathena/rathena/blob/master/db/const.txt" rel="nofollow"&gt;const.txt&lt;/a&gt; file. Example,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;IG_TestRandomItem  392&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Maximum Item Group ID is 399 as defined in &lt;a class="" href="https://github.com/rathena/rathena/blob/master/src/map/itemdb.h#L26" rel="nofollow"&gt;#define MAX_ITEMGROUP 400&lt;/a&gt; Then put the item list on &lt;a class="" href="https://github.com/rathena/rathena/blob/master/db/import/item_group_db.txt" rel="nofollow"&gt;item_group_db.txt&lt;/a&gt; with format&lt;/p&gt;
&lt;p&gt;&lt;code&gt;//GroupID,ItemID,Rate{,Amount,Random,isAnnounced,Duration,isNamed,isBound}&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;IG_TestRandomItem,607,10&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;IG_TestRandomItem,608,5&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;IG_TestRandomItem,678,7&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Then use script command &lt;a class="" href="/getrandgroupitem" title="wikilink"&gt;getrandgroupitem&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;getrandgroupitem IG_TestRandomItem,1;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If the item list is added when server is running, just use &lt;a class="" href="/@reloaditemdb" title="wikilink"&gt;@reloaditemdb&lt;/a&gt;. More info can be found on &lt;a class="" href="https://github.com/rathena/rathena/blob/master/doc/item_group.txt" rel="nofollow"&gt;Item Group Documentation&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="method-2-f_rand-function"&gt;Method 2: F_Rand Function&lt;/h3&gt;
&lt;p&gt;This function is one of many useful functions in &lt;a class="" href="https://github.com/rathena/rathena/blob/master/npc/other/Global_Functions.txt" rel="nofollow"&gt;Global_Functions.txt&lt;/a&gt; file.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;//////////////////////////////////////////////////////////////////////////////////&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;// Returns a random argument.&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;// -- callfunc "F_Rand",arg0,arg1,...&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;// Example:&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;//    // You can use it to pick a random number from a list:&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;//    set @itemIDfromList, callfunc("F_Rand",1129,1222,1163,1357,1360,1522,1811,1410);&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;//////////////////////////////////////////////////////////////////////////////////&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;function   script  F_Rand  {&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;return getarg(rand(getargcount()));&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;How to use?&lt;/em&gt; Just use like at the example, call the F_Rand function then follow the item ID, the rate for each item to shows up is 1/n. Example usage can we see in item_db.txt,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;12136,Women's_Bundle,Women's Bundle,2,0,,100,,,,,0xFFFFFFFF,63,2,,,,,,{&lt;/code&gt;&lt;br/&gt;
&lt;code&gt;getitem callfunc("F_Rand",558,529,2668,7518),1; },{},{}&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="method-3-using-array"&gt;Method 3: Using Array&lt;/h3&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// begin of the script&lt;/span&gt;
&lt;span class="n"&gt;setarray&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.@&lt;/span&gt;&lt;span class="n"&gt;RandItem&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="mi"&gt;501&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;502&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;504&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;505&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.@&lt;/span&gt;&lt;span class="n"&gt;RandItemCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;getarraysize&lt;/span&gt;&lt;span class="p"&gt;(.@&lt;/span&gt;&lt;span class="n"&gt;RandItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;getitem&lt;/span&gt;&lt;span class="p"&gt;(.@&lt;/span&gt;&lt;span class="n"&gt;Randitem&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(.@&lt;/span&gt;&lt;span class="n"&gt;RandItemCount&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// end of the script&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;.@RandItem[]&lt;/strong&gt; is an array that stores the available item rewards.&lt;ul&gt;
&lt;li&gt;.@RandItem[0] =&amp;gt; &lt;em&gt;501&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;.@RandItem[1] =&amp;gt; &lt;em&gt;502&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;.@RandItem[2] =&amp;gt; &lt;em&gt;503&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;.@RandItem[3] =&amp;gt; &lt;em&gt;504&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;.@RandItem[4] =&amp;gt; &lt;em&gt;505&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.@RandItemCount&lt;/strong&gt; stores length of &lt;em&gt;.@RandItem[]&lt;/em&gt; array&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;rand(&amp;lt;number&amp;gt;)&amp;lt;/number&amp;gt;&lt;/strong&gt; results a random number from &lt;em&gt;0&lt;/em&gt; until &lt;em&gt;&amp;lt;number&amp;gt; -1&amp;lt;/number&amp;gt;&lt;/em&gt;. See &lt;a class="" href="/Rand" title="wikilink"&gt;Rand&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;getitem(&amp;lt;item_id&amp;gt;,&amp;lt;amount&amp;gt;)&amp;lt;/amount&amp;gt;&amp;lt;/item_id&amp;gt;&lt;/strong&gt; gives to player an item with id &lt;em&gt;&amp;lt;item_id&amp;gt;&amp;lt;/item_id&amp;gt;&lt;/em&gt;. See &lt;a class="" href="/Getitem" title="wikilink"&gt;Getitem&lt;/a&gt; or maybe you can use &lt;a class="" href="/Getitem2" title="wikilink"&gt;Getitem2&lt;/a&gt; too.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a class="" href="/Category:Scripting_Tips_and_Tricks" title="wikilink"&gt;Category:Scripting Tips and Tricks&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brynner</dc:creator><pubDate>Mon, 20 Feb 2023 05:00:11 -0000</pubDate><guid>https://sourceforge.net2ee627e52b8320b24aec02b9bdd5c05853f7ea2e</guid></item></channel></rss>