• 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 /ban error

Larb

New Member
Joined
Nov 26, 2016
Messages
85
Reaction score
1
I add this script Solved - Need /ban with comment, and lenght for TFS 1.0 in my server but have this error
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/global.lua:155: attempt to index local 'str' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/global.lua:155: in function 'trim'
        data/talkactions/scripts/ban.lua:18: in function <data/talkactions/scrip
ts/ban.lua:3>

i need add
Lua:
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, minutes, reason\nFor example: /ban testName, Bug abuse, 1d")
and i use /ban testName Ban for default
tfs 1.2
 
Are you sure that you saved the file and restarted the server?
Add a print("test") after onSay to see if it actually reloaded, because I can get the functions to work.
https://moaifiddle.com/AT8U96OXE6/1
nil nil nil

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:eek:nSay
data/global.lua:146: attempt to index local 'str' (a nil value)
stack traceback:
[C]: in function '__index'
data/global.lua:146: in function 'split'
data/talkactions/scripts/ban.lua:18: in function <data/talkactions/scrip
ts/ban.lua:3>
 
nil nil nil

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:eek:nSay
data/global.lua:146: attempt to index local 'str' (a nil value)
stack traceback:
[C]: in function '__index'
data/global.lua:146: in function 'split'
data/talkactions/scripts/ban.lua:18: in function <data/talkactions/scrip
ts/ban.lua:3>

Seeing as the line numbers changed do you already have string.* functions in your global.lua?
In that case remove them and add the ones linked above.

Did it print nil nil nil?
In that case you didn't write print("test") it will either print nothing (aka it did not load the script) or it prints test.
 
Seeing as the line numbers changed do you already have string.* functions in your global.lua?
In that case remove them and add the ones linked above.

Did it print nil nil nil?
In that case you didn't write print("test") it will either print nothing (aka it did not load the script) or it prints test.
sorry my bad
i add in global
local param = "test1, test2, test3"
now in ban.lua
test1 test2 test3
test1 test2 test3
test1 test2 test3
test1 test2 test3
test1 test2 test3
test1 test2 test3
test1 test2 test3
My Global
Lua:
dofile('data/lib/libs.lua')

NOT_MOVEABLE_ACTION = 8000
PARTY_PROTECTION = 1 -- Set to 0 to disable.
ADVANCED_SECURE_MODE = 1 -- Set to 0 to disable.

STORAGEVALUE_PROMOTION = 30018



function doCreatureSayWithRadius(cid, text, type, radiusx, radiusy, position)
    if not position then
        position = Creature(cid):getPosition()
    end

    local spectators, spectator = Game.getSpectators(position, false, true, radiusx, radiusx, radiusy, radiusy)
    for i = 1, #spectators do
        spectator = spectators[i]
        spectator:say(text, type, false, spectator, position)
    end
end

function getBlessingsCost(level)
    if level <= 30 then
        return 2000
    elseif level >= 120 then
        return 20000
    else
        return (level - 20) * 200
    end
end

function isInRange(pos, fromPos, toPos)
    return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
end


function Creature.getMonster(self)
return self:isMonster() and self or nil
end

function getTibianTime()
    local worldTime = getWorldTime()
    local hours = math.floor(worldTime / 60)

    local minutes = worldTime % 60
    if minutes < 10 then
        minutes = '0' .. minutes
    end
    return hours .. ':' .. minutes
end

function getDistanceBetween(firstPosition, secondPosition)
    local xDif = math.abs(firstPosition.x - secondPosition.x)
    local yDif = math.abs(firstPosition.y - secondPosition.y)
    local posDif = math.max(xDif, yDif)
    if firstPosition.z ~= secondPosition.z then
        posDif = posDif + 15
    end
    return posDif
end

table.contains = function(array, value)
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

