JesusAliso Posted February 12, 2024 Share Posted February 12, 2024 Quote --- Settings --- LOT_PRIZE_NUM = 1000 -- The lottery prize . LOT_PRIZE_PLUS = 100 -- If no one won the prize it will be increased , this is the plus number . LOT_PRIZE_PLUS_TIMES = 5 -- If no one won the prize it will be increased , this is how many times it will be increased -- LOT_TICKET_PRICE = 50 -- The Lottery ticket prize . LOT_NUM_LIMIT = 10 -- What is the higher lottery number . -- LOT_TIME_LIMIT_FROM,LOT_TIME_LIMIT_TO = 30,60 -- Random timer limit to start the lottery in seconds . LOT_RANDOM_NUMBER = 1 -- Random timer to make lottery in minutes . --- Script --- rRoot = resourceRoot -- LOT_NUM = nil LOT_PRIZE = nil LOT_ON = false LOT_INC = 0 LOT_TICKETS = {} LOT_WINNERS = {} -- function outLot(msg,to) if to then -- outputChatBox("**#00FF00[Loteria]#FFFF00 "..msg,to,255,0,0,true) else outputChatBox("**#00FF00[Loteria]#FFFF00 "..msg,root,255,0,0,true) end end function onLotStart() outputDebugString("Lottery By Al3grab | Started") -- local help = getResourceFromName("helpmanager") if not help then outLot("By Al3grab Started") else local state = getResourceState(help) if state == "running" then outLot("By Al3grab Started , Press F9 For Help") else outLot("By Al3grab Started") end end -- createRandomLot() end addEventHandler("onResourceStart",rRoot,onLotStart) function createRandomLot() local random:~ = math.random(1,tonumber(LOT_RANDOM_NUMBER)) if random:~ then outLot("La próxima lotería comenzará en #00FFFF"..tonumber(random:~).."#FFFF00 Minutos") random:~Timer = setTimer ( createLot , random:~ * 60 * 1000 , 1 ) end end function createLot(prize) if random:~Timer then if isTimer(random:~Timer) then killTimer(random:~Timer) end end LOT_NUM_LIMIT = LOT_NUM_LIMIT or 30 prize = prize or LOT_PRIZE_NUM -- local lot = math.floor(math.random(1,tonumber(LOT_NUM_LIMIT))) local lotTime = math.floor(math.random(LOT_TIME_LIMIT_FROM,LOT_TIME_LIMIT_TO)) local lotTime = lotTime * 1000 if lot and lotTime then startLottery( lot , lotTime , prize or 50000 , LOT_PRIZE_PLUS or 5000 , LOT_TICKET_PRICE or 5000 ) end end addCommandHandler("lottery",function(me,cmd,prize) if hasObjectPermissionTo(me,"command.shutdown") then createLot(prize or nil) end end , false ,false ) function startLottery ( LotNumber , StartAfter , Prize , Plus , TicketPrice ) if ( LotNumber and StartAfter and Prize and Plus and TicketPrice ) then outLot("La lotería comenzará en #00FFFF"..tonumber(math.floor(StartAfter/1000)).."#FFFF00 Segundos , El premio es #00FF00"..Prize.."$") outLot("Usa /Ticket <numero (1-"..tonumber(LOT_NUM_LIMIT)..")> Comando para comprar un billete, el billete cuesta: #00FF00"..TicketPrice.."$") LOT_NUM = LotNumber LOT_PRIZE = Prize LOT_INC = 0 LOT_ON = true setTimer( function () LOT_WINNERS = {} if ( LOT_TICKETS and type(LOT_TICKETS) == "table" ) then for k,v in ipairs ( LOT_TICKETS ) do local Player = v[1] local TicketNumber = v[2] if ( Player and TicketNumber ) then if TicketNumber == LOT_NUM then table.insert(LOT_WINNERS,Player) end end end -- if ( LOT_WINNERS ) then onLotteryFinish(LOT_WINNERS) end end end , StartAfter , 1 ) end end function onLotteryFinish ( table ) if ( table ) then outLot("El número de la suerte fue #00FFFF"..tonumber(LOT_NUM).."#FFFF00 !") if #table > 0 then outLot("Los ganadores son:") for k,v in ipairs ( table ) do if isElement(v) then outputChatBox("- "..getPlayerName(v),root,255,255,0,true) givePlayerMoney(v,LOT_PRIZE) end end -- destroyLottery(true) else outLot("¡Nadie ganó la lotería!") increaseLottery() end end end function increaseLottery() if ( tonumber(LOT_PRIZE_PLUS) ) then if LOT_INC ~= LOT_PRIZE_PLUS_TIMES then local LOT_INC = tonumber(LOT_PRIZE) + tonumber(LOT_PRIZE_PLUS) -- destroyLottery(false) outLot("La lotería se ha aumentado a #00FF00"..tonumber(LOT_INC).."$#FFFF00 !") createLot(LOT_INC) -- LOT_INC = LOT_INC + 1 else destroyLottery(true) end end end function destroyLottery(startNew) LOT_NUM = nil LOT_PRIZE = nil LOT_ON = false LOT_INC = 0 LOT_TICKETS = {} LOT_WINNERS = {} -- if startNew then createRandomLot() end end addCommandHandler("ticket",function ( me , cmd , number ) if LOT_ON then if tonumber(number) and tonumber(number) >= 1 and tonumber(number) <= tonumber(LOT_NUM_LIMIT) then if getPlayerMoney(me) >= LOT_TICKET_PRICE then outputChatBox("**#00FF00[Loteria]#FFFF00 Tu número es "..number..", buena suerte !",me,255,0,0,true) takePlayerMoney(me,LOT_TICKET_PRICE) -- table.insert(LOT_TICKETS,{me,tonumber(number)}) else outputChatBox("**#00FF00[Loteria]#FFFF00 no tienes #00FF00"..tonumber(LOT_TICKET_PRICE).."$",me,255,0,0,true) end else outputChatBox("**#00FF00[Loteria]#FFFF00 El numero para el Ticket debe estar entre 1-"..LOT_NUM_LIMIT.."",me,255,0,0,true) end else outputChatBox("**#00FF00[Loteria]#FFFF00 Ninguna Lotería está funcionando ahora !",me,255,0,0,true) end end , false , false ) Hello everyone, I found this lottery code and I would like to optimize it a little more. I haven't been here for a long time, but I would like to come back and learn a little more. How can I do this: -Limit the purchase of the ticket to 1, since the code allows you to buy 10 -Show the current lottery prize in an on-screen text If you can tell me in detail what functions/events I should use to do this, I would greatly appreciate it. I'm a newbie but I can learn. PD: I publish in the English section, since my Spanish language section is inactive PD: If anyone is interested in helping me with my server please contact me on discord, I don't have much to offer but I would like to learn Discord: .jesusaliso Link to comment
xMKHx Posted February 16, 2024 Share Posted February 16, 2024 LOT_NUM_LIMIT = 10 -- What is the higher lottery number . Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now