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

RevScripts [OTBR] Help talkaction !target

miguelshta

Member
Joined
Mar 21, 2009
Messages
351
Solutions
1
Reaction score
13
Location
Toronto, Canada
I’m trying to do this command
unknown.png

Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local creature = target()
    local color = 11


    player:sendCreatureSquare(creature, color)
    return false
end

guildTarget:register()
Post automatically merged:

@Sarah Wesker
 
Last edited:
The code itself is almost correct, just one thing is wrong.

Replace:
Code:
local creature = target()

with:

Code:
local creature =player:getTarget()

The problem is, this is not the only thing that needs to be modified.

As the command should work for whole guild, source modification is nessesary.

Because now, it will only set the square for player that uses the command.
 
sendCreatureSquare isn't available in luascript.cpp as far as I can see. So you will need to add that in.
As for a "hacky" bit of code without to much source edits.
If you test it with chars on screen, you will see only guild members will creature say.

You don't need as many loops but I did it as a quick test and wanted to see the data in the different tables.
Rest is up to you.
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 11
    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()
 
C++:
int LuaScriptInterface::luaSendCreatureSquare(lua_State* L)
{
    // player:sendCreatureSquare(creature, color)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
    return 1;
    }

    Creature* creature = getUserdata<Creature>(L, 2);
    if (!creature) {
        lua_pushnil(L);
    return 1;
    }

    uint32_t color = getNumber<uint32_t>(L, 3, 0);

    player->sendCreatureSquare(creature, static_cast <SquareColor_t>(color));
    lua_pushboolean(L, true);
    return 1;
}

This is the sendCreatureSquare function, made by me in other forum. Click here
 
C++:
int LuaScriptInterface::luaSendCreatureSquare(lua_State* L)
{
    // player:sendCreatureSquare(creature, color)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
    return 1;
    }

    Creature* creature = getUserdata<Creature>(L, 2);
    if (!creature) {
        lua_pushnil(L);
    return 1;
    }

    uint32_t color = getNumber<uint32_t>(L, 3, 0);

    player->sendCreatureSquare(creature, static_cast <SquareColor_t>(color));
    lua_pushboolean(L, true);
    return 1;
}

This is the sendCreatureSquare function, made by me in other forum. Click here
Nice one.
 
sendCreatureSquare isn't available in luascript.cpp as far as I can see. So you will need to add that in.
As for a "hacky" bit of code without to much source edits.
If you test it with chars on screen, you will see only guild members will creature say.

You don't need as many loops but I did it as a quick test and wanted to see the data in the different tables.
Rest is up to you.
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 11
    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()
can you help me again? the script works good but i wanted to add exaustion of 10 seconds also the duration of the square "modificable" because it has no duration when i use the command the square appear for like 1 second
 
sendCreatureSquare isn't available in luascript.cpp as far as I can see. So you will need to add that in.
As for a "hacky" bit of code without to much source edits.
If you test it with chars on screen, you will see only guild members will creature say.

You don't need as many loops but I did it as a quick test and wanted to see the data in the different tables.
Rest is up to you.
Lua:
local guildTarget = TalkAction("!target")
function guildTarget.onSay(player, words, param)
    local color = 11
    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()
Can it 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
 
Back
Top