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

Lottery ticket

richux

Tibera.org
Joined
Aug 18, 2008
Messages
3,666
Reaction score
26
Location
---------
I would like to request action that would be simuliar the one lottery ticket. Its like, you use item, and than you get winning lottery ticket(item nr 1) or loose(item nr 2) I am totally a noob in lua, so I couldnt figure it out myself. It has something to do with mathrandom I think... Ehh, w/e

Here is the piggybank script(a bit simuliar) so it would be nice if someone modified it or told me how to do it:

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if math.random(1, 6) == 1 then
		doSendMagicEffect(fromPosition, CONST_ME_POFF)
		doPlayerAddItem(cid, ITEM_GOLD_COIN, 1)
		doTransformItem(item.uid, 2115)
	else
		doSendMagicEffect(fromPosition, CONST_ME_SOUND_YELLOW)
		doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
	end
	return TRUE
end
 
Code:
  function onUse(cid, item, fromPosition, itemEx, toPosition)
        if math.random(1, 6) == 1 then
                doSendMagicEffect(fromPosition, CONST_ME_POFF)
                doPlayerAddItem(cid, PUT_ITEM_ID_1_HERE, 1)
                doTransformItem(item.uid, 2115)
        else
                doSendMagicEffect(fromPosition, CONST_ME_SOUND_YELLOW)
                doPlayerAddItem(cid, PUT_ITEM_ID_2_HERE, 1)
        end
        return TRUE
end

Just change PUT_ITEM_ID_2_HERE and PUT_ITEM_ID_1_HERE

Like doPlayerAddItem(cid, 2400, 1)


++Rep if i helped
 
@nevalopo

Great, it works now! Only one more question, how to configure the script so it would be bigger chance to loose(to get one item more times than other when using the ticket)? However, you deserve rep! :)

Script atm:

LUA:
  function onUse(cid, item, fromPosition, itemEx, toPosition)
        if math.random(1, 6) == 1 then
                doSendMagicEffect(fromPosition, CONST_ME_SOUND_YELLOW)
				doPlayerSendTextMessage(cid,22,'Congratulations, you have won in lottery!')
				doTransformItem(item.uid, 5958)
        else
                doSendMagicEffect(fromPosition, CONST_ME_POFF)
				doPlayerSendTextMessage(cid,22,'Seems like you got a blank, try again!')
				doTransformItem(item.uid, 7696)
        end
        return TRUE
end


EDIT:
HAHA! I AM SO STUPID AINN't I?:D TO change chance of winning you have to change :

LUA:
if math.random(1, 6) == 1 then

This means that there is one chanse to win from 6 tickets.

kkthxbye!
 
Last edited:
There you go, just change the chance nothing more :p

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local chance = 30 -- chance in % to get the Winner Ticket
	if math.random(1,100) <= chance then
		doSendMagicEffect(fromPosition, CONST_ME_SOUND_YELLOW)
		doPlayerSendTextMessage(cid,22,'Congratulations, you have won in lottery!')
		doTransformItem(item.uid, 5958)
	else
		doSendMagicEffect(fromPosition, CONST_ME_POFF)
		doPlayerSendTextMessage(cid,22,'Seems like you got a blank, try again!')
		doTransformItem(item.uid, 7696)
	end
	return TRUE
end

kind regards, Evil Hero
 
Thanks Evil!
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Back
Top