• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua talkactions guildpoints.lua error

Tiago Seeker

New Member
Joined
Jan 29, 2016
Messages
6
Reaction score
0
i talk this actions !guildpoints, for give a guild points for the player,

but ...

MuC6XW.png



this script guildpoints.lua

local config = {
executeInterval = 24,
minimumLevel = 20,
membersNeeded = 1,
minimumDifferentIps = 1,
pointAmount = 1
}

local function getValidAccounts(guild)
local resultId = db.storeQuery('SELECT a.`id` FROM `accounts` a, `guild_membership` m, `players` p WHERE m.`guild_id` = ' ..guild:getId() .. ' AND p.`id` = m.`player_id` AND p.`level` > ' .. config.minimumLevel .. ' and a.`id` = p.`account_id` AND a.`guild_points_stats` = 0 GROUP BY a.`id`;')
if resultId == false then
return {}
end

local accounts = {}
repeat
table.insert(accounts, result.getDataInt(resultId, 'id'))
until not result.next(resultId)
result.free(resultId)

return accounts
end

function onSay(cid, words, param, channel)
local player = Player(cid)
local guild = player:getGuild()
if not guild or player:getGuildLevel() ~= GUILDLEVEL_LEADER then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Only guild leader can request points.')
return false
end

local resultId = db.storeQuery('SELECT `last_execute_points` FROM `guilds` WHERE id = ' .. guild:getId())
if resultId == false then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendCancelMessage('Error while running database query.')
return false
end

local lastExecution = result.getDataInt(resultId, 'last_execute_points')
result.free(resultId)
if lastExecution >= os.time() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'The command can only be run once every ' ..config.executeInterval .. ' hours.')
return false
end

local members = guild:getMembersOnline()
for i = #members, 1, -1 do
if members:getLevel() < config.minimumLevel then
table.remove(members, i)
end
end

if #members < config.membersNeeded then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Only ' .. #members .. ' guild members online, you need ' ..config.membersNeeded .. ' guild members with level ' .. config.minimumLevel .. ' or higher.')
return false
end

local ipDictionary, ipCount = {}, 0
for i = 1, #members do
local ip = members:getIp()
if not ipDictionary[ip] then
ipDictionary[ip] = true
ipCount = ipCount + 1
end
end

if ipCount < config.minimumDifferentIps then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Only ' .. ipCount .. ' members are valid, you need ' ..config.minimumDifferentIps .. ' players with different ip addresses.')
return false
end

local validAccounts = getValidAccounts(guild)
db.query('UPDATE `guilds` SET `last_execute_points` = ' .. (os.time() + config.executeInterval * 3600) .. ' WHERE `guilds`.`id` = ' .. guild:getId() .. ';')
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, #validAccounts .. ' guild members received points.')
if #validAccounts > 0 then
db.query('UPDATE `accounts` SET `guild_points` = `guild_points` + ' .. config.pointAmount .. ', `guild_points_stats` = ' .. os.time() .. ' WHERE `id` IN (' .. table.concat(validAccounts, ',') .. ');')
for i = 1, #members do
local member = members
if isInArray(validAccounts, member:getAccountId()) then
member:sendTextMessage(MESSAGE_INFO_DESCR, 'You received ' .. config.pointAmount .. ' guild points.')
end
end
end
return false
end
 
Back
Top