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

TFS 1.X+ admin giving a gift to all the active players by Command

Lua:
local giftId = 1234
for _, onlinePlayer in pairs(Game.getPlayers()) do
    local gift = Game.createItem(giftId, 1)
    local message = ("You have received %s."):format(gift:getNameDescription(gift:getSubType(), true))
    if not onlinePlayer:addItemEx(gift, false) then
        onlinePlayer:getInbox():addItemEx(gift, FLAG_NOLIMIT)
        message = ("%s It has been sent to your inbox because it couldn't be carried."):format(message)
    end

    onlinePlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
end
 
Last edited:
Lua:
local giftId = 1234
for _, onlinePlayer in pairs(Game.getPlayers()) do
    local gift = Game.createItem(giftId, 1)
    local message = ("You have received %s."):format(gift:getNameDescription(gift:getSubType(), true))
    if not onlinePlayer:addItemEx(gift, false) then
        onlinePlayer:getInbox():addItemEx(gift, FLAG_NOLIMIT)
        message = ("%s It has been sent to your inbox because it couldn't be carried."):format(message)
    end

    onlinePlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
end
Please give me the steps to do it
What commands are used to do that
Thanks for the help, I wish you good luck
 
Lua:
local giftId = 1234
for _, onlinePlayer in pairs(Game.getPlayers()) do
    local gift = Game.createItem(giftId, 1)
    local message = ("You have received %s."):format(gift:getNameDescription(gift:getSubType(), true))
    if not onlinePlayer:addItemEx(gift, false) then
        onlinePlayer:getInbox():addItemEx(gift, FLAG_NOLIMIT)
        message = ("%s It has been sent to your inbox because it couldn't be carried."):format(message)
    end

    onlinePlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
end

Lua Script Error: [Test Interface]
data/talkactions/scripts/Admin.lua
data/talkactions/scripts/Admin.lua:4: attempt to call method 'getNameDescription' (a nil value)
stack traceback:
[C]: in function 'getNameDescription'
data/talkactions/scripts/Admin.lua:4: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/Admin.lua
 
What engine you're using? Because i have no problems with this on tfs 1.5

Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    local giftId = 5092
    for _, onlinePlayer in pairs(Game.getPlayers()) do
    local gift = Game.createItem(giftId, 1)
    local message = ("You have received %s."):format(gift:getNameDescription(gift:getSubType(), true))
    if not onlinePlayer:addItemEx(gift, false) then
        onlinePlayer:getDepotChest(1, true):addItemEx(gift, FLAG_NOLIMIT)
        message = ("%s It has been sent to your inbox because it couldn't be carried."):format(message)
    end
        onlinePlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
    end
end
 
What engine you're using? Because i have no problems with this on tfs 1.5

Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    local giftId = 5092
    for _, onlinePlayer in pairs(Game.getPlayers()) do
    local gift = Game.createItem(giftId, 1)
    local message = ("You have received %s."):format(gift:getNameDescription(gift:getSubType(), true))
    if not onlinePlayer:addItemEx(gift, false) then
        onlinePlayer:getDepotChest(1, true):addItemEx(gift, FLAG_NOLIMIT)
        message = ("%s It has been sent to your inbox because it couldn't be carried."):format(message)
    end
        onlinePlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
    end
end
tfs 1.2 Tell me in detail where to add it?
What command should I use for this as well?
 
data/talkactions/scripts create file gift.lua and paste the script
open talkactions.xml and put something like this on admin commands
Lua:
    <talkaction words="/gift" script="gift.lua" />
 
Back
Top