ghettobird
LUA newbie
Hello OTland, so for the past few days I wanted to release a lottery system like none other,
1st of all I took some of the script from the other lottery system so some of the credits go to the creator of that script
Now first I will explain how this lottery system will work...
Every hour (u can change time ofc...) it will give a "suprise bag" to a player (only if he is online so it won't work if your ot has 0 online ) and for that surprise bag i created an action script which allows you to use it and get an item (i just used the items from the other script since i couldn't think of any myself )
So now let's start with the script...
Globalevents/scripts ---> lottery.lua
Now in globalevents.xml
So now we have the lottery script in globalevents, let's head to the actions folder so we can make the surprise bag which will be given randomly to any online player work
Actions/scripts -->
PS: I haven't had any time to actually test the surprise bag script but if you have any problems just post here and I'll gladly help (that's if limos doesn't answer before me )
now go to actions.xml
Also to avoid any misunderstandings I repeat what I have said earlier, I had the other lottery event script open when I scripted this one, so i give the creator some credit... But this script was created by me
1st of all I took some of the script from the other lottery system so some of the credits go to the creator of that script
Now first I will explain how this lottery system will work...
Every hour (u can change time ofc...) it will give a "suprise bag" to a player (only if he is online so it won't work if your ot has 0 online ) and for that surprise bag i created an action script which allows you to use it and get an item (i just used the items from the other script since i couldn't think of any myself )
So now let's start with the script...
Globalevents/scripts ---> lottery.lua
Code:
local config = {
lottery_hour = "1 Hours", -- after how many hours should lottery begin, explains itself really...
reward_count = 4, -- How much items/rewards? so you want 4 random items then write 4...
website = 1 -- Doesn't need explanation :p
}
function onThink(interval, lastExecution)
local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
if(config.website == 1) then
db.executeQuery("INSERT INTO `lottery` (`name`) VALUES ('".. getCreatureName(winner) .."');")
end
doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: Suprise Bag' ..'! - Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
doPlayerAddItem(winner, 6571,config.reward_count)
return TRUE
end
Now in globalevents.xml
Code:
<globalevent name="lottery" interval="4050000" event="script" value="lottery.lua"/>
So now we have the lottery script in globalevents, let's head to the actions folder so we can make the surprise bag which will be given randomly to any online player work
Actions/scripts -->
Code:
-- CREATED BY GHETTOBIRD --!
local PRESENT_BLUE = {2494, 2472} -- Add more items if you want just seperate them with an item id...
local PRESENT_RED = {2160, 2514} -- same as above ;)
function onUse(cid, item, fromPosition, itemEx, toPosition)
local count = 1
if(item.itemid == 6570) then
local randomChance = math.random(1, #PRESENT_BLUE)
if(randomChance == 1) then
count = 2
elseif(randomChance == 2) then
count = 2
end
doPlayerAddItem(cid, PRESENT_BLUE[randomChance], count)
elseif(item.itemid == 6571) then
local randomChance = math.random(1, #PRESENT_RED)
if randomChance > 0 and randomChance < 4 then
count = 2
end
doPlayerAddItem(cid, PRESENT_RED[randomChance], count)
end
doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
doRemoveItem(item.uid, 1)
return true
end
PS: I haven't had any time to actually test the surprise bag script but if you have any problems just post here and I'll gladly help (that's if limos doesn't answer before me )
now go to actions.xml
Code:
<action fromid="6570" toid="6571" event="script" value="surprisebag.lua"/>
Also to avoid any misunderstandings I repeat what I have said earlier, I had the other lottery event script open when I scripted this one, so i give the creator some credit... But this script was created by me