• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Talkactions not working. A nil value?

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,758
Solutions
127
Reaction score
2,277
Hello, I have problem with my talkaction. Its returning nil value error I dont know why, because these functions exist in tfs 1.2

03c5e91cfd40f54156e25782e110c351.png


Code:
local config = {
executeInterval = 168,
minimumLevel = 150,
membersNeeded = 1,
minimumDifferentIps = 1,
pointAmount = 50
}

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() ~= 3 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