Lottery system (help) !

Discussion in 'Support' started by Glidarn, Jan 22, 2012.

  1. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    check post 8

    Attached Files:

    Last edited: Jan 23, 2012
  2. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
  3. Cykotitan

    Cykotitan Experienced G'

    Joined:
    Nov 4, 2008
    Messages:
    16,909
    /thread
  4. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    ye i don't understand, i changed it as should be.
  5. Cykotitan

    Cykotitan Experienced G'

    Joined:
    Nov 4, 2008
    Messages:
    16,909
    itemid:12608 itemcount: 1?
  6. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    yes, i did something but now he only getting this
  7. Cykotitan

    Cykotitan Experienced G'

    Joined:
    Nov 4, 2008
    Messages:
    16,909
    since you won't post the script, i'll have to guess that your libs (primarily 000-constant.lua) are outdated
  8. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    troll, anyway i removed he's char he made a new char i guess it will work now but i'm trying to add a lottery system wich has some errors and i'm kinda stuck on the npc error lotternpc.jpg

    [lua]-- Credits for inspiration and ideas to Azi, <a href="http://forum.otsmedia.eu/archive/index.php/thread-876.html" target="_blank">http://forum.otsmedia.eu/archive/ind...hread-876.html</a>
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local talkState = {}
    function onCreatureAppear(cid)
    npcHandler:eek:nCreatureAppear(cid)
    end
    function onCreatureDisappear(cid)
    npcHandler:eek:nCreatureDisappear(cid)
    end
    function onCreatureSay(cid, type, msg)
    npcHandler:eek:nCreatureSay(cid, type, msg)
    end
    function onThink()
    npcHandler:eek:nThink()
    end
    function creatureSayCallback(cid, type, msg)
    if(not(npcHandler:isFocused(cid))) then
    return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, "lottery")) then
    npcHandler:say("Welcome to our {lottery}. The lottery is a chance to get rich really quick! All you need to do is to {buy} a {ticket}, state four numbers from 1 to " .. lotteryConfig.maxNumber .. " and wait for the draw.", cid)
    elseif(msgcontains(msg, "buy") or msgcontains(msg, "ticket")) then
    npcHandler:say("Do you want to buy a ticket for a lottery?", cid)
    talkState[talkUser] = 1
    elseif(msgcontains(msg, "yes")) then
    if(talkState[talkUser] == 1) then
    if(db.getResult("SELECT * FROM `lottery` WHERE `player_id` = " .. getPlayerGUID(cid) .. ""):getID() < 1) then
    npcHandler:say("Please state four numbers from 1 to " .. lotteryConfig.maxNumber .. ". You can always state random numbers saying 'random'. Remember you cannot state two exact numbers.", cid)
    talkState[talkUser] = 2
    else
    npcHandler:say("You've already bought a ticket for this lottery.", cid)
    talkState[talkUser] = 0
    end
    end
    elseif(msgcontains(msg, "no")) then
    if(talkState[talkUser] > 0) then
    npcHandler:say("Then no.", cid)
    talkState[talkUser] = 0
    end
    elseif(talkState[talkUser] == 2) then
    local numbers = {}
    if(string.lower(msg) == "random") then
    repeat
    randomNumber = math.random(1, lotteryConfig.maxNumber)
    if(not(isInArray(numbers, randomNumber))) then
    table.insert(numbers, randomNumber)
    end
    until table.maxn(numbers) == lotteryConfig.numbersCount
    else
    if(string.explode(msg, ", ")) then
    if(table.maxn(string.explode(msg, ", ")) == lotteryConfig.numbersCount) then
    for i = 1, lotteryConfig.numbersCount do
    if(tonumber(string.explode(msg, ", ")) < 1 or tonumber(string.explode(msg, ", ")) > lotteryConfig.maxNumber or isInArray(numbers, string.explode(msg, ", "))) then
    npcHandler:say("The combination of numbers is wrong.", cid)
    talkState[talkUser] = 0
    return true
    end
    table.insert(numbers, string.explode(msg, ", "))
    end
    else
    npcHandler:say("You must state atleast " .. lotteryConfig.numbersCount .. " numbers.", cid)
    return true
    end
    else
    npcHandler:say("You can state numbers only.", cid)
    return true
    end
    end
    local output = ""
    for i = 1, lotteryConfig.numbersCount do
    if(i ~= lotteryConfig.numbersCount) then
    output = output .. numbers .. ", "
    else
    output = output .. numbers
    end
    end
    if(getPlayerMoney(cid) < lotteryConfig.ticketPrice) then
    npcHandler:say("You don't have enought money.", cid)
    talkState[talkUser] = 0
    else
    db.executeQuery("INSERT INTO `lottery` (`player_id`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", '" .. tostring(output) .. "')")
    npcHandler:say("Your numbers are " .. output .. ". I wish you good luck and big winnings!", cid)
    talkState[talkUser] = 0
    doPlayerRemoveMoney(cid, lotteryConfig.ticketPrice)
    end
    end
    return true
    end
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())[/lua]


    http://otland.net/f82/teckmans-lottery-system-139287/
    Last edited: Jan 23, 2012
  9. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    i would really need help with it since wanted to update this with tomorrows server save
  10. Evan

    Evan A splendid one to behold Staff Member Global Moderator

    Joined:
    May 6, 2009
    Messages:
    6,654
  11. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
  12. Evan

    Evan A splendid one to behold Staff Member Global Moderator

    Joined:
    May 6, 2009
    Messages:
    6,654
    Well, the error you have is saying that lotteryConfig does not exist.
    So, from the link I show, you need to add that table.
  13. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
  14. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    i added the queries but
    then the error is coming up -.-
  15. Evan

    Evan A splendid one to behold Staff Member Global Moderator

    Joined:
    May 6, 2009
    Messages:
    6,654
    What error?
  16. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    the on the pictures wich i attached on previous post
  17. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
    please, i really need this and the zombie thing since i'm updating the map tomorrow :/

    lottery
    troll, anyway i removed he's char he made a new char i guess it will work now but i'm trying to add a lottery system wich has some errors and i'm kinda stuck on the npc error View attachment 12036

    [lua]-- Credits for inspiration and ideas to Azi, <a href="http://forum.otsmedia.eu/archive/index.php/thread-876.html" target="_blank">http://forum.otsmedia.eu/archive/ind...hread-876.html</a>
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local talkState = {}
    function onCreatureAppear(cid)
    npcHandler:eek:nCreatureAppear(cid)
    end
    function onCreatureDisappear(cid)
    npcHandler:eek:nCreatureDisappear(cid)
    end
    function onCreatureSay(cid, type, msg)
    npcHandler:eek:nCreatureSay(cid, type, msg)
    end
    function onThink()
    npcHandler:eek:nThink()
    end
    function creatureSayCallback(cid, type, msg)
    if(not(npcHandler:isFocused(cid))) then
    return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, "lottery")) then
    npcHandler:say("Welcome to our {lottery}. The lottery is a chance to get rich really quick! All you need to do is to {buy} a {ticket}, state four numbers from 1 to " .. lotteryConfig.maxNumber .. " and wait for the draw.", cid)
    elseif(msgcontains(msg, "buy") or msgcontains(msg, "ticket")) then
    npcHandler:say("Do you want to buy a ticket for a lottery?", cid)
    talkState[talkUser] = 1
    elseif(msgcontains(msg, "yes")) then
    if(talkState[talkUser] == 1) then
    if(db.getResult("SELECT * FROM `lottery` WHERE `player_id` = " .. getPlayerGUID(cid) .. ""):getID() < 1) then
    npcHandler:say("Please state four numbers from 1 to " .. lotteryConfig.maxNumber .. ". You can always state random numbers saying 'random'. Remember you cannot state two exact numbers.", cid)
    talkState[talkUser] = 2
    else
    npcHandler:say("You've already bought a ticket for this lottery.", cid)
    talkState[talkUser] = 0
    end
    end
    elseif(msgcontains(msg, "no")) then
    if(talkState[talkUser] > 0) then
    npcHandler:say("Then no.", cid)
    talkState[talkUser] = 0
    end
    elseif(talkState[talkUser] == 2) then
    local numbers = {}
    if(string.lower(msg) == "random") then
    repeat
    randomNumber = math.random(1, lotteryConfig.maxNumber)
    if(not(isInArray(numbers, randomNumber))) then
    table.insert(numbers, randomNumber)
    end
    until table.maxn(numbers) == lotteryConfig.numbersCount
    else
    if(string.explode(msg, ", ")) then
    if(table.maxn(string.explode(msg, ", ")) == lotteryConfig.numbersCount) then
    for i = 1, lotteryConfig.numbersCount do
    if(tonumber(string.explode(msg, ", ")) < 1 or tonumber(string.explode(msg, ", ")) > lotteryConfig.maxNumber or isInArray(numbers, string.explode(msg, ", "))) then
    npcHandler:say("The combination of numbers is wrong.", cid)
    talkState[talkUser] = 0
    return true
    end
    table.insert(numbers, string.explode(msg, ", "))
    end
    else
    npcHandler:say("You must state atleast " .. lotteryConfig.numbersCount .. " numbers.", cid)
    return true
    end
    else
    npcHandler:say("You can state numbers only.", cid)
    return true
    end
    end
    local output = ""
    for i = 1, lotteryConfig.numbersCount do
    if(i ~= lotteryConfig.numbersCount) then
    output = output .. numbers .. ", "
    else
    output = output .. numbers
    end
    end
    if(getPlayerMoney(cid) < lotteryConfig.ticketPrice) then
    npcHandler:say("You don't have enought money.", cid)
    talkState[talkUser] = 0
    else
    db.executeQuery("INSERT INTO `lottery` (`player_id`, `numbers`) VALUES (" .. getPlayerGUID(cid) .. ", '" .. tostring(output) .. "')")
    npcHandler:say("Your numbers are " .. output .. ". I wish you good luck and big winnings!", cid)
    talkState[talkUser] = 0
    doPlayerRemoveMoney(cid, lotteryConfig.ticketPrice)
    end
    end
    return true
    end
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())[/lua]


    http://otland.net/f82/teckmans-lottery-system-139287/


    Solved the Zombie event but i really need help with the lottery system
    Last edited: Jan 24, 2012
  18. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
  19. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964
  20. Glidarn

    Glidarn Member

    Joined:
    May 9, 2009
    Messages:
    964

Share This Page