Advertisement
Guest User

tk

a guest
Jun 30th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. GuildPointsConfigs =
  2. {
  3. ExecuteIntervalHours = 24,
  4. NeedPlayersOnline = 1,
  5. NeedDiferentIps = 1,
  6. MinLevel = 80,
  7. AddPointsForAcc = 9
  8. }
  9.  
  10.  
  11. function getGuildPlayersValidAccIDS(GuildID, MinLevel)
  12. local RanksIDS, AccsID, ValidAccsID = {}, {}, {}
  13. local q = db.storeQuery("SELECT `id` FROM `guild_ranks` WHERE guild_id = '".. GuildID .."';")
  14.  
  15. if q then
  16. return ValidAccsID
  17. end
  18.  
  19. while true do
  20. table.insert(RanksIDS, result.getDataInt(q, "id"))
  21.  
  22. if not result.next(q) then
  23. break
  24. end
  25. end
  26.  
  27. local q = db.storeQuery("SELECT `account_id` FROM `players` WHERE `rank_id` IN (".. table.concat(RanksIDS, ', ') ..") AND `level` >= ".. MinLevel ..";")
  28. if q then
  29. return ValidAccsID
  30. end
  31.  
  32. while true do
  33. local AccID = result.getDataInt(q, "account_id")
  34. if #AccsID > 0 then
  35. for k = 1, #AccsID do
  36. if AccID == AccsID[k] then
  37. AddAccList = false
  38. break
  39. end
  40. AddAccList = true
  41. end
  42. if AddAccList then
  43. table.insert(AccsID, AccID)
  44. end
  45. else
  46. table.insert(AccsID, AccID)
  47. end
  48.  
  49. if not result.next(q) then
  50. break
  51. end
  52. end
  53.  
  54. local q = db.storeQuery("SELECT `id` FROM `accounts` WHERE `guild_points_stats` = 0 AND `id` IN (".. table.concat(AccsID, ', ') ..");")
  55.  
  56. if q then
  57. return ValidAccsID
  58. end
  59.  
  60. while true do
  61. local AccID = result.getDataInt(q, "id")
  62.  
  63. if #ValidAccsID > 0 then
  64. for k = 1, #ValidAccsID do
  65. if AccID == ValidAccsID[k] then
  66. AddAccList = false
  67. break
  68. end
  69. AddAccList = true
  70. end
  71. if AddAccList then
  72. table.insert(ValidAccsID, AccID)
  73. end
  74. else
  75. table.insert(ValidAccsID, AccID)
  76. end
  77.  
  78. if not result.next(q) then
  79. break
  80. end
  81. end
  82.  
  83. return ValidAccsID
  84. end
  85.  
  86.  
  87. function onSay(cid, words, param, channel)
  88. if(getPlayerGuildLevel(cid) == 3) then
  89. local GuildID = getPlayerGuildId(cid)
  90. local q = db.storeQuery("SELECT `last_execute_points` FROM `guilds` WHERE id = '".. GuildID .."';")
  91.  
  92. if not q then
  93. return true
  94. end
  95.  
  96. if result.getDataInt(q, "last_execute_points") < os.time() then
  97. local GuildMembers = {}
  98. local GuildMembersOnline = {}
  99. local PlayersOnline = getOnlinePlayers()
  100.  
  101. for _, pid in ipairs(getOnlinePlayers()) do
  102. if getPlayerGuildId(pid) == GuildID then
  103. if getPlayerLevel(pid) >= GuildPointsConfigs.MinLevel then
  104. table.insert(GuildMembersOnline, pid)
  105. end
  106. end
  107. end
  108.  
  109. if #GuildMembersOnline >= GuildPointsConfigs.NeedPlayersOnline then
  110. local IPS = {}
  111. for i, pid in ipairs(GuildMembersOnline) do
  112. local PlayerIP = getPlayerIp(pid)
  113. if #IPS > 0 then
  114. for k = 1, #IPS do
  115. if PlayerIP == IPS[k] then
  116. AddIPList = false
  117. break
  118. end
  119. AddIPList = true
  120. end
  121. if AddIPList then
  122. table.insert(IPS, PlayerIP)
  123. end
  124. else
  125. table.insert(IPS, PlayerIP)
  126. end
  127. end
  128. if #IPS >= GuildPointsConfigs.NeedDiferentIps then
  129. local ValidAccounts = getGuildPlayersValidAccIDS(GuildID, GuildPointsConfigs.MinLevel)
  130.  
  131. db.query("UPDATE `guilds` SET `last_execute_points` = ".. os.time() +(GuildPointsConfigs.ExecuteIntervalHours * 3600) .." WHERE `guilds`.`id` = ".. GuildID ..";")
  132.  
  133. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "".. #ValidAccounts .." Players received points")
  134.  
  135. if #ValidAccounts > 0 then
  136.  
  137. db.query("UPDATE `accounts` SET `guild_points` = `guild_points` + " ..GuildPointsConfigs.AddPointsForAcc .. ", `guild_points_stats` = ".. os.time() .." WHERE `id` IN (" .. table.concat(ValidAccounts, ',') ..");")
  138.  
  139. for i, pid in ipairs(GuildMembersOnline) do
  140. local PlayerMSGAccID = getPlayerAccountId(pid)
  141. for k = 1, #ValidAccounts do
  142. if PlayerMSGAccID == ValidAccounts[k] then
  143. doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, "You received "..GuildPointsConfigs.AddPointsForAcc .." guild points.")
  144. break
  145. end
  146. end
  147. end
  148. end
  149. else
  150. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Only ".. #IPS .." players are valid, you need ".. GuildPointsConfigs.NeedDiferentIps .." players with different ips.")
  151. end
  152. else
  153. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Has only ".. #GuildMembersOnline .." players online you need ".. GuildPointsConfigs.NeedPlayersOnline .." players online at least from level ".. GuildPointsConfigs.MinLevel ..".")
  154. end
  155. else
  156. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "The command can only be run once every "..GuildPointsConfigs.ExecuteIntervalHours .." hours.")
  157. end
  158. else
  159. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Only guild leader can request points.")
  160. end
  161. return true
  162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement