Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. function getLotteryPlayers()
  2. local players = {}
  3. for _, zid in pairs(getPlayersOnline()) do
  4. if getCreatureStorage(zid, 1300) == 1 and getPlayerAccess(zid) < 4 then
  5. table.insert(players, zid)
  6. end
  7. end
  8. return players
  9. end
  10.  
  11. local players = getLotteryPlayers()
  12.  
  13. local rewarditems = {
  14. {id = 9776, count = 1},
  15. {id = 2498, count = 1},
  16. {id = 2492, count = 1},
  17. {id = 2488, count = 1}
  18. }
  19.  
  20.  
  21. function onSay(cid, words, param, channel)
  22. local t = string.explode(param, ",")
  23. if (t[1] == 'open') then
  24.  
  25.  
  26. setGlobalStorageValue(1300, 1)
  27. doBroadcastMessage("".. getCreatureName(cid) .." is testing donation lottery.", MESSAGE_EVENT_ADVANCE)
  28. --doBroadcastMessage("".. getCreatureName(cid) .." has opened donation lottery to participate say /lotteryjoin for 100gn.", MESSAGE_EVENT_ADVANCE)
  29.  
  30. elseif (t[1] == 'roll') then
  31.  
  32. local storage = getGlobalStorageValue(1300)
  33.  
  34. if  storage == 1 then
  35.  
  36.     local players = getLotteryPlayers()
  37.     local list = {}
  38.     for i, tid in ipairs(players) do
  39.     list[i] = tid
  40.     end
  41.     local winner = list[math.random(1, #list)]
  42.     doBroadcastMessage('['.. getCreatureName(cid) ..'] has drawn the donation lottery and the winner is ['.. getCreatureName(winner) ..'] - Congratulations!', MESSAGE_EVENT_ADVANCE)
  43.     setGlobalStorageValue(1300, 0) 
  44.     for _, bid in pairs(getPlayersOnline()) do
  45.     if getCreatureStorage(bid, 1300) == 1 then
  46.     doPlayerSetStorageValue(bid, 1300, 0)
  47.     end
  48.     end
  49.  
  50.     else
  51.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Lottery is not open yet start it first.")
  52.     end
  53. end
  54. return true
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement