Jump to content

Lottery


Best-Killer

Recommended Posts

Server-Side

local lottery = nil 
local winningNum = nil 
  
addEvent ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", true ) 
addEventHandler ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", root, function ( number )  
    local a = getPlayerAccount ( source ) 
    if ( isGuestAccount ( a ) ) then 
        return exports.SAEGMessages:sendClientMessage ( "Please login to use the lottery", source, 255, 0, 0 ) 
    end 
  
    if ( lottery [ getAccountName ( a ) ] ) then 
        return exports.SAEGMessages:sendClientMessage ( "You already bought the lottery ticket \""..tostring(lottery[getAccountName(a)]).."\"", source, 255, 255, 0 ) 
    end 
  
    for i, v in pairs ( lottery ) do 
        if ( v == number ) then 
            return exports.SAEGMessages:sendClientMessage ( "This number has already been bought.", source, 255, 255, 0 ) 
        end 
    end 
  
    if ( getPlayerMoney ( source ) < 100 ) then 
        return exports.SAEGMessages:sendClientMessage ( "You don't have enough money to buy a lottery ticket", 255, 0, 0 ) 
    end 
  
    takePlayerMoney ( source, 100 ) 
    exports.SAEGMessages:sendClientMessage ( "You have bought lottery ticket #"..tostring ( number ).."!", source, 0, 255, 0) 
    lottery[getAccountName(a)] = number 
end ) 
  
function winLottery ( ) 
    local winAccount = nil 
    local winner = nil 
    local num = getLotteryWinningNumber ( ) 
    for i, v in pairs ( lottery ) do 
        if ( v == num ) then 
            winAccount = i 
        end 
    end 
    if ( winAccount ) then 
        for i, v in pairs ( getElementsByType ( "player" ) ) do  
            local a = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( a ) and getAccountName ( a ) == winAccount ) then 
                winner = v 
            end 
        end 
    end 
    if ( winAccount and not winner ) then 
        winner = winaccount.." #ff0000(offline)" 
    elseif ( not winAccount ) then 
        winner = nil 
    end 
    exports.SAEGMessages:sendClientMessage("Lottery Winner is :"..tostring(winner or "Nobody")" Prize :"..tostring(prize), root, 0, 255, 0)  
    if ( winner ~= nil and getElementType ( winner ) == "player" ) then 
        exports.SAEGMessages:sendClientMessage("You won $"..tostring(prize).." from the lottery!", winner, 0, 255, 0) 
        givePlayerMoney ( winner, prize ) 
    end 
  
    generateNextLottery ( ) 
    getLastNumber ()  
end  
  
function generateNextLottery ( ) 
    lottery = { } 
    winningNum = math.random ( 1, 30 ) 
    prize = math.random ( 1, 2000000 ) 
    if ( isTimer ( lotTImer ) ) then 
        killTimer ( lotTImer ) 
        lotTImer = nil 
    end 
    lotTImer = setTimer ( winLottery, 1800000, 1) 
end  
  
function getLotteryWinningNumber ( ) 
    return winningNum 
end 
  
function getLotteryTimer ( ) 
    return lotTImer  
end 
  
generateNextLottery ( ) 
  
  
function getLastNumber ()  
    triggerClientEvent ( source, "SAEGLottery->onClientRequestWinDetails", source, getLotteryWinningNumber) 
end ) 

Client-Side

addEvent ( "SAEGLottery->onClientRequestWinDetails", true ) 
addEventHandler ( "SAEGLottery->onClientRequestWinDetails", root, function ( l )  
    guiSetText ( GUIEditor.label[5], "Last Jackpot: "..tostring ( l ) ) 
end ) 

i tried to get Last Number won but it's don't Work :/

0 errors / 0 warnings

Link to comment

Try this:

local lottery = nil 
local winningNum = nil 
  
addEvent ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", true ) 
addEventHandler ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", root, function ( number ) 
    local a = getPlayerAccount ( source ) 
    if ( isGuestAccount ( a ) ) then 
        return exports.SAEGMessages:sendClientMessage ( "Please login to use the lottery", source, 255, 0, 0 ) 
    end 
  
    if ( lottery [ getAccountName ( a ) ] ) then 
        return exports.SAEGMessages:sendClientMessage ( "You already bought the lottery ticket \""..tostring(lottery[getAccountName(a)]).."\"", source, 255, 255, 0 ) 
    end 
  
    for i, v in pairs ( lottery ) do 
        if ( v == number ) then 
            return exports.SAEGMessages:sendClientMessage ( "This number has already been bought.", source, 255, 255, 0 ) 
        end 
    end 
  
    if ( getPlayerMoney ( source ) < 100 ) then 
        return exports.SAEGMessages:sendClientMessage ( "You don't have enough money to buy a lottery ticket", 255, 0, 0 ) 
    end 
  
    takePlayerMoney ( source, 100 ) 
    exports.SAEGMessages:sendClientMessage ( "You have bought lottery ticket #"..tostring ( number ).."!", source, 0, 255, 0) 
    lottery[getAccountName(a)] = number 
end ) 
  
function winLottery ( ) 
    local winAccount = nil 
    local winner = nil 
    local num = getLotteryWinningNumber ( ) 
    for i, v in pairs ( lottery ) do 
        if ( v == num ) then 
            winAccount = i 
        end 
    end 
    if ( winAccount ) then 
        for i, v in pairs ( getElementsByType ( "player" ) ) do 
            local a = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( a ) and getAccountName ( a ) == winAccount ) then 
                winner = v 
            end 
        end 
    end 
    if ( winAccount and not winner ) then 
        winner = winaccount.." #ff0000(offline)" 
    elseif ( not winAccount ) then 
        winner = nil 
    end 
    exports.SAEGMessages:sendClientMessage("Lottery Winner is :"..tostring(winner or "Nobody")" Prize :"..tostring(prize), root, 0, 255, 0) 
    if ( winner ~= nil and getElementType ( winner ) == "player" ) then 
        exports.SAEGMessages:sendClientMessage("You won $"..tostring(prize).." from the lottery!", winner, 0, 255, 0) 
        givePlayerMoney ( winner, prize ) 
    end 
  
    generateNextLottery ( ) 
    getLastNumber () 
end 
  
function generateNextLottery ( ) 
    lottery = { } 
    winningNum = math.random ( 1, 30 ) 
    prize = math.random ( 1, 2000000 ) 
    if ( isTimer ( lotTImer ) ) then 
        killTimer ( lotTImer ) 
        lotTImer = nil 
    end 
    lotTImer = setTimer ( winLottery, 1800000, 1) 
end 
  
function getLotteryWinningNumber ( ) 
    return winningNum 
end 
  
function getLotteryTimer ( ) 
    return lotTImer 
end 
  
generateNextLottery ( ) 
  
  
function getLastNumber () 
    triggerClientEvent ( source, "SAEGLottery->onClientRequestWinDetails", source, winningNum) 
end ) 

Link to comment
local lottery = nil 
local winningNum = nil 
  
addEvent ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", true ) 
addEventHandler ( "SAEGLottery->onClientAttemptToBuyLotteryTicket", root, function ( number ) 
    local a = getPlayerAccount ( source ) 
    if ( isGuestAccount ( a ) ) then 
        return exports.SAEGMessages:sendClientMessage ( "Please login to use the lottery", source, 255, 0, 0 ) 
    end 
  
    if ( lottery [ getAccountName ( a ) ] ) then 
        return exports.SAEGMessages:sendClientMessage ( "You already bought the lottery ticket \""..tostring(lottery[getAccountName(a)]).."\"", source, 255, 255, 0 ) 
    end 
  
    for i, v in pairs ( lottery ) do 
        if ( v == number ) then 
            return exports.SAEGMessages:sendClientMessage ( "This number has already been bought.", source, 255, 255, 0 ) 
        end 
    end 
  
    if ( getPlayerMoney ( source ) < 100 ) then 
        return exports.SAEGMessages:sendClientMessage ( "You don't have enough money to buy a lottery ticket", 255, 0, 0 ) 
    end 
  
    takePlayerMoney ( source, 100 ) 
    exports.SAEGMessages:sendClientMessage ( "You have bought lottery ticket #"..tostring ( number ).."!", source, 0, 255, 0) 
    lottery[getAccountName(a)] = number 
end ) 
  
function winLottery ( ) 
    local winAccount = nil 
    local winner = nil 
    local num = getLotteryWinningNumber ( ) 
    for i, v in pairs ( lottery ) do 
        if ( v == num ) then 
            winAccount = i 
        end 
    end 
    if ( winAccount ) then 
        for i, v in pairs ( getElementsByType ( "player" ) ) do 
            local a = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( a ) and getAccountName ( a ) == winAccount ) then 
                winner = v 
            end 
        end 
    end 
    if ( winAccount and not winner ) then 
        winner = winaccount.." #ff0000(offline)" 
    elseif ( not winAccount ) then 
        winner = nil 
    end 
    outputChatBox ( "Winner: "..tostring(winer or "Nobody"), root, 255, 255, 255, true) 
    outputChatBox ( "Winning Number: #ffff00"..tostring ( num ), root, 255, 255, 255, true) 
    if ( winner ~= nil and getElementType ( winner ) == "player" ) then 
        exports.SAEGMessages:sendClientMessage("You won $"..tostring(prize).." from the lottery!", winner, 0, 255, 0) 
        givePlayerMoney ( winner, prize ) 
    end 
  
    generateNextLottery ( ) 
    getLastNumber ( ) 
end 
  
function generateNextLottery ( ) 
    lottery = { } 
    winningNum = math.random ( 1, 30 ) 
    prize = math.random ( 1, 2000000 ) 
    if ( isTimer ( lotTImer ) ) then 
        killTimer ( lotTImer ) 
        lotTImer = nil 
    end 
    lotTImer = setTimer ( winLottery, 50000, 1) 
end 
  
function getLotteryWinningNumber ( ) 
    return winningNum 
end 
  
function getLotteryTimer ( ) 
    return lotTImer 
end 
function getLastNumber ( ) 
    return winningNum 
end 
generateNextLottery ( ) 
getLastNumber ( ) 
  
  
addEvent ( "SAEGLottery->onClientRequestWinDetails", true ) 
addEventHandler ( "SAEGLottery->onClientRequestWinDetails", root, function ( )  
    triggerClientEvent ( source, "SAEGLottery->onClientRequestWinDetails", source, getLastNumber()) 
end ) 
  
addEvent ( "SAEGLotter->onClientRequestTimerDetails", true ) 
addEventHandler ( "SAEGLotter->onClientRequestTimerDetails", root, function ( ) 
    triggerClientEvent ( source, "SAEGLottery->onServerSendClientTimerDetails", source, convertMilSecsToTimer ( getTimerDetails ( getLotteryTimer ( ) ) )) 
end ) 
  
  
function convertMilSecsToTimer ( mil ) 
    local h = 0 
    local m = 0 
    local s = 0 
  
    while ( mil > 1000 ) do 
        s = s + 1 
        mil = mil - 1000 
    end 
  
    while ( s > 60 ) do 
        s = s - 60 
        m = m + 1 
    end  
  
    while ( m > 60 ) do 
        m = m - 60 
        h = h + 1 
    end 
  
    return tostring ( h ).."h "..tostring(m).."m "..tostring (s).."s" 
end  

new code 0 errors but still not showing :/ pls help me guys

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...