• 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 Lua + select in mysql

TiagoTwo

New Member
Joined
Feb 5, 2013
Messages
18
Reaction score
0
I have this in my kills.lua
local kills = math.ceil(skullTime / fragTime)

but when Ido the talkactions, the result is :

14:25 You have 30 unjustified kills. The amount of unjustified kills will decrease after: 8 hours, 4 minutes and 24 seconds.

and I change thee local kills to this :

local kills = db.getResult("SELECT kills FROM players WHERE account_id =" ..player:getAccountId()..";")

but when I execute the talkaction, in my console have a error :

data/talkactions/scripts/kills.lua:14: attempt to call field 'getResult' (a nil value)
stack traceback:
[C]: in function 'getResult'
data/talkactions/scripts/kills.lua:14: in function <data/talkactions/scripts/kills.lua:1>

any player do !frags and the Frags is 30, only the frag I guess it's wrong, than, I change the local kills to select in the database the registre kills in players .. can help me ?

TFS 1.2

kills.lua

Code:
function onSay(player, words, param)

    local fragTime = configManager.getNumber(configKeys.FRAG_TIME)
    if fragTime <= 0 then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
        return false
    end

    local skullTime = player:getSkullTime()
    if skullTime <= 0 then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
        return false
    end

   -- I want to change this line to this
   --local kills = db.getResult("SELECT kills FROM players WHERE account_id =" ..player:getAccountId()..";")
    local kills = math.ceil(skullTime / fragTime)

    local remainingSeconds = math.floor((skullTime % fragTime) / 1000)

    local hours = math.floor(remainingSeconds / 3600)
    local minutes = math.floor((remainingSeconds % 3600) / 60)
    local seconds = remainingSeconds % 60

    local message = "You have " .. kills .. " unjustified kill" .. (kills > 1 and "s" or "") .. ". The amount of unjustified kills will decrease after: "
    if hours ~= 0 then
        if hours == 1 then
            message = message .. hours .. " hour, "
        else
            message = message .. hours .. " hours, "
        end
    end

    if hours ~= 0 or minutes ~= 0 then
        if minutes == 1 then
            message = message .. minutes .. " minute and "
        else
            message = message .. minutes .. " minutes and "
        end
    end

    if seconds == 1 then
        message = message .. seconds .. " second."
    else
        message = message .. seconds .. " seconds."
    end

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    return false
end
 
Code:
local result = db.storeQuery(query)

if result then
    local kills = result.getNumber(result, 'kills')
    ...
end
 
Code:
local result = db.storeQuery(query)

if result then
    local kills = result.getNumber(result, 'kills')
    ...
end

local result = db.storeQuery("SELECT skull FROM players WHERE account_id =" ..player:getAccountId()..";")

if result then
local kills = result.getNumber(result, 'skull')
end

Is it ?

and the error if is it :
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/kills.lua:eek:nSay
data/talkactions/scripts/kills.lua:18: attempt to index local 'result' (a number value)
stack traceback:
[C]: in function '__index'
data/talkactions/scripts/kills.lua:18: in function <data/talkactions/scripts/kills.lua:1>
 

In database my Skulls is type: TinyInt

error :
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/kills.lua:eek:nSay
data/talkactions/scripts/kills.lua:28: attempt to compare number with nil
stack traceback:
[C]: in function '__lt'
data/talkactions/scripts/kills.lua:28: in function <data/talkactions/scripts/kills.lua:1>

kills.lua line 28
local message = "You have " .. kills .. " unjustified kill" .. (kills > 1 and "s" or "") .. ". The amount of unjustified kills will decrease after: "

so, I delete this part of code :
.. (kills > 1 and "s" or "") ..

the result :
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/kills.lua:eek:nSay
data/talkactions/scripts/kills.lua:28: attempt to concatenate global 'kills' (a nil value)
stack traceback:
[C]: in function '__concat'
data/talkactions/scripts/kills.lua:28: in function <data/talkactions/scripts/kills.lua:1>


kills.lua
function onSay(player, words, param)

local fragTime = configManager.getNumber(configKeys.FRAG_TIME)
if fragTime <= 0 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
return false
end

local skullTime = player:getSkullTime()
if skullTime <= 0 then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
return false
end

local kills = math.ceil(skullTime / fragTime)
local remainingSeconds = math.floor((skullTime % fragTime) / 1000)
local hours = math.floor(remainingSeconds / 3600)
local minutes = math.floor((remainingSeconds % 3600) / 60)
local seconds = remainingSeconds % 60

local message = "You have " .. kills .. " unjustified kill" .. (kills > 1 and "s" or "") .. ". The amount of unjustified kills will decrease after: "
if hours ~= 0 then
if hours == 1 then
message = message .. hours .. " hour, "
else
message = message .. hours .. " hours, "
end
end

if hours ~= 0 or minutes ~= 0 then
if minutes == 1 then
message = message .. minutes .. " minute and "
else
message = message .. minutes .. " minutes and "
end
end
if seconds == 1 then
message = message .. seconds .. " second."
else
message = message .. seconds .. " seconds."
end

player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
return false
end
 
Last edited:
Back
Top