• 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!

Talkaction /giveall item, x tfs 1.2 error "explode"

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys, i got this script from the forum, buit it gives me an error, does anyone know how to fix it?
Lua:
function onSay(cid, words, param, channel)
    local t = string.explode(param, ",")
    if t[1] ~= nil and t[2] ~= nil then
        doBroadcastMessage(getPlayerName(cid) .. " give: " .. t[2] .." ".. getItemNameById(t[1]) .. " for all players online!")
        local list = {}
        for i, player in ipairs(getPlayersOnline()) do
            local playerIp = getPlayerIp(player)
            if not list[tostring(playerIp)] then
                list[tostring(playerIp)] = player
            end
        end
        if next(list) then
            for ip, pid in pairs(list) do
                if isPlayer(pid) then
                    doPlayerAddItem(pid, t[1], t[2])
                end
            end
        end
    else
        doPlayerPopupFYI(cid, "No param...\nSend:\n /itemadd itemid,how_much_items\nexample:\n /itemadd 2160,10")
    end
    return true
end


and i get this error:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/giveall.lua:onSay
data/talkactions/scripts/giveall.lua:2: attempt to call field 'explode' (a nil value)
stack traceback:
        [C]: in function 'explode'
        data/talkactions/scripts/giveall.lua:2: in function <data/talkactions/scripts/giveall.lua:1>

plz help :(
 
Solution
Try this:

Lua:
local function getEligiblePlayers()
    local list = {}
    local eligiblePlayers = {}
    for k,v in pairs(Game.getPlayers()) do
        local player = Player(v)
        if player then
            local IP = player:getIp()
            if not list[IP] then
                list[IP] = true
                table.insert(eligiblePlayers, player:getName())
            end
        end
    end
    return eligiblePlayers
end
     

function onSay(player, words, param, channel)
    local t = param:split(',')
 
    if not (t[1] and t[2]) then
        player:popupFYI('Incorrect Params:\n/itemadd ITEM_ID,COUNT\n\nExample:\n/itemadd 2160,10')
        return false
    end
 
    local iT = ItemType(tonumber(t[1]))
    if iT:getId() == 0...
Try to replace:
Code:
local t = string.explode(param, ",")

With:
Code:
local t = param:split(",")
 
Try to replace:
Code:
local t = string.explode(param, ",")

With:
Code:
local t = param:split(",")

didn't work :( i get this now
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/giveall.lua:onSay
data/talkactions/scripts/giveall.lua:4: attempt to call global 'getItemNameById' (a nil value)
stack traceback:
        [C]: in function 'getItemNameById'
        data/talkactions/scripts/giveall.lua:4: in function <data/talkactions/scripts/giveall.lua:1>
 
didn't work :( i get this now
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/giveall.lua:onSay
data/talkactions/scripts/giveall.lua:4: attempt to call global 'getItemNameById' (a nil value)
stack traceback:
        [C]: in function 'getItemNameById'
        data/talkactions/scripts/giveall.lua:4: in function <data/talkactions/scripts/giveall.lua:1>

It looks like the function getItemNameById doesn't exist in your distro.

I found this in compat.lua of 1.3: getItemName(itemId)
forgottenserver/compat.lua at bdd48705579998c3f7ef6de4778dbe8834ed29d4 · otland/forgottenserver · GitHub
 
Try this:

Lua:
local function getEligiblePlayers()
    local list = {}
    local eligiblePlayers = {}
    for k,v in pairs(Game.getPlayers()) do
        local player = Player(v)
        if player then
            local IP = player:getIp()
            if not list[IP] then
                list[IP] = true
                table.insert(eligiblePlayers, player:getName())
            end
        end
    end
    return eligiblePlayers
end
     

function onSay(player, words, param, channel)
    local t = param:split(',')
 
    if not (t[1] and t[2]) then
        player:popupFYI('Incorrect Params:\n/itemadd ITEM_ID,COUNT\n\nExample:\n/itemadd 2160,10')
        return false
    end
 
    local iT = ItemType(tonumber(t[1]))
    if iT:getId() == 0 then
        player:popupFYI('An item by the ID of  --> ' .. t[1] .. ' <-- does not exist.')
        return false
    end

    local count = tonumber(t[2])
    if not count then
        player:popupFYI('Count must be a number: ' .. t[2] .. ' is not a number.')
        return false
    end

    local players = getEligiblePlayers()
    if #players == 0 then
        player:popupFYI('There are not enough eligible players online. [ ' .. #players .. ']')
        return false
    end
 
    for k,v in pairs(players) do
        local p = Player(v)
        if p then
            p:addItem(iT:getId(), count)
        end
    end
 
    Game.broadcastMessage(player:getName() .. ' gifts: ' .. count .. ' ' .. (count > 1 and iT:getPluralName() or iT:getName()) .. ' for all players online.')
  return false
end
 
Last edited by a moderator:
Solution
Try this:

Code:
local function getEligiblePlayers()
    local list = {}
    local eligiblePlayers = {}
    for k,v in pairs(Game.getPlayers()) do
        local player = Player(v)
        if player then
            local IP = player:getIp()
            if not list[IP] then
                list[IP] = true
                table.insert(eligiblePlayers, player:getName())
            end
        end
    end
    return eligiblePlayers
end
     

function onSay(player, words, param, channel)
    local t = param:split(',')
 
    if not (t[1] and t[2]) then
        player:popupFYI('Incorrect Params:\n/itemadd ITEM_ID,COUNT\n\nExample:\n/itemadd 2160,10')
        return false
    end
 
    local iT = ItemType(tonumber(t[1]))
    if iT:getId() == 0 then
        player:popupFYI('An item by the ID of  --> ' .. t[1] .. ' <-- does not exist.')
        return false
    end

    local count = tonumber(t[2])
    if not count then
        player:popupFYI('Count must be a number: ' .. t[2] .. ' is not a number.')
        return false
    end

    local players = getEligiblePlayers()
    if #players == 0 then
        player:popupFYI('There are not enough eligible players online. [ ' .. #players .. ']')
        return false
    end
 
    for k,v in pairs(players) do
        local p = Player(v)
        if p then
            p:addItem(iT:getId(), count)
        end
    end
 
    Game.broadcastMessage(player:getName() .. ' gifts: ' .. count .. ' ' .. (count > 1 and iT:getPluralName() or iT:getName()) .. ' for all players online.')
  return false
end
thanks! it looks pretty now, but still doesn't give the item :/
nothing in console
 
No errors? put print(1) print(2) after the different parts to see what's going wrong.

I tested it on my server and works, but I use an edited TFS 1.1, maybe someone with a 1.2 environment set up can help u guys better.

AElPBPU.png
 
Last edited:
No errors? put print(1) print(2) after the different parts to see what's going wrong.

I tested it on my server and works, but I use an edited TFS 1.1, maybe someone with a 1.2 environment set up can help u guys better.

AElPBPU.png
it worked man im so sorry!! i was typing /giveall 2160, 1 instead of /giveall 2160,1
Thank you so much!
 
Back
Top