Advertisement
Guest User

GUILDPOINTS

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