• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Request] Make chest give item

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,051
Solutions
2
Reaction score
260
Location
United States
Hello and im here to request a script for a chest to give a reward of the same item but 1 time in each chest, does anyone have a script for it?
 
I still don't understand. :p

What do you mean by item in another chest?

Multiple chests that give the same item?

Yes but only once per chest, for example the Anni if i wanna make it so it gives demon armor once per chest but i can use 3 chest to get the same item and i want it so i cannot get a reward from the chests i used, but i wanna make it for addon doll ;d (ID: 8982)
 
Hello and im here to request a script for a chest to give a reward of the same item but 1 time in each chest, does anyone have a script for it?

Had trouble checking if player had free inventory space or not. >.>
Anyways all fixed and ready to go.
@Codex NG Is there a better way I could make this, so there isn't 4 if statements in a row?

For the record.. you can use any item in the game.. you don't have to explicitly use a chest.
daz5TN8.png

Code:
<action actionid="45000" event="script" value="Xikini_easy_chests.lua"/>
Code:
local config = {
     [1] = { uid = 45001, item = 8982, amount = 1},
     [2] = { uid = 45002, item = 8982, amount = 1},
     [3] = { uid = 45003, item = 8982, amount = 1},
     [4] = { uid = 45004, item = 8982, amount = 1}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     for i = 1, #config do
         if config[i].uid == item.uid then
             if getPlayerStorageValue(cid, config[i].uid) < 1 then
                 if getPlayerFreeCap(cid) >= getItemWeightById(config[i].item, config[i].amount) then
                     local item = doCreateItemEx(config[i].item, config[i].amount)
                     if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                         doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
                     else
                         doPlayerSendCancel(cid, "You have received ".. config[i].amount .." ".. config[i].item ..".")
                         setPlayerStorageValue(cid, config[i].uid, 1)
                     end
                 else
                     doPlayerSendCancel(cid, "You require ".. getItemWeightById(config[i].item, config[i].amount) .." capacity to obtain this reward.")
                 end
             else
                 doPlayerSendCancel(cid, "You have already obtained this reward.")
             end
             break
         end
     end
     
     return true
end
 
Last edited by a moderator:
Had trouble checking if player had free inventory space or not. >.>
Anyways all fixed and ready to go.
@Codex NG Is there a better way I could make this, so there isn't 4 if statements in a row?

For the record.. you can use any item in the game.. you don't have to explicitly use a chest.
daz5TN8.png

Code:
<action actionid="45000" event="script" value="Xikini_easy_chests.lua"/>
Code:
local config = {
     [1] = { uid = 45001, item = 8982, amount = 1},
     [2] = { uid = 45002, item = 8982, amount = 1},
     [3] = { uid = 45003, item = 8982, amount = 1},
     [4] = { uid = 45004, item = 8982, amount = 1}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     for i = 1, #config do
         if config[i].uid == item.uid then
             if getPlayerStorageValue(cid, config[i].uid) < 1 then
                 if getPlayerFreeCap(cid) >= getItemWeightById(config[i].item, config[i].amount) then
                     local item = doCreateItemEx(config[i].item, config[i].amount)
                     if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                         doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
                     else
                         doPlayerSendCancel(cid, "You have received ".. config[i].amount .." ".. config[i].item ..".")
                         setPlayerStorageValue(cid, config[i].uid, 1)
                     end
                 else
                     doPlayerSendCancel(cid, "You require ".. getItemWeightById(config[i].item, config[i].amount) .." capacity to obtain this reward.")
                 end
             else
                 doPlayerSendCancel(cid, "You have already obtained this reward.")
             end
             break
         end
     end
   
     return true
end
one small itsy bitsy problem, when i use the chest it says "You have found 1 8982." XD other then that it works amazing ^.^
 
one small itsy bitsy problem, when i use the chest it says "You have found 1 8982." XD other then that it works amazing ^.^
Oh. :p

Here's an updated chest.
Fixed the itsy bitsy problem, and also added in a small exhaust so players don't spam the chest and possibly get extra rewards.
Just a failsafe. :p -- Quick note, gods do not get exhausted, so if your testing the exhaust, try on a normal character.

Code:
local config = {
     [1] = { uid = 45001, item = 2152, amount = 1},
     [2] = { uid = 45002, item = 2152, amount = 1},
     [3] = { uid = 45003, item = 2152, amount = 1},
     [4] = { uid = 45004, item = 2152, amount = 1}
}
local exstorage = 45000

function onUse(cid, item, fromPosition, itemEx, toPosition)
     if exhaustion.check(cid, exstorage) then
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendCancel(cid, "You are exhausted.")
         return true
     end
     exhaustion.set(cid, exstorage, 2)
     for i = 1, #config do
         if config[i].uid == item.uid then
             if getPlayerStorageValue(cid, config[i].uid) < 1 then
                 if getPlayerFreeCap(cid) >= getItemWeightById(config[i].item, config[i].amount) then
                     local item = doCreateItemEx(config[i].item, config[i].amount)
                     if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                         doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
                     else
                         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found ".. config[i].amount .." ".. getItemNameById(config[i].item) ..".")
                         setPlayerStorageValue(cid, config[i].uid, 1)
                     end
                 else
                     doPlayerSendCancel(cid, "You require ".. getItemWeightById(config[i].item, config[i].amount) .." capacity to obtain this reward.")
                 end
             else
                 doPlayerSendCancel(cid, "You have already obtained this reward.")
             end
             break
         end
     end
  
     return true
end
 
Last edited by a moderator:
Oh. :p

Here's an updated chest.
Fixed the itsy bitsy problem, and also added in a small exhaust so players don't spam the chest and possibly get extra rewards.
Just a failsafe. :p -- Quick note, gods do not get exhausted, so if your testing the exhaust, try on a normal character.

Code:
local config = {
     [1] = { uid = 45001, item = 2152, amount = 1},
     [2] = { uid = 45002, item = 2152, amount = 1},
     [3] = { uid = 45003, item = 2152, amount = 1},
     [4] = { uid = 45004, item = 2152, amount = 1}
}
local exstorage = 45000

function onUse(cid, item, fromPosition, itemEx, toPosition)
     if exhaustion.check(cid, exstorage) then
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendCancel(cid, "You are exhausted.")
         return true
     end
     exhaustion.set(cid, exstorage, time)
     for i = 1, #config do
         if config[i].uid == item.uid then
             if getPlayerStorageValue(cid, config[i].uid) < 1 then
                 if getPlayerFreeCap(cid) >= getItemWeightById(config[i].item, config[i].amount) then
                     local item = doCreateItemEx(config[i].item, config[i].amount)
                     if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                         doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
                     else
                         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found ".. config[i].amount .." ".. getItemNameById(config[i].item) ..".")
                         setPlayerStorageValue(cid, config[i].uid, 1)
                     end
                 else
                     doPlayerSendCancel(cid, "You require ".. getItemWeightById(config[i].item, config[i].amount) .." capacity to obtain this reward.")
                 end
             else
                 doPlayerSendCancel(cid, "You have already obtained this reward.")
             end
             break
         end
     end
  
     return true
end
:SS

Code:
[18/02/2016 02:54:19] [Error - Action Interface] 
[18/02/2016 02:54:19] data/actions/scripts/Xikini_easy_chests.lua:onUse
[18/02/2016 02:54:19] Description: 
[18/02/2016 02:54:19] data/lib/034-exhaustion.lua:28: attempt to perform arithmetic on local 'time' (a nil value)
[18/02/2016 02:54:19] stack traceback:
[18/02/2016 02:54:19]     data/lib/034-exhaustion.lua:28: in function 'set'
[18/02/2016 02:54:19]     data/actions/scripts/Xikini_easy_chests.lua:15: in function <data/actions/scripts/Xikini_easy_chests.lua:9>

Code:
local config = {
   [1] = { uid = 45001, item = 8982, amount = 1},
   [2] = { uid = 45002, item = 8982, amount = 1},
   [3] = { uid = 45003, item = 8982, amount = 1},
   [4] = { uid = 45004, item = 8982, amount = 1}
}
local exstorage = 45000

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if exhaustion.check(cid, exstorage) then
     doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
     doPlayerSendCancel(cid, "You are exhausted.")
     return true
   end
   exhaustion.set(cid, exstorage, time)
   for i = 1, #config do
     if config[i].uid == item.uid then
       if getPlayerStorageValue(cid, config[i].uid) < 1 then
         if getPlayerFreeCap(cid) >= getItemWeightById(config[i].item, config[i].amount) then
           local item = doCreateItemEx(config[i].item, config[i].amount)
           if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
             doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
             doPlayerSendCancel(cid, "You require free inventory space to obtain this reward.")
           else
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found ".. config[i].amount .." ".. getItemNameById(config[i].item) ..".")
             setPlayerStorageValue(cid, config[i].uid, 1)
           end
         else
           doPlayerSendCancel(cid, "You require ".. getItemWeightById(config[i].item, config[i].amount) .." capacity to obtain this reward.")
         end
       else
         doPlayerSendCancel(cid, "You have already obtained this reward.")
       end
       break
     end
   end

   return true
end
 
Back
Top