string.split = function(str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v
    end
    return res
end

string.trim = function(str)
    return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
end


-- Stamina
if nextUseStaminaTime == nil then
    nextUseStaminaTime = {}
end

-- CASAMENTO MARRY

PROPOSED_STATUS = 1
MARRIED_STATUS = 2
PROPACCEPT_STATUS = 3
LOOK_MARRIAGE_DESCR = TRUE
ITEM_WEDDING_RING = 2121
ITEM_ENGRAVED_WEDDING_RING = 10502

function getPlayerSpouse(id)
    local resultQuery = db.storeQuery("SELECT `marriage_spouse` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_spouse")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerSpouse(id, val)
    db.query("UPDATE `players` SET `marriage_spouse` = " .. val .. " WHERE `id` = " .. id)
end

function getPlayerMarriageStatus(id)
    local resultQuery = db.storeQuery("SELECT `marriage_status` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_status")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerMarriageStatus(id, val)
    db.query("UPDATE `players` SET `marriage_status` = " .. val .. " WHERE `id` = " .. id)
end

function Player:getMarriageDescription(thing)
    local descr = ""
    if getPlayerMarriageStatus(thing:getGuid()) == MARRIED_STATUS then
        playerSpouse = getPlayerSpouse(thing:getGuid())
        if self == thing then
            descr = descr .. " You are "
        elseif thing:getSex() == PLAYERSEX_FEMALE then
            descr = descr .. " She is "
        else
            descr = descr .. " He is "
        end
        descr = descr .. "married to " .. getPlayerNameById(playerSpouse) .. '.'
    end
    return descr
end

function say(param)
selfSay(text)
doCreatureSay(param.cid, param.text, 1)
end

function delayedSay(text, delay)
local delay = delay or 0
local cid = getNpcCid()
addEvent(say, delay, {cid = cid, text = text})
end
 
Last edited:
My Global
Lua:
dofile('data/lib/libs.lua')

NOT_MOVEABLE_ACTION = 8000
PARTY_PROTECTION = 1 -- Set to 0 to disable.
ADVANCED_SECURE_MODE = 1 -- Set to 0 to disable.

STORAGEVALUE_PROMOTION = 30018



function doCreatureSayWithRadius(cid, text, type, radiusx, radiusy, position)
    if not position then
        position = Creature(cid):getPosition()
    end

    local spectators, spectator = Game.getSpectators(position, false, true, radiusx, radiusx, radiusy, radiusy)
    for i = 1, #spectators do
        spectator = spectators[i]
        spectator:say(text, type, false, spectator, position)
    end
end

function getBlessingsCost(level)
    if level <= 30 then
        return 2000
    elseif level >= 120 then
        return 20000
    else
        return (level - 20) * 200
    end
end

function isInRange(pos, fromPos, toPos)
    return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
end


function Creature.getMonster(self)
return self:isMonster() and self or nil
end

function getTibianTime()
    local worldTime = getWorldTime()
    local hours = math.floor(worldTime / 60)

    local minutes = worldTime % 60
    if minutes < 10 then
        minutes = '0' .. minutes
    end
    return hours .. ':' .. minutes
end

function getDistanceBetween(firstPosition, secondPosition)
    local xDif = math.abs(firstPosition.x - secondPosition.x)
    local yDif = math.abs(firstPosition.y - secondPosition.y)
    local posDif = math.max(xDif, yDif)
    if firstPosition.z ~= secondPosition.z then
        posDif = posDif + 15
    end
    return posDif
end

table.contains = function(array, value)
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

string.split = function(str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v
    end
    return res
end

string.trim = function(str)
    return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
end


-- Stamina
if nextUseStaminaTime == nil then
    nextUseStaminaTime = {}
end

-- CASAMENTO MARRY

PROPOSED_STATUS = 1
MARRIED_STATUS = 2
PROPACCEPT_STATUS = 3
LOOK_MARRIAGE_DESCR = TRUE
ITEM_WEDDING_RING = 2121
ITEM_ENGRAVED_WEDDING_RING = 10502

function getPlayerSpouse(id)
    local resultQuery = db.storeQuery("SELECT `marriage_spouse` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_spouse")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerSpouse(id, val)
    db.query("UPDATE `players` SET `marriage_spouse` = " .. val .. " WHERE `id` = " .. id)
end

function getPlayerMarriageStatus(id)
    local resultQuery = db.storeQuery("SELECT `marriage_status` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_status")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerMarriageStatus(id, val)
    db.query("UPDATE `players` SET `marriage_status` = " .. val .. " WHERE `id` = " .. id)
end

function Player:getMarriageDescription(thing)
    local descr = ""
    if getPlayerMarriageStatus(thing:getGuid()) == MARRIED_STATUS then
        playerSpouse = getPlayerSpouse(thing:getGuid())
        if self == thing then
            descr = descr .. " You are "
        elseif thing:getSex() == PLAYERSEX_FEMALE then
            descr = descr .. " She is "
        else
            descr = descr .. " He is "
        end
        descr = descr .. "married to " .. getPlayerNameById(playerSpouse) .. '.'
    end
    return descr
end

function say(param)
selfSay(text)
doCreatureSay(param.cid, param.text, 1)
end

function delayedSay(text, delay)
local delay = delay or 0
local cid = getNpcCid()
addEvent(say, delay, {cid = cid, text = text})
end

Have you updated the correct file?
The error message does not match the file, so either you modified the file before uploading or it's the wrong file or server.
 
Have you updated the correct file?
The error message does not match the file, so either you modified the file before uploading or it's the wrong file or server.
yes, i making test in my computer before upload any files on dedicated server
 
how are you using the /ban command?
the string splits use "," not " ", you have to use commas inbetween your arguments
he even posted an example of how to use it.
Usage:
/ban playerName, reason, time

Ban with hours duration:
/ban testName, Botting, 30h

Ban with days duration:
/ban testName, Botting, 30d
 
how are you using the /ban command?
the string splits use "," not " ", you have to use commas inbetween your arguments
he even posted an example of how to use it.
but if i forget:
/ban Testbane, 3d, show this error
i need add for show it
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, minutes, reason\nFor example: /ban testName, Bug abuse, 1d")
 
but if i forget:
/ban Testbane, 3d, show this error
i need add for show it
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, minutes, reason\nFor example: /ban testName, Bug abuse, 1d")
Lua:
if param == "" then
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, reason, minutes\nFor example: /ban testName, Bug abuse, 1d")
end
reason comes before minutes in that script
 
Lua:
if param == "" then
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, reason, minutes\nFor example: /ban testName, Bug abuse, 1d")
end
reason comes before minutes in that script
Sorry for this reply, but where i insert this part in the script ?
 
Sorry for this reply, but where i insert this part in the script ?

Before the script starts to use param.
Lua:
local param = x

print(param)

In this case on line 2
Lua:
local param = x
if param == "" then
    return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, reason, minutes\nFor example: /ban testName, Bug abuse, 1d")
end

print(param)
 
Back
Top