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

GlobalEvent NEW LOTTERY SYSTEM, TFS 0.4

Do you like this new type of lottery where you get a bag and click on it?


  • Total voters
    14

ghettobird

LUA newbie
Joined
Aug 17, 2013
Messages
679
Reaction score
132
Location
OTland
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 :p) 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 :p)


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 :)
 
Thanks :)


@offtopic: Guys I just bought a dedicated server - 4 GB ram - windows server 2012 so i can open a free hosting service here... Be sure to check it out!
 
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 :p) 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 :p)


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 :)
isnt it for version 0.3.6? cuz i made it and doesn't work till now
 
isnt it for version 0.3.6? cuz i made it and doesn't work till now
I don't think you care by now, but I am extremely sorry for my late reply, I am nearly quitting OTland nowadays, no time for anything other than studying :/, however if I remember correctly I ran it in some of the 0.4 servers I hosted & it worked perfectly, so if you can just tell me what the error is (if I don't go offline again) I will gladly help you solve it...

My apologies again...
 
I don't think you care by now, but I am extremely sorry for my late reply, I am nearly quitting OTland nowadays, no time for anything other than studying :/, however if I remember correctly I ran it in some of the 0.4 servers I hosted & it worked perfectly, so if you can just tell me what the error is (if I don't go offline again) I will gladly help you solve it...

My apologies again...
mmm np man but there isn't any errors came on console
 
this script consists of 2 parts, an action & a globalevents part...

The globalevents part sends a "mystery box" to a random player, the actions part is where that player uses that box & get's an item...

Tell me which part didn't work?

Anyway ill read your comment tomorrow morning, try to specify more please so I work on it since I will have time tomorrow & after tomorrow, good night mate I'm out ! :)!
 
this script consists of 2 parts, an action & a globalevents part...

The globalevents part sends a "mystery box" to a random player, the actions part is where that player uses that box & get's an item...

Tell me which part didn't work?

Anyway ill read your comment tomorrow morning, try to specify more please so I work on it since I will have time tomorrow & after tomorrow, good night mate I'm out ! :)!
with globalevents >.<
 
thx its working good the problem was in time ,using 0.3.6
another problem
[22/12/2014 15:51:44] OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: no such table: lottery (INSERT INTO "lottery" ("name") VALUES ('Hakona Matata');)

@Limos
@Printer
@heba
@Ninja
 
Last edited:
@imback1 ; you didn't put the sql query for it, which makes the table "lottery"
-----------------
EDIT: I don't really remember how I did this script, no time to go over it really but tell me if this query works,
Code:
CREATE TABLE IF NOT EXISTS `lottery` (
  `player_id` int(11) NOT NULL,
  `numbers` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
@imback1 ; you didn't put the sql query for it, which makes the table "lottery"
-----------------
EDIT: I don't really remember how I did this script, no time to go over it really but tell me if this query works,
Code:
CREATE TABLE IF NOT EXISTS `lottery` (
  `player_id` int(11) NOT NULL,
  `numbers` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
near "ENGINE": syntax error:
@ghettobird
 
Last edited:
@imback1;
Code:
CREATE TABLE IF NOT EXISTS `lottery` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`item` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

This one worked fine for me
 
Back
Top