Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. local specialQuests = {
  2.     [2001] = 30015 --Annihilator
  3. }
  4.  
  5. local questsExperience = {
  6.     [30015] = 10000
  7. }
  8.  
  9. function onUse(cid, item, fromPosition, itemEx, toPosition)
  10.     if(getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges) == TRUE) then
  11.         return TRUE
  12.     end
  13.  
  14.     local storage = specialQuests[item.actionid]
  15.     if(storage == nil) then
  16.         storage = item.uid
  17.         if(storage > 65535) then
  18.             return FALSE
  19.         end
  20.     end
  21.  
  22.     local result = "It is empty."
  23.     if(getPlayerStorageValue(cid, storage) <= 0) then
  24.         local items = {}
  25.         local reward = 0
  26.  
  27.         local size = isContainer(item.uid) == TRUE and getContainerSize(item.uid) or 0
  28.         if(size == 0) then
  29.             reward = doCopyItem(item, FALSE)
  30.         else
  31.             for i = 0, size do
  32.                 local tmp = getContainerItem(item.uid, i)
  33.                 if(tmp.itemid > 0) then
  34.                     table.insert(items, tmp)
  35.                 end
  36.             end
  37.         end
  38.  
  39.         size = table.maxn(items)
  40.         if(size == 1) then
  41.             reward = doCopyItem(items[1], TRUE)
  42.         end
  43.  
  44.         if(reward ~= 0) then
  45.             local ret = getItemDescriptions(reward.uid)
  46.             if(reward.type > 0 and isItemRune(reward.itemid) == TRUE) then
  47.                 result = reward.type .. " charges " .. ret.name
  48.             elseif(reward.type > 0 and isItemStackable(reward.itemid) == TRUE) then
  49.                 result = reward.type .. " " .. ret.plural
  50.             else
  51.                 result = ret.article .. " " .. ret.name
  52.             end
  53.         else
  54.             result = ""
  55.             if(size > 20) then
  56.                 reward = doCopyItem(item, FALSE)
  57.             elseif(size > 8) then
  58.                 reward = getThing(doCreateItemEx(1988, 1))
  59.             else
  60.                 reward = getThing(doCreateItemEx(1987, 1))
  61.             end
  62.  
  63.             for i = 1, size do
  64.                 local tmp = doCopyItem(items[i], TRUE)
  65.                 if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
  66.                     print("[Warning] QuestSystem:", "Could not add quest reward")
  67.                 else
  68.                     local ret = ", "
  69.                     if(i == 2) then
  70.                         ret = " and "
  71.                     elseif(i == 1) then
  72.                         ret = ""
  73.                     end
  74.  
  75.                     result = result .. ret
  76.                     ret = getItemDescriptions(tmp.uid)
  77.                     if(tmp.type > 0 and isItemRune(tmp.itemid) == TRUE) then
  78.                         result = result .. tmp.type .. " charges " .. ret.name
  79.                     elseif(tmp.type > 0 and isItemStackable(tmp.itemid) == TRUE) then
  80.                         result = result .. tmp.type .. " " .. ret.plural
  81.                     else
  82.                         result = result .. ret.article .. " " .. ret.name
  83.                     end
  84.                 end
  85.             end
  86.         end
  87.  
  88.         if(doPlayerAddItemEx(cid, reward.uid, FALSE) ~= RETURNVALUE_NOERROR) then
  89.             result = "You have found a reward weighing " .. getItemWeight(reward.uid) .. " oz. It is too heavy or you have not enough space."
  90.         else
  91.             result = "You have found " .. result .. "."
  92.             setPlayerStorageValue(cid, storage, 1)
  93.             if(questsExperience[storage] ~= nil) then
  94.                 doPlayerAddExp(cid, questsExperience[storage])
  95.                 doSendAnimatedText(getCreaturePosition(cid), questsExperience[storage], TEXTCOLOR_WHITE)
  96.             end
  97.         end
  98.     end
  99.  
  100.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
  101.     return TRUE
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement