• 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!

Need help with Script

CharlesHudson

Just alive, or just breathing...
Joined
Oct 25, 2011
Messages
98
Reaction score
14
HELLO everybody i come here becouse i need help with 2 script i'm testing, but nothing that i do works
The scripts is thinking for work as rewards
When is your first time completing the quest, u will receive the main reward (CUSTOM ITEM)
But you have to wait 24 hours to receive another reward
When you complete 24 hours you are able to get another reward but this time
is one with random chance to get
This are my 2 scripts im using TFS 1.0
Plx HELPPP
Code:
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(21696) < 0 then
    player:setStorageValue(21696, 1)
    player:addItem(21696, 1)
    player:setStorageValue(21696, os.time())
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif player:getStorageValue(21696 > os.time() + 24* 60 * 60 )
    then
           local index = math.random(#items)
      player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
      player:setStorageValue(21696, os.time())
   else

        player:getPosition():sendMagicEffect(CONST_ME_POFF)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
           end 
   return true
end
That is for a single chest

Code:
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},   
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if player:getStorageValue(25918) < 0 and player:getStorageValue(25958) < 0 then
        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local article = itemType:getArticle()
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(25918, 1)   
        player:setStorageValue(25958, 1)
        player:setStorageValue(60501, os.time())
   elseif player:getStorageValue(60501 > os.time() + 24 * 60 * 60)
   then
       local index = math.random(#items)
       player:addItem(cid, items[index][1], math.random(items[index][2]), true)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
      player:setStorageValue(60501, os.time())
   else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')

   end 
   return true
end
Multiple Chest

THANKS IN ADVANCE
I wait for you help plx
 
Solution
Lua:
player:getStorageValue(21696) > (os.time() + 60 )
This won't work. Check that he's setting the storage value to os.time().
Code:
if old_time > curent_time + 60
This will just never pass.


Try this instead.
Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary...
I fixed a small error in both scripts, and properly tabbed them.

Can you explain the problem in more detail please?
Lua:
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if player:getStorageValue(21696) < 0 then
       player:setStorageValue(21696, 1)
       player:addItem(21696, 1)
       player:setStorageValue(21696, os.time())
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
   elseif player:getStorageValue(21696 > os.time() + 24* 60 * 60 ) then
       local index = math.random(#items)
       player:addItem(items[index][1], math.random(items[index][2]), true)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
       player:setStorageValue(21696, os.time())
   else
       player:getPosition():sendMagicEffect(CONST_ME_POFF)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
   end
   return true
end
Lua:
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(25918) < 0 and player:getStorageValue(25958) < 0 then
        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
            local article = itemType:getArticle()
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(25918, 1)
        player:setStorageValue(25958, 1)
        player:setStorageValue(60501, os.time())
    elseif player:getStorageValue(60501 > os.time() + 24 * 60 * 60) then
        local index = math.random(#items)
        player:addItem(cid, items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(60501, os.time())
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end
 
Well when i try to use after 24 hrs, still giving the msg "You must wait a full 24 hours before another reward can be obtained"
And if i move
Lua:
    elseif player:getStorageValue(60501 > os.time() + 24 * 60 * 60) then
Gives the reward always, don't take time remains
 
I edit my last codes, i see storages was the same
Lua:
local storage = 9631
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if player:getStorageValue(21696) < 0 then
       player:setStorageValue(21696, 1)
       player:addItem(21696, 1)
       player:setStorageValue(9631, os.time())
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
   elseif player:getStorageValue(9631 > os.time() + 60) then
       local index = math.random(#items)
       player:addItem(items[index][1], math.random(items[index][2]), true)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
       player:setStorageValue(9631, os.time())
   else
       player:getPosition():sendMagicEffect(CONST_ME_POFF)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
   end
   return true
end
I put in time 60 that means 1 min i guess
Still no waiting i use the chest and gives me random reward
 
Lua:
player:getStorageValue(21696) > (os.time() + 60 )
This won't work. Check that he's setting the storage value to os.time().
Code:
if old_time > curent_time + 60
This will just never pass.


Try this instead.
Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif cur_time > player:getStorageValue(9631) then
        local index = math.random(#items)
        player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(9631, cur_time + time_between_uses)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end
 
Solution
This won't work. Check that he's setting the storage value to os.time().
Code:
if old_time > curent_time + 60
This will just never pass.


Try this instead.
Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif cur_time > player:getStorageValue(9631) then
        local index = math.random(#items)
        player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(9631, cur_time + time_between_uses)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end
Are we going to fight to see who helps faster?
 
Lua:
local storage = 9631
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif cur_time > player:getStorageValue(9631) then
        local index = math.random(#items)
        player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(9631, cur_time + time_between_uses)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end
This works on single chest THANKS :D

still
Lua:
local cur_time = os.time()
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},   
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if player:getStorageValue(25918) < 0 and player:getStorageValue(25958) < 0 then
        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
        local article = itemType:getArticle()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(25918, 1)   
        player:setStorageValue(25958, 1)
        player:setStorageValue(60501, cur_time + time_between_uses)
     elseif cur_time > player:getStorageValue(60501) then
       local index = math.random(#items)
       player:addItem(cid, items[index][1], math.random(items[index][2]), true)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
       player:setStorageValue(60501,  cur_time + time_between_uses)
   else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')

   end 
   return true
end
perma time waiting
 
Lua:
local storage = 9631
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif cur_time > player:getStorageValue(9631) then
        local index = math.random(#items)
        player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(9631, cur_time + time_between_uses)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end
This works on single chest THANKS :D

still
Lua:
local cur_time = os.time()
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},  
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   if player:getStorageValue(25918) < 0 and player:getStorageValue(25958) < 0 then
        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
        local article = itemType:getArticle()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(25918, 1)  
        player:setStorageValue(25958, 1)
        player:setStorageValue(60501, cur_time + time_between_uses)
     elseif cur_time > player:getStorageValue(60501) then
       local index = math.random(#items)
       player:addItem(cid, items[index][1], math.random(items[index][2]), true)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
       player:setStorageValue(60501,  cur_time + time_between_uses)
   else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')

   end
   return true
end
perma time waiting
You need to have
Code:
local cur_time = os.time()
inside the function.
When it's outside the function, it's only updated when you reload or restart server.
Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},   
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
 
You need to have
Code:
local cur_time = os.time()
inside the function.
When it's outside the function, it's only updated when you reload or restart server.
Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},  
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
Ok man, you fix all my troubles <3 U are the best man i though u say u only script for 0.3.6 jajaj <3
Bogart Thank u man too <3
U both guys are the best !!
 
It ended like this
Single chest
Lua:
local storage = 9631
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8882, 1}, {16015, 1}, {22398, 1}, {18511, 1}, {2160, 50}}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cur_time = os.time()
    if player:getStorageValue(21696) < 0 then
        player:setStorageValue(21696, 1)
        player:addItem(21696, 1)
        player:setStorageValue(9631, cur_time + time_between_uses)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found the Legendary Bow.")
    elseif cur_time > player:getStorageValue(9631) then
        local index = math.random(#items)
        player:addItem(items[index][1], math.random(items[index][2]), true)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
        player:setStorageValue(9631, cur_time + time_between_uses)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')
    end
    return true
end

And for 2 chest

Lua:
local time_between_uses = 1 * 60   -- 60 seconds * 60 minutes * 24 hours
local items = {{8881, 5}, {16007, 5}, {22422, 10}, {9933, 10}, {2160, 50}}
local chests = {
    [25918] = {itemid = 25958, count = 1},
    [25958] = {itemid = 25918, count = 1},   
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
 local cur_time = os.time()
   if player:getStorageValue(25918) < 0 and player:getStorageValue(25958) < 0 then
        local chest = chests[item.uid]
        local itemType = ItemType(chest.itemid)
        if itemType then
        local article = itemType:getArticle()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#article > 0 and article .. ' ' or '') .. itemType:getName() .. '.')
        end
        player:addItem(chest.itemid, chest.count)
        player:setStorageValue(25918, 1)   
        player:setStorageValue(25958, 1)
        player:setStorageValue(60501, cur_time + time_between_uses)
     elseif cur_time > player:getStorageValue(60501) then
       local index = math.random(#items)
       player:addItem(cid, items[index][1], math.random(items[index][2]), true)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
       player:setStorageValue(60501,  cur_time + time_between_uses)
   else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
          player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait a full 24 hours before another reward can be obtained.')

   end 
   return true
end
Time is only for testing
 
@Xikini How i can to made the msg
Lua:
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You get a .')
get the item name? jeje
Idk 1.2 functions well enough.
Only thing I could do is put the name of the item into your table. :/

Lua:
local items = {
   {8881, 5, "name singular", "name plural"},
   {16007, 5, "name singular", "name plural"},
   {22422, 10, "name singular", "name plural"},
   {9933, 10, "name singular", "name plural"},
   {2160, 50, "crystal coin", "crystal coins"}
}
Lua:
local index = math.random(#items)
local rand = math.random(items[index][2])
player:addItem(cid, items[index][1], rand, true)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received " .. rand == 1 and "a " .. items[index][3] .. "" or "" .. rand .. " " .. items[index][4] .. "" .. ".")
Code:
You have received a crystal coin.
You have received 50 crystal coins.
 
Back
Top