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

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
201
Reaction score
15
hello, this can work that you can only say the command when the target is attacked?

If the command is executed without any target, this error appears

Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/talkactions/player/target.lua:callback
...rgottenserver/data/scripts/talkactions/player/target.lua:23: attempt to index local 'creature' (a nil value)
stack traceback:
        [C]: in function '__index'
        ...rgottenserver/data/scripts/talkactions/player/target.lua:23: in function <...rgottenserver/data/scripts/talkactions/player/target.lua:2>

And that the box lasted a little longer at least 10, 15 seconds

script.lua
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 210
    local pGuild = player:getGuild()
    if pGuild == nil then  return false  end -- no guild
    local pGuildRank = player:getGuildLevel()
    if pGuildRank and pGuildRank < 2 then return false end -- not vice or leader
    local spectators = Game.getSpectators(player:getPosition(), false, true, 7, 7, 5, 5) -- get all players on screen
    local creature = player:getTarget()
    local guildlst = {}

    for _, targetPlayer in ipairs(spectators) do
        if not targetPlayer:getGroup():getAccess() then
            sGuild = targetPlayer:getGuild()
            if sGuild and sGuild == pGuild then
                table.insert(guildlst, targetPlayer) -- check if in same guild as player
            end
        end

    end
    for _, guildPlayer in ipairs(guildlst) do
        guildPlayer:sendCreatureSquare(creature, color)
        guildPlayer:say(creature:getName() .. " - Test", TALKTYPE_MONSTER_SAY)
    end

    return false
end

guildTarget:register()

i used otbr tfs 1.3
 
Solution
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 210
    local pGuild = player:getGuild()
    if pGuild == nil then  return false  end -- no guild
    local pGuildRank = player:getGuildLevel()
    if pGuildRank and pGuildRank < 2 then return false end -- not vice or leader
    local spectators = Game.getSpectators(player:getPosition(), false, true, 7, 7, 5, 5) -- get all players on screen
    local creature = player:getTarget()
    local guildlst = {}

    for _, targetPlayer in ipairs(spectators) do
        if not targetPlayer:getGroup():getAccess() then
            sGuild = targetPlayer:getGuild()
            if sGuild and sGuild == pGuild then...
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 210
    local pGuild = player:getGuild()
    if pGuild == nil then  return false  end -- no guild
    local pGuildRank = player:getGuildLevel()
    if pGuildRank and pGuildRank < 2 then return false end -- not vice or leader
    local spectators = Game.getSpectators(player:getPosition(), false, true, 7, 7, 5, 5) -- get all players on screen
    local creature = player:getTarget()
    local guildlst = {}

    for _, targetPlayer in ipairs(spectators) do
        if not targetPlayer:getGroup():getAccess() then
            sGuild = targetPlayer:getGuild()
            if sGuild and sGuild == pGuild then
                table.insert(guildlst, targetPlayer) -- check if in same guild as player
            end
        end

    end
    for _, guildPlayer in ipairs(guildlst) do
        if creature then
           guildPlayer:sendCreatureSquare(creature, color)
           guildPlayer:say(creature:getName() .. " - Test", TALKTYPE_MONSTER_SAY)
        end
    end

    return false
end

guildTarget:register()
 
Solution
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 210
    local pGuild = player:getGuild()
    if pGuild == nil then  return false  end -- no guild
    local pGuildRank = player:getGuildLevel()
    if pGuildRank and pGuildRank < 2 then return false end -- not vice or leader
    local spectators = Game.getSpectators(player:getPosition(), false, true, 7, 7, 5, 5) -- get all players on screen
    local creature = player:getTarget()
    local guildlst = {}

    for _, targetPlayer in ipairs(spectators) do
        if not targetPlayer:getGroup():getAccess() then
            sGuild = targetPlayer:getGuild()
            if sGuild and sGuild == pGuild then
                table.insert(guildlst, targetPlayer) -- check if in same guild as player
            end
        end

    end
    for _, guildPlayer in ipairs(guildlst) do
        if creature then
           guildPlayer:sendCreatureSquare(creature, color)
           guildPlayer:say(creature:getName() .. " - Test", TALKTYPE_MONSTER_SAY)
        end
    end

    return false
end

guildTarget:register()
probably better to add the following bellow line #9
Lua:
if not creature then
    return false
end
 
Back
Top