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

Npc free items

Szmycu

Tibiaservers.net
Joined
Sep 2, 2008
Messages
65
Reaction score
5
Location
Poland
I need script for npc who give free item for example once for day . If u have any .lua please post i will adjust it
 
Just post it, no need to be all secret about it.

This is for a chest not a NPC.
File named: timechest.lua

Code:
-- Time Chest by Limos
local config = {
     exhausttime = 86400, -- time in seconds
     exhauststorage = 2302,
     level = 250 -- minimum level to open the chest
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
     local rewarditems = {
         [25] = {
             nextlevel = 50,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [250] = {
             nextlevel = 250,
             {id = 2472, chance = 5, count = 1},
             {id = 7730, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 20)}
         },
         [500] = {
             nextlevel = 2500,
             {id = 2522, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2472, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(20, 80)}
         },
         [2500] = {
             nextlevel = 100000,
             {id = 2365, chance = 5, count = 1},
             {id = 2798, chance = 10, count = 15},
             {id = 2522, chance = 35, count = 1},
             {id = 2157, chance = 50, count = math.random(1, 3)}
         }
     }
     if getPlayerLevel(cid) < config.level then
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
         return true
     end

     if exhaustion.check(cid, config.exhauststorage) then
         local time = exhaustion.get(cid, config.exhauststorage)
         local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
         if time >= 3600 then
             text = hours.." "..(hours == 1 and "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 120 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         end
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
         return true
     end

     local chance = math.random(1,100)
     for v, x in pairs(rewarditems) do
         if getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local info = getItemInfo(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. info.plural
             else
                 text = info.article .. " " .. info.name
             end

             local item = doCreateItemEx(rewarditems[level][i].id, rewarditems[level][i].count)
             if doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR then
                 doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                 text = "You have found a reward. It is to heavy or you have not enough space."
             else
                 text = "You have found " .. text .. "."
                 exhaustion.set(cid, config.exhauststorage, config.exhausttime)
             end
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end

In Actions.xml :

Code:
<action uniqueid="4005" event="script" value="quests/timechest.lua"/>

You can use it after 24 hours again. (Gods can always.) Ofc you can change the items and the chances.

All credits to Limos :)
 
When I add the data/actions/scripts/quests/timechest.lua file with the contents from above and then add the other line to my actions.xml file I see this when the server starts up. if I remove the call from actions.xml this error isn't there.

Code:
>> Loading script systems
[Warning - Action::loadFunction] Function "" does not exist.
>> Loading monsters

Any thoughts? Server still goes online fine.
 
When I add the data/actions/scripts/quests/timechest.lua file with the contents from above and then add the other line to my actions.xml file I see this when the server starts up. if I remove the call from actions.xml this error isn't there.

Code:
>> Loading script systems
[Warning - Action::loadFunction] Function "" does not exist.
>> Loading monsters

Any thoughts? Server still goes online fine.
Which distro do you use?
Maybe because this is script is actually made for 0.3.6.
 
Last edited by a moderator:
Back
Top