Advertisement
Guest User

xikinis-easy-chest-system-for-0-3-7

a guest
Mar 4th, 2016
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.71 KB | None | 0 0
  1. function onUse(cid, item, fromPosition, itemEx, toPosition)
  2.  
  3.     --[[
  4.    
  5. ...............................................................................
  6. ........__.....__.._______...__....__.._______...___.....__..._______..........
  7. ........\.\..././.|__...__|.|..|.././.|__...__|.|...\...|..|.|__...__|.........
  8. .........\.\././.....|.|....|..|././.....|.|....|....\..|..|....|.|............
  9. ..........\.../......|.|....|..|/./......|.|....|..|\.\.|..|....|.|............
  10. ........../...\......|.|....|.....\......|.|....|..|.\.\|..|....|.|............
  11. ........././.\.\...__|.|__..|..|\..\...__|.|__..|..|..\....|..__|.|__..........
  12. ......../_/...\_\.|_______|.|__| \__\.|_______|.|__|...\___|.|_______|.........
  13. ...............................................................................
  14.  
  15. https://otland.net/threads/241126/#post-2331922
  16. ]]
  17.  
  18.  
  19.     --[[
  20.  
  21.         Yes, This green text is long.
  22.         Yes, it's needed.
  23.        
  24.        
  25.         General usage
  26.             -> Place item/chest on map.
  27.             -> Give item/chest on map an Action_ID
  28.             -> Update reward in this script.
  29.             -> Ensure actions.xml contains the Action_ID's required in this script.
  30.             -> Recommend using ' actionid="45801-45899" ' in actions.xml, to save space and time.
  31.        
  32.         For most 'options' | 1 = true | 0 = false/ignore |
  33.         However, it is recommended to remove unused portions of tables where possible.
  34.         Unexpected results can be expected if you keep 'unused options' within the tables.
  35.        
  36.         Options that can be turned off using 0
  37.             -> random_item
  38.             -> timed
  39.             -> use_container
  40.        
  41. -----------------------------------------
  42.         -> This note applies to special requirements
  43.                 -> uid
  44.                 -> writable
  45.                 -> flavourText
  46.                
  47.         -> Note: If you attempt to place a special requirement on more then 1 item at a time, the special requirement will only be placed on the first item.
  48.                 Example: [1] = { aid = 45811, uid = 1, item_id = 2467, item_count = 3 }
  49.                 -> In this example, 3 leather armors will be added to the player inventory.
  50.                     Only the first leather armor added will contain the uid.
  51. ------------------------------------------
  52.  
  53.         aid
  54.             -> This is the chest/item value used in the map.
  55.             -> It is also the storage value for the chest/item.
  56.             -> Note: AID is used for keys as well.
  57.                 If you want to add a key, always make sure the next chest/item's aid is ahead of your key values
  58.                
  59.         multi_chest
  60.             -> If you want to have more then 1 chest in a quest.
  61.             -> Think Anni-Style quests.
  62.             -> If using 'multi_chest' then make the aid of each chest the same, and make the uid of each chest different
  63.        
  64.         uid
  65.             -> If you want to add an uid to an item use 'uid = 1'. This will default to the aid used for the chest/item.
  66.             -> If you are adding more then 1 item with an uid, or you want to use custom uid's, simply put in the uid you want to use.
  67.                     example: uid = 45001
  68.             -> Note: If you place an uid on stackable items, unexpected results are expected.
  69.             -> Note: It's impossible to add an uid to 'use_container'
  70.                 This is only the holding containers. Any item you place 'inside' can have a uid attributed to it.
  71.                
  72.         key
  73.             -> If you use 'key = 1', key's AID will default to the 'aid + 1' used for the chest/item.
  74.             -> It's exactly the same as uid.. but for keys.
  75.             -> If you want to add a key, always make sure the next chest/item's aid is ahead of your key values
  76.                 -> AGAIN, Never put the key's value the same as a chest.
  77.                     This will allow the key to be 'used' to obtain rewards from the chest(s), because they have the same aid.
  78.        
  79.         item_id
  80.             -> Fairly simple. Just put the itemID of the item you wish to give.
  81.            
  82.         item_count
  83.             -> Again, fairly simple. Put the amount of items you want to give.
  84.             -> If there is no 'item_count' then it will default to 1.
  85.                 -> Note: If the item is not stackable, and you give more then 1 item, unexpected results are expected.
  86.                 -> Note: If item is stackable and you put more then 100, unexpected results are expected.
  87.                 -> Note: If you put 0 as the item_count, unexpected results are expected.
  88.                 -> Note: If sub_id is present, item_count will be ignored.
  89.             -> Can use math.random(number) to specify a random amount.
  90.            
  91.         sub_id
  92.             -> Rarely used, but useful if needed.
  93.             -> Note: The commands to give 'sub_id' use [count/subType]
  94.                 Explanation/Reason
  95.                     All items that have subTypes are not stackable, so it simply doesn't care if the item has a count.
  96.                     For this reason, if subType is used, item_count will be ignored.
  97.                    
  98.         vocation_required
  99.             -> Look on line 111 if you want to edit the vocation_required section.
  100.             -> Allows you to set a certain vocation for each chest.
  101.                 sorcerer = sorcerer or master sorcerer
  102.                 master sorcerer = only master sorcerer
  103.                 et cetera,..
  104.            
  105.         writeable
  106.             -> Allows you to place text inside of writable/readable objects.
  107.             -> Note: If you use on an item that is not writable/readable, unexpected results are expected.
  108.            
  109.         flavourText
  110.             -> Allows you to place 'flavourText'
  111.             -> flavourTest appears at the very end of an item.
  112.                 Example:
  113.                     14:11 You see a blade of corruption (Atk:91, Def:101).
  114.                     It weighs 80.00 oz.
  115.                     This is where flavourText appears.
  116.                
  117.         random_item
  118.             -> Allows you to give 1 random item + amount.
  119.             -> Note: Must be used in conjuction with 'items' table.
  120.            
  121.         items
  122.             -> Is a table value used in conjuction with 'random_item'
  123.             -> Create table as long as you want counting with [1], [2], [3], et cetera.
  124.                
  125.         timed
  126.             -> This tells the script that this chest/item is reusable after a x amount time.
  127.            
  128.         timer
  129.             -> Tells the script how long until the chest/item can be reused.
  130.             -> Timer is only used if 'timed = 1'
  131.             -> Time is counted in seconds.
  132.                 Examples:
  133.                     60 = 60 seconds
  134.                     120 = 2 minutes
  135.                     2*60 = 2 minutes
  136.                     4*60*60 = 4 hours
  137.             -> If no timer exists, timer is defaulted to 24 hours.
  138.             -> Note: If you put 0 as the timer, unexpected results are expected.
  139.        
  140.         use_container
  141.             -> This tells the script to put items into a container.
  142.                 -> Note: If using 'random_items', 'use_container' will be ignored.
  143.             -> You are only allowed to go 2 containers deep.
  144.                 Example: brown bag, containing a brown backpack, containing a leather helmet.
  145.             -> Note: Must be used in conjuction with 'inside' table(s).
  146.  
  147.         container
  148.             -> Tells the script what container to use.
  149.                 -> If no container is specified will default to a brown bag.
  150.             -> Note: If more items are given then the capacity of the container(s), unexpected results are expected.
  151.             -> Note: If you put 0 as the container, unexpected results are expected.
  152.            
  153.         inside
  154.             -> Is a table value used in conjuction with 'use_container'
  155.             -> Create table as long as you want counting with [1], [2], [3], et cetera.
  156.                 -> Note: If you make the table longer then the capacity of 'container', unexpected results are expected.
  157.                
  158.         ]]
  159.  
  160.  
  161.    
  162.     exstorage = 45800
  163.     t = {
  164.         -- Simple chest
  165.         -- 1 Brown Backpack
  166.         [1] = { aid = 45801, item_id = 1988 },
  167.        
  168.         -- Simple key chest
  169.         -- 1 wooden key with AID 45803
  170.         [2] = { aid = 45802, key = 1, item_id = 2087 },
  171.        
  172. -- SKIP 1 AID
  173.        
  174.         -- Simple key chest
  175.         -- 1 silver key with AID 45806
  176.         [3] = { aid = 45804, key = 45806, item_id = 2088 },
  177.        
  178. -- SKIP 2 AID
  179.        
  180.         -- Simple chest with stackable items
  181.         -- 3 Gold Coins
  182.         [4] = { aid = 45807, item_id = 2148, item_count = 3 },
  183.        
  184.         -- Simple chest with random amount of stackable items
  185.         -- 1-5 red apples
  186.         [5] = { aid = 45808, item_id = 2674, item_count = math.random(5) },
  187.        
  188.         -- Multiple items chest
  189.         -- 1 brown bag, 1 Leather Boots, 1 Leather Legs, 3 platinum coins
  190.         [6] = { aid = 45809, use_container = 1, inside = {
  191.                 [1] = { item_id = 2643 },
  192.                 [2] = { item_id = 2649 },
  193.                 [3] = { item_id = 2152, item_count = 3 }
  194.                 }
  195.             },
  196.        
  197.         -- Multiple of the same item chest
  198.         -- 1 brown bag, 2 vials of oil, 1 lamp, 5 torches
  199.         [7] = { aid = 45810, use_container = 1, inside = {
  200.                 [1] = { item_id = 2006, sub_id = 11 },
  201.                 [2] = { item_id = 2006, sub_id = 11 },
  202.                 [3] = { item_id = 2044 },
  203.                 [4] = { item_id = 2050, item_count = 5 }
  204.                 }
  205.             },
  206.            
  207.         -- Multiple key with aid chest
  208.         -- 1 brown backpack, 1 wooden key, 1 silver key, 1 golden key, with AID's 45812, 45813, 45814
  209.         [8] = { aid = 45811, use_container = 1, container = 1988, inside = {
  210.                 [1] = { item_id = 2091, key = 1 },
  211.                 [2] = { item_id = 2088, key = 45813 },
  212.                 [3] = { item_id = 2087, key = 45814 }
  213.                 }
  214.             },
  215.            
  216. -- SKIP 3 AID
  217.            
  218.         -- Multiple items chest with items contained inside containers, and without
  219.         -- 1 brown bags, 1 brown backpack, 1 leather helmet, 1 leather armor, 1 crystal ring
  220.         -- 1 sword, 1 wooden shield, 1 scarf, 1 red bag, 25 arrows, 1-4 cherries
  221.         [9] = { aid = 45815, use_container = 1, inside = {
  222.                 [1] = { use_container = 1, container = 1993, inside = {
  223.                     [1] = { item_id = 2512 },
  224.                     [2] = { item_id = 2376 },
  225.                     [3] = { item_id = 2456 }
  226.                     }
  227.                 },
  228.                 [2] = { use_container = 1, inside = {
  229.                     [1] = { item_id = 2461 },
  230.                     [2] = { item_id = 2467 },
  231.                     [3] = { item_id = 2544, item_count = 25 }
  232.                     }
  233.                 },
  234.                 [3] = { item_id = 2124 },
  235.                 [4] = { item_id = 2679, item_count = math.random(4) },
  236.                 [5] = { item_id = 2661 }
  237.                 }
  238.             },
  239.        
  240.         --  Multiple items chest, showing how to use 'writable' and 'flavourText'
  241.         -- 1 brown bag,
  242.         -- 2 stamped letters (1 with an uid)(both with 'writable'),
  243.         -- 2 bone keys (1 with an aid)(both with 'flavourText'),
  244.         -- 1 letter, containing uid, writable, and flavourText
  245.         [10] = { aid = 45816, use_container = 1, inside = {
  246.                 [1] = { item_id = 2598, writeable = "Writeable goes here." },
  247.                 [2] = { item_id = 2598, uid = 1, writeable = "I have the uid." },
  248.                 [3] = { item_id = 2092, flavourText = "flavourText goes here." },
  249.                 [4] = { item_id = 2092, key = 1, flavourText = "I have the uid." },
  250.                 [5] = { item_id = 2597, uid = 45817, writeable = "Use /n with a left-to-right slash,\nTo make new lines.\n\nYou can add many in a row if required.", flavourText = "I am a proud unstamped letter." }
  251.                 }
  252.             },
  253.            
  254. -- SKIP 1 AID
  255.        
  256.         -- Simple key chest (24h timer)
  257.         -- 1 wooden key with AID 45801
  258.         [11] = { aid = 45818, timed = 1, key = 1, item_id = 2087 },
  259.        
  260. -- SKIP 1 AID
  261.            
  262.         -- Random item Chest. (better known on the forum as 'Daily Chest'.
  263.         -- 1 stamped letter with uid + writable
  264.         -- 1 crystal key with uid + flavourText
  265.         -- 1 brown book with uid, + writable + flavourText
  266.         [12] = { aid = 45820, timed = 1, random_item = 1, items = {
  267.                 [1] = { item_id = 2598, uid = 1, writeable = "Woo text. :D...." },
  268.                 [2] = { item_id = 2090, key = 1, flavourText = "I ain't a key, I am Le key.." },
  269.                 [3] = { item_id = 1950, uid = 45821, writeable = "Woo more text. \n:D......", flavourText = "I am a Book.\n\nA strong and sturdy book." }
  270.                 }
  271.             },
  272.            
  273. -- SKIP 1 AID
  274.            
  275.         -- Random item Chest. (with 15 second delay.)
  276.         -- Who wants to build a cake with meh?
  277.         [13] = { aid = 45822, timed = 1, timer = 15, random_item = 1, items = {
  278.                 [1] = { item_id = 2006, sub_id = 6 },
  279.                 [2] = { item_id = 2692, item_count = 2 },
  280.                 [3] = { item_id = 2680, item_count = math.random(3) },
  281.                 [4] = { item_id = 2566 },
  282.                 [5] = { item_id = 2047 }
  283.                 }
  284.             },
  285.        
  286.         -- Anni-Style Chest
  287.         -- Actual annihilator loot. You get one of the following,
  288.         -- Magic Sword, Demon Armor, Stonecutter Axe, or a present box containing an annihilation bear
  289.         [14] = { aid = 45823, multi_chest = 45823, item_id = 2400 },
  290.         [15] = { aid = 45823, multi_chest = 45824, item_id = 2494 },
  291.         [16] = { aid = 45823, multi_chest = 45825, item_id = 2431 },
  292.         [17] = { aid = 45823, multi_chest = 45826, item_id = 1988, use_container = 1, container = 1990, inside = {
  293.                 [1] = { item_id = 2326 }
  294.                 }
  295.             },
  296.        
  297. -- SKIP 3 AID
  298.  
  299.         -- Simple vocational chest
  300.         -- vocational item, sword, crossbow, spellbook, red apple
  301.         [18] = { aid = 45827, multi_chest = 45827, vocation_required = "sorcerer", item_id = 2175 },
  302.         [19] = { aid = 45827, multi_chest = 45828, vocation_required = "druid", item_id = 2674 },
  303.         [20] = { aid = 45827, multi_chest = 45829, vocation_required = "paladin", item_id = 2455 },
  304.         [21] = { aid = 45827, multi_chest = 45830, vocation_required = "knight", item_id = 2376 },
  305.        
  306. -- SKIP 3 AID
  307.  
  308.         -- Slightly more complicated vocational chest
  309.         -- vocational items, broadsword,  royal crossbow, spellbook, red apple
  310.         [22] = { aid = 45831, multi_chest = 45831, vocation_required = "master sorcerer", item_id = 8900 },
  311.         [23] = { aid = 45831, multi_chest = 45832, vocation_required = "elder druid", item_id = 6393 },
  312.         [24] = { aid = 45831, multi_chest = 45833, vocation_required = "royal paladin", item_id = 8851 },
  313.         [25] = { aid = 45831, multi_chest = 45834, vocation_required = "elite knight", item_id = 2413 },
  314.        
  315. -- SKIP 3 AID
  316.  
  317.         -- Simple chest
  318.         -- 1 Brown Backpack
  319.         [26] = { aid = 45835, item_id = 1988 } -- Always make sure the very last line in the table has no comma.
  320.        
  321. --------------------------------------------------
  322. -- That's everything you can do with the system.--
  323. --------------------------------------------------
  324.        
  325.     }
  326.  
  327.     ---------------------------------------------------------------------
  328.     -- don't touch anything under here unless you know what your doing --
  329.     ---------------------------------------------------------------------
  330.     n = 0
  331.     m = 0
  332.     no_inv = 0
  333.  
  334.     if exhaustion.check(cid, exstorage) then
  335.         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  336.         return true
  337.     end
  338.     exhaustion.set(cid, exstorage, 1)
  339.    
  340.     for i = 1, #t do
  341.         if t[i].aid == item.aid then
  342.             if t[i].timed ~= nil then
  343.                 if exhaustion.check(cid, t[i].aid) then
  344.                     doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  345.                     doPlayerSendCancel(cid, "You are exhausted. You can obtain this reward again in ".. os.date("!%Hh %Mm %Ss", getPlayerStorageValue(cid, t[i].aid) - os.time()) ..".")
  346.                     break
  347.                 end
  348.                 setPlayerStorageValue(cid, t[i].aid, 0)
  349.             end
  350.             if getPlayerStorageValue(cid, t[i].aid) >= 1 then
  351.                 doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  352.                 doPlayerSendCancel(cid, "It is empty.")
  353.                 return true
  354.             end
  355.             if t[i].multi_chest ~= nil then
  356.                 i = i
  357.                 repeat
  358.                     if t[i].multi_chest ~= item.uid then
  359.                         i = i + 1
  360.                     end
  361.                 until t[i].multi_chest == item.uid
  362.             end
  363.             if t[i].vocation_required ~= nil then
  364.                 local voc = true
  365.                 if t[i].vocation_required == "sorcerer" then
  366.                     if getPlayerVocation(cid) ~= 1 or not 5 then
  367.                         voc = false
  368.                     end
  369.                 elseif t[i].vocation_required == "master sorcerer" then
  370.                     if getPlayerVocation(cid) ~= 5 then
  371.                         voc = false
  372.                     end
  373.                 elseif t[i].vocation_required == "druid" then
  374.                     if getPlayerVocation(cid) ~= 2 or not 6 then
  375.                         voc = false
  376.                     end
  377.                 elseif t[i].vocation_required == "elder druid" then
  378.                     if getPlayerVocation(cid) ~= 6 then
  379.                         voc = false
  380.                     end
  381.                 elseif t[i].vocation_required == "paladin" then
  382.                     if getPlayerVocation(cid) ~= 3 or not 7 then
  383.                         voc = false
  384.                     end
  385.                 elseif t[i].vocation_required == "royal paladin" then
  386.                     if getPlayerVocation(cid) ~= 7 then
  387.                         voc = false
  388.                     end
  389.                 elseif t[i].vocation_required == "knight" then
  390.                     if getPlayerVocation(cid) ~= 4 or not 8 then
  391.                         voc = false
  392.                     end
  393.                 elseif t[i].vocation_required == "elite knight" then
  394.                     if getPlayerVocation(cid) ~= 8 then
  395.                         voc = false
  396.                     end
  397.                 end
  398.                 if voc == false then
  399.                     doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  400.                     doPlayerSendCancel(cid, "Only ".. t[i].vocation_required .."'s can obtain this reward.")
  401.                     return true
  402.                 end
  403.             end
  404.             n = i
  405.             if t[i].random_item ~= nil then
  406.                 if t[i].random_item == 1 then
  407.                     rand = math.random(#t[i].items)
  408.                 end
  409.             end
  410.             if getAllItemWeight(weight) > getPlayerFreeCap(cid) then
  411.                 doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  412.                 doPlayerSendCancel(cid, "You require ".. string.format("%.2f", getAllItemWeight(weight)) .." capacity to obtain this reward.")
  413.                 return true
  414.             end
  415.             if t[i].random_item == 1 then
  416.                 if t[i].items[rand].sub_id ~= nil then
  417.                     item = doCreateItemEx(t[i].items[rand].item_id, t[i].items[rand].sub_id or 1)
  418.                 else
  419.                     item = doCreateItemEx(t[i].items[rand].item_id, t[i].items[rand].item_count or 1)
  420.                 end
  421.                 if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
  422.                     no_inv = 1
  423.                 else
  424.                     if t[i].items[rand].key ~= nil then
  425.                         if t[i].items[rand].key > 1 then
  426.                             doSetItemActionId(item, t[i].items[rand].key)
  427.                         else
  428.                             doSetItemActionId(item, t[i].aid + 1)
  429.                         end
  430.                     elseif t[i].items[rand].uid ~= nil then
  431.                         if t[i].items[rand].uid > 1 then
  432.                             doItemSetAttribute(item, "uid", t[i].items[rand].uid)
  433.                         else
  434.                             doItemSetAttribute(item, "uid", t[i].aid)
  435.                         end
  436.                     end
  437.                     if t[i].items[rand].flavourText ~= nil then
  438.                         doItemSetAttribute(item, "description", t[i].items[rand].flavourText)
  439.                     end
  440.                     if t[i].items[rand].writeable ~= nil then
  441.                         doSetItemText(item, t[i].items[rand].writeable)
  442.                     end
  443.                 end
  444.             elseif t[i].use_container == 1 then
  445.                 local item = doCreateItemEx(t[i].container or 1987, 1)
  446.                 if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
  447.                     no_inv = 1
  448.                 else
  449.                     for i = 1, #t[n].inside do
  450.                         if t[n].inside[i].use_container == 1 then
  451.                             m = i
  452.                             local newContainer = doAddContainerItem(item, t[n].inside[i].container or 1987, 1)
  453.                             for i = 1, #t[n].inside[m].inside do
  454.                                 if t[n].inside[m].inside[i].sub_id ~= nil then
  455.                                     item2 = doAddContainerItem(newContainer, t[n].inside[m].inside[i].item_id, t[n].inside[m].inside[i].sub_id or 1)
  456.                                 else
  457.                                     item2 = doAddContainerItem(newContainer, t[n].inside[m].inside[i].item_id, t[n].inside[m].inside[i].item_count or 1)
  458.                                 end
  459.                                 if t[n].inside[m].inside[i].key ~= nil then
  460.                                     if t[n].inside[m].inside[i].key > 1 then
  461.                                         doSetItemActionId(item2, t[n].inside[m].inside[i].key)
  462.                                     else
  463.                                         doSetItemActionId(item2, t[n].aid + 1)
  464.                                     end
  465.                                 elseif t[n].inside[m].inside[i].uid ~= nil then
  466.                                     if t[n].inside[m].inside[i].uid > 1 then
  467.                                         doItemSetAttribute(item2, "uid", t[n].inside[m].inside[i].uid)
  468.                                     else
  469.                                         doItemSetAttribute(item2, "uid", t[n].aid)
  470.                                     end
  471.                                 end
  472.                                 if t[n].inside[m].inside[i].flavourText ~= nil then
  473.                                     doItemSetAttribute(item2, "description", t[n].inside[m].inside[i].flavourText)
  474.                                 end
  475.                                 if t[n].inside[m].inside[i].writeable ~= nil then
  476.                                     doSetItemText(item2, t[n].inside[m].inside[i].writeable)
  477.                                 end
  478.                             end
  479.                         else
  480.                             if t[n].inside[i].sub_id ~= nil then
  481.                                 item2 = doAddContainerItem(item, t[n].inside[i].item_id, t[n].inside[i].sub_id or 1)
  482.                             else
  483.                                 item2 = doAddContainerItem(item, t[n].inside[i].item_id, t[n].inside[i].item_count or 1)
  484.                             end
  485.                             if t[n].inside[i].key ~= nil then
  486.                                 if t[n].inside[i].key > 1 then
  487.                                     doSetItemActionId(item2, t[n].inside[i].key)
  488.                                 else
  489.                                     doSetItemActionId(item2, t[n].aid + 1)
  490.                                 end
  491.                             elseif t[n].inside[i].uid ~= nil then
  492.                                 if t[n].inside[i].uid > 1 then
  493.                                     doItemSetAttribute(item2, "uid", t[n].inside[i].uid)
  494.                                 else
  495.                                     doItemSetAttribute(item2, "uid", t[n].aid)
  496.                                 end
  497.                             end
  498.                             if t[n].inside[i].flavourText ~= nil then
  499.                                 doItemSetAttribute(item2, "description", t[n].inside[i].flavourText)
  500.                             end
  501.                             if t[n].inside[i].writeable ~= nil then
  502.                                 doSetItemText(item2, t[n].inside[i].writeable)
  503.                             end
  504.                         end
  505.                     end
  506.                 end
  507.             else
  508.                 if t[i].sub_id ~= nil then
  509.                     item = doCreateItemEx(t[i].item_id, t[i].sub_id or 1)
  510.                 else
  511.                     item = doCreateItemEx(t[i].item_id, t[i].item_count or 1)
  512.                 end
  513.                 if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
  514.                     no_inv = 1
  515.                 else
  516.                     if t[i].key ~= nil then
  517.                         if t[i].key > 1 then
  518.                             doSetItemActionId(item, t[i].key)
  519.                         else
  520.                             doSetItemActionId(item, t[i].aid + 1)
  521.                         end
  522.                     elseif t[i].uid ~= nil then
  523.                         if t[i].uid > 1 then
  524.                             doItemSetAttribute(item, "uid", t[i].uid)
  525.                         else
  526.                             doItemSetAttribute(item, "uid", t[i].aid)
  527.                         end
  528.                     end
  529.                     if t[i].flavourText ~= nil then
  530.                         doItemSetAttribute(item, "description", t[i].flavourText)
  531.                     end
  532.                     if t[i].writeable ~= nil then
  533.                         doSetItemText(item, t[i].writeable)
  534.                     end
  535.                 end
  536.             end
  537.             if no_inv == 1 then
  538.                 doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  539.                 doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
  540.                 return true
  541.             end
  542.             if t[i].use_container == 1 then
  543.                 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a ".. getItemNameById(t[i].container or 1987) .." weighing ".. string.format("%.2f", getAllItemWeight(weight)) .." oz.")
  544.             elseif t[i].random_item == 1 then
  545.                 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found ".. t[i].items[rand].item_count .." ".. getItemNameById(t[i].items[rand].item_id) ..".")
  546.             else
  547.                 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found ".. t[i].item_count .." ".. getItemNameById(t[i].item_id) ..".")
  548.             end
  549.             if t[i].timed ~= nil then
  550.                 if t[i].timed == 1 then
  551.                     exhaustion.set(cid, t[i].aid, t[i].timer or 24 * 60 * 60)
  552.                 else
  553.                     setPlayerStorageValue(cid, t[i].aid, 1)
  554.                 end
  555.             else
  556.                 setPlayerStorageValue(cid, t[i].aid, 1)
  557.             end
  558.             break
  559.         end
  560.     end
  561.     return true
  562. end
  563.  
  564. function getAllItemWeight(weight)
  565.     local items = {}
  566.     local count = {}
  567.     local weight = 0
  568.     if t[n].random_item == 1 then
  569.         table.insert(items, t[n].items[rand].item_id)
  570.         if t[n].items[rand].sub_id ~= nil then
  571.             table.insert(count, 1)
  572.         else
  573.             table.insert(count, t[n].items[rand].item_count or 1)
  574.         end
  575.     elseif t[n].use_container == 1 then
  576.         table.insert(items, t[n].container or 1987)
  577.         table.insert(count, 1)
  578.         for i = 1, #t[n].inside do
  579.             if t[n].inside[i].use_container == 1 then
  580.                 table.insert(items, t[n].inside[i].container or 1987)
  581.                 table.insert(count, 1)
  582.                 m = i
  583.                 for i = 1, #t[n].inside[m].inside do
  584.                     table.insert(items, t[n].inside[m].inside[i].item_id)
  585.                     if t[n].inside[m].inside[i].sub_id ~= nil then
  586.                         table.insert(count, 1)
  587.                     else
  588.                         table.insert(count, t[n].inside[m].inside[i].item_count or 1)
  589.                     end
  590.                 end
  591.             else
  592.                 table.insert(items, t[n].inside[i].item_id)
  593.                 if t[n].inside[i].sub_id ~= nil then
  594.                     table.insert(count, 1)
  595.                 else
  596.                     table.insert(count, t[n].inside[i].item_count or 1)
  597.                 end
  598.             end
  599.         end
  600.     else
  601.         table.insert(items, t[n].item_id)
  602.         if t[n].sub_id ~= nil then
  603.             table.insert(count, 1)
  604.         else
  605.             table.insert(count, t[n].item_count or 1)
  606.         end
  607.     end
  608.     for i = 1, #items do
  609.         weight = (weight + (getItemWeightById(items[i], count[i])))
  610.     end
  611.     return weight
  612. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement