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

Lottery Lottery!

Swiff

Member
Joined
Apr 6, 2009
Messages
366
Reaction score
12
Location
Sweden
Good morning OtLand, I have reestablished a hunger for open tibia creation and I'm about to start where I left off last time!

I was searching for a script about a lottery chest. I did find one on Otfans but it was not configured to my purpose, and I could not seem to edit it, and they could not seem to reply on the post anymore:/

So, What I need is a chest that will do something like this:

Code:
onuse (upon using the chest)
doremoveitem"id"( the item required to use the chest successfully)
math.random(30) (the number of different prices you could win)
[random 1] item = 2152, amountmax = 10
[random 2] item = 1988
etc. to 30.
else do playersendcancel "you need a specific item to use this chest!"

Now, as you can see I'm not a script god:D I try to learn a few things now and then but this right here is jsut messed up. I just thought it'd be easier for a scripter if they knew.. kinda what I wanted to do :)

The idea is basicly - you go find yourself these rare stones and with them you can use the lottery chest, and if you're lucky u'll win a nice item or cash, or maybe u'll win an empty backpack.

I had an idea about restricting the usage to 10 times each 24h, but I don't know what kind of request that would be, I'd be happy with just the exchange of a rare item for a random reward.
 
LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = xxxx -- itemID required to use the chest.
local prize = {xxxx, xxxx, xxxx, xxxx, xxxx} -- and so on...
local actionid = xxxx -- actionID of chest.

if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
doPlayerAddItem(local.prize)[math.random(1, table.maxn(local.prize))], 1)
doPlayerSendTextMessage("You won a "..getItemIdByName..".")
else
DoPlayerSendCancel(cid, cancel)
DoSendMagicEffect(cid, CONST_ME_POFF)
end
return true
end
 
LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = 2157 -- itemID required to use the chest.
local prize = {2157, 2153, 2154, 2155, 2156} -- and so on...
local actionid = 1337 -- actionID of chest.
 
if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
doPlayerAddItem(local.prize)[math.random(1, table.maxn(local.prize))], 1) /*unexpected symbol near 'local' on this line it says. POP*/
doPlayerSendTextMessage("You won a "..getItemIdByName..".")
else
DoPlayerSendCancel(cid, cancel)
DoSendMagicEffect(cid, CONST_ME_POFF)
end
return true
end

Moreover, I'm using 0.3.6pl1
 
Last edited:
Try this

LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = 2157 -- itemID required to use the chest.
local prize = {2157, 2153, 2154, 2155, 2156} -- and so on...
local actionid = 1337 -- actionID of chest.

if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
doPlayerAddItem(cid, prize)[math.random(1, table.maxn(prize)], 1)
doPlayerSendTextMessage("You won a "..getItemIdByName(cid)..".")
else
DoPlayerSendCancel(cid, cancel)
DoSendMagicEffect(cid, CONST_ME_POFF)
end
return true
end
 
Last edited:
zzZzZ...I rewrote it this should work.

LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = 2157 -- itemID required to use the chest.
local prize = {2157, 2153, 2154, 2155, 2156} -- and so on...
local actionid = 1337 -- actionID of chest.
local count = 1 -- quantity of the item received EG. 1 = 1 SD. 10 = 10 SDs. 
 
if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
local randomChance = math.random(1, 5)
doPlayerAddItem(cid, prize[randomChance], count)
doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
else
DoPlayerSendCancel(cid, cancel)
DoSendMagicEffect(cid, CONST_ME_POFF)
end
return true
end
 
Thank you, it works:) rep++

ah, except the
LUA:
else
DoPlayerSendCancel
DoSendMagicEffect
But I can fix that :D

Hm.. seems to be some other nil values aswell, line 11 and 14. But this is about the else statement, so atleast the lottery code works:)
 
Last edited:
Thank you, it works:) rep++

ah, except the
LUA:
else
DoPlayerSendCancel
DoSendMagicEffect
But I can fix that :D

Hm.. seems to be some other nil values aswell, line 11 and 14. But this is about the else statement, so atleast the lottery code works:)

To fix that error you can try:

LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = 2157 -- itemID required to use the chest.
local prize = {2157, 2153, 2154, 2155, 2156} -- and so on...
local actionid = 1337 -- actionID of chest.
local count = 1 -- quantity of the item received EG. 1 = 1 SD. 10 = 10 SDs. 
 
if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
local randomChance = math.random(1, 5)
doPlayerAddItem(cid, prize[randomChance], count)
doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)

elseif getPlayerItemCount(cid, itemreq) < 1 then
doPlayerSendCancel(cid, cancel)
doSendMagicEffect(cid, CONST_ME_POFF)
end
return true
end
 
Last edited:
The poff animation isn't playing. and I still get a error in the console about atempting to index a nil value. at or below :11: it says something about :1: line aswell.

The players can't see this. I put in a cancel message that says they need a special item to use it. But everytime they gonan use it, wether or not they have the required item, this error shows up in the server console.
 
Optus your doing it all wrong.. I dunno what exactly does he need, i'm just fixing the script u scripted..
LUA:
function onUse(cid, item, frompos, item2, topos)
local itemreq = 2157 -- itemID required to use the chest.
local prize = {2157, 2153, 2154, 2155, 2156} -- and so on...
local actionid = 1337 -- actionID of chest.
local count = 1 -- quantity of the item received EG. 1 = 1 SD. 10 = 10 SDs. 
 
if item.actionid == actionid and getPlayerItemCount(cid, itemreq) >= 1 then
doPlayerRemoveItem(cid, itemreq, 1) 
local randomChance = math.random(1, 5)
doPlayerAddItem(cid, prize[randomChance], count)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
 
elseif getPlayerItemCount(cid, itemreq) == false then
doPlayerSendCancel(cid, 'You dont have the required item to participate in the lottery.')
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
return true
end
 
It works, nice effect thanks. But it won't send the cancel message for some reason. This item that I am using is a non usable object - it's not a container nor a shovel for example. It's a plain rock hard item that you (now) can rightclick to get random items in echange for this special item.

SO, it works when you have the item, everything is fine. But when you don't have the item, nothing happens, the cancel message does not appear >.<
 
Back
Top