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

Lua Crate that gives you an random item, every hour

Fermantor

Active Member
Joined
Dec 16, 2009
Messages
209
Solutions
4
Reaction score
34
Location
Germany
There are crates in rl Tibia, that gives you an item, every 1 hour, when you click on them. I wanna use this on my server to, but I don't know, how to re-set the StorageValue of an player, if he/she is logged out.
My script so far, look like this:
LUA:
local Items = {
[1] = {2160,2},
[2] = {2160,2},
[3] = {2160,2},
[4] = {2160,2},
[5] = {2160,2}
}

function onUse(cid, item, fromPos, item2, toPos)
	if getPlayerStorageValue(cid, 11010) == -1 then
		local chance = math.random(1,5)
		for id, item in pairs(Items) do
			if chance == id then
				doPlayerAddItem(cid, item[1], item[2])
				doCreatureSay(cid, "You have found " .. item[2] .. " " .. item[1], 34)
				setPlayerStorageValue(cid, 11010, 1)
				local GUID = getPlayerGUID(cid)
				addEvent(back, 1000*5, GUID)
			end
		end
	else
		doCreatureSay(cid, "You have found nothing usefull.", 34)
	end
	return true
end

function back(id)
	db.query("UPDATE `player_storage` SET `value` = -1 WHERE `player_id` = " .. id .. " AND `key` = 11010")
end

I am using TFS 0.2.14 (mystic spirit, tibia 9.61)
 
Back
Top