• 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.2] creature:sendSquare(color, sec[,canSee])

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,643
Solutions
559
Reaction score
3,948
Usage: creature:sendSquare(color, sec [,canSee])

Example: creature:sendSquare(180, 5) -> Sends red colored square to creature for 5 seconds

Note: canSee should be a table argument such as: {'Playername', 'Playername2'}

Video

lib/core/creature.lua
Code:
local function sendSquare(cid, color, sec, n, send)
    local creature = Creature(cid)
    if not creature then
        return false
    end
    if n <= sec then
        local pos = creature:getPosition()
        local msg = NetworkMessage()
        msg:addByte(0x93)
        msg:addU32(cid)
        msg:addByte(0x01)
        msg:addByte(color)
        for i = 1, #send do
            if pos:getDistance(send[i]:getPosition()) <= 7 then
                msg:sendToPlayer(send[i])
            end
        end
        addEvent(sendSquare, 1000, cid, color, sec, n + 1, send)
    end
end

function Creature:sendSquare(color, sec, canSee, n)
    --// Creature:sendSquare(color, sec[, canSee])
    local pos = self:getPosition()

    --// Create a send table if canSee is an argument (otherwise uses spectators)
    local specs = Game.getSpectators(pos, false, true, 0, 8, 0, 6)
    local send = {}
    if canSee then
        if type(canSee) == 'table' then
            for i = 1, #specs do
                if isInArray(canSee, specs[i]:getName()) then
                    send[#send+1] = specs[i]
                end
            end
        else
            return print('Error [Creature:sendSquare] invalid argument type for canSee')
        end
    end
    send = (next(send) and send) or specs
    sendSquare(self:getId(), color, sec, (n and n+1) or 0, send)
    return true
end
 
Last edited:
1- You can use real send square function which is added on player.h
2- And it should be Player.sendSquare since this function is not related to creature itself while it's son ( player )
3- Tibia doesn't require the message to be sent only when creature(to be squared) is on screen or even being a known creature.

Some information about squares
The second byte ( length )
  • 0 means remove
  • 1 means flashing for a second
  • 2 means until another notification

----------------------------------------------
Information is shared by development of Fortissimum, especially E-PvP system.
 
Last edited:
updated function

1- You can use real send square function which is added on player.h
2- And it should be Player.sendSquare since this function is not related to creature itself while it's son ( player )
3- Tibia doesn't require the message to be sent only when creature(to be squared) is on screen or even being a known creature.

Some information about squares
The second byte ( length )
  • 0 means remove
  • 1 means flashing for a second
  • 2 means until another notification

----------------------------------------------
Information is shared by development of Fortissimum, especially E-PvP system.
forgot to address this but here i am 4 months later

1. yes i know but too lazy to implement it in sources
2. it is related to creature itself, this is for all creatures, not just player
3. yes i know, but there is no point in sending it if no one will be seeing it.
 
Can be possible if player is red skull it gets red square automatically until it loses? However, great work.
 
Can be possible if player is red skull it gets red square automatically until it loses? However, great work.
Code:
local skulls = {
    SKULL_YELLOW = TEXTCOLOR_YELLOW,
    SKULL_WHITE = TEXTCOLOR_WHITE,
    SKULL_RED = TEXTCOLOR_RED,
    SKULL_BLACK = TEXTCOLOR_BLACK,
    SKULL_ORANGE = TEXTCOLOR_ORANGE
}

local function sendSkullSquare(cid)
    local player = Player(cid)
    if not player then
        return
    end
    local skullColor = skulls[player:getSkull()]
    if skullColor then
        player:sendSquare(skullColor, 1)
        addEvent(sendSkullSquare, 1000, cid)
    end
end

function onLogin(player)
    sendSkullSquare(player:getId())
    return true
end
 
Doesn't work for some reason, can you send me a private message so I can specify more?
 
Last edited:
updated, small bugfix (couldn't send networkmessage through addevent) + rewrote canSee a bit (less confusing)
 
C++
const.h
Code:
enum SquareColor_t : uint8_t {
    SQ_COLOR_BLACK = 0,
    SQ_COLOR_BLUE = 5,
    SQ_COLOR_LIGHTGREEN = 30,
    SQ_COLOR_LIGHTBLUE = 35,
    SQ_COLOR_MAYABLUE = 95,
    SQ_COLOR_DARKRED = 108,
    SQ_COLOR_LIGHTGREY = 129,
    SQ_COLOR_SKYBLUE = 143,
    SQ_COLOR_PURPLE = 155,
    SQ_COLOR_RED = 180,
    SQ_COLOR_ORANGE = 198,
    SQ_COLOR_YELLOW = 210,
    SQ_COLOR_WHITE_EXP = 215,
    SQ_COLOR_NONE = 255,
};

luascript.cpp
Code:
registerEnum(SQ_COLOR_BLACK)
registerEnum(SQ_COLOR_BLUE)
registerEnum(SQ_COLOR_LIGHTGREEN)
registerEnum(SQ_COLOR_LIGHTBLUE)
registerEnum(SQ_COLOR_MAYABLUE)
registerEnum(SQ_COLOR_DARKRED)
registerEnum(SQ_COLOR_LIGHTGREY)
registerEnum(SQ_COLOR_SKYBLUE)
registerEnum(SQ_COLOR_PURPLE)
registerEnum(SQ_COLOR_RED)
registerEnum(SQ_COLOR_ORANGE)
registerEnum(SQ_COLOR_YELLOW)
registerEnum(SQ_COLOR_WHITE_EXP)
registerEnum(SQ_COLOR_NONE)

globals.lua
Code:
squareColors = {
    ['black'] = SQ_COLOR_BLACK,
    ['blue'] = SQ_COLOR_BLUE,
    ['light green'] = SQ_COLOR_LIGHTGREEN,
    ['light blue'] = SQ_COLOR_LIGHTBLUE,
    ['maya blue'] = SQ_COLOR_MAYABLUE,
    ['dark red'] = SQ_COLOR_DARKRED,
    ['light grey'] = SQ_COLOR_LIGHTGREY,
    ['sky blue'] = SQ_COLOR_SKYBLUE,
    ['purple'] = SQ_COLOR_PURPLE,
    ['red'] = SQ_COLOR_RED,
    ['orange'] = SQ_COLOR_ORANGE,
    ['yellow'] = SQ_COLOR_YELLOW,
    ['white'] = SQ_COLOR_WHITE_EXP,
    ['none'] = SQ_COLOR_NONE
}
 
C++
const.h
Code:
enum SquareColor_t : uint8_t {
    SQ_COLOR_BLACK = 0,
    SQ_COLOR_BLUE = 5,
    SQ_COLOR_LIGHTGREEN = 30,
    SQ_COLOR_LIGHTBLUE = 35,
    SQ_COLOR_MAYABLUE = 95,
    SQ_COLOR_DARKRED = 108,
    SQ_COLOR_LIGHTGREY = 129,
    SQ_COLOR_SKYBLUE = 143,
    SQ_COLOR_PURPLE = 155,
    SQ_COLOR_RED = 180,
    SQ_COLOR_ORANGE = 198,
    SQ_COLOR_YELLOW = 210,
    SQ_COLOR_WHITE_EXP = 215,
    SQ_COLOR_NONE = 255,
};

luascript.cpp
Code:
registerEnum(SQ_COLOR_BLACK)
registerEnum(SQ_COLOR_BLUE)
registerEnum(SQ_COLOR_LIGHTGREEN)
registerEnum(SQ_COLOR_LIGHTBLUE)
registerEnum(SQ_COLOR_MAYABLUE)
registerEnum(SQ_COLOR_DARKRED)
registerEnum(SQ_COLOR_LIGHTGREY)
registerEnum(SQ_COLOR_SKYBLUE)
registerEnum(SQ_COLOR_PURPLE)
registerEnum(SQ_COLOR_RED)
registerEnum(SQ_COLOR_ORANGE)
registerEnum(SQ_COLOR_YELLOW)
registerEnum(SQ_COLOR_WHITE_EXP)
registerEnum(SQ_COLOR_NONE)

globals.lua
Code:
squareColors = {
    ['black'] = SQ_COLOR_BLACK,
    ['blue'] = SQ_COLOR_BLUE,
    ['light green'] = SQ_COLOR_LIGHTGREEN,
    ['light blue'] = SQ_COLOR_LIGHTBLUE,
    ['maya blue'] = SQ_COLOR_MAYABLUE,
    ['dark red'] = SQ_COLOR_DARKRED,
    ['light grey'] = SQ_COLOR_LIGHTGREY,
    ['sky blue'] = SQ_COLOR_SKYBLUE,
    ['purple'] = SQ_COLOR_PURPLE,
    ['red'] = SQ_COLOR_RED,
    ['orange'] = SQ_COLOR_ORANGE,
    ['yellow'] = SQ_COLOR_YELLOW,
    ['white'] = SQ_COLOR_WHITE_EXP,
    ['none'] = SQ_COLOR_NONE
}

data\lib\core\constants.lua
Code:
TEXTCOLOR_BLACK = 0
TEXTCOLOR_BLUE = 5
TEXTCOLOR_GREEN = 18
TEXTCOLOR_TEAL = 35
TEXTCOLOR_LIGHTGREEN = 66
TEXTCOLOR_DARKBROWN = 78
TEXTCOLOR_LIGHTBLUE = 89
TEXTCOLOR_DARKPURPLE = 112
TEXTCOLOR_BROWN = 120
TEXTCOLOR_GREY = 129
TEXTCOLOR_DARKRED = 144
TEXTCOLOR_DARKPINK = 152
TEXTCOLOR_PURPLE = 154
TEXTCOLOR_DARKORANGE = 156
TEXTCOLOR_RED = 180
TEXTCOLOR_PINK = 190
TEXTCOLOR_ORANGE = 192
TEXTCOLOR_DARKYELLOW = 205
TEXTCOLOR_YELLOW = 210
TEXTCOLOR_WHITE = 215
TEXTCOLOR_NONE = 255
 
Last edited:
data\lib\core\constants.lua
Code:
TEXTCOLOR_BLACK = 0
TEXTCOLOR_BLUE = 5
TEXTCOLOR_GREEN = 18
TEXTCOLOR_TEAL = 35
TEXTCOLOR_LIGHTGREEN = 66
TEXTCOLOR_DARKBROWN = 78
TEXTCOLOR_LIGHTBLUE = 89
TEXTCOLOR_DARKPURPLE = 112
TEXTCOLOR_BROWN = 120
TEXTCOLOR_GREY = 129
TEXTCOLOR_DARKRED = 144
TEXTCOLOR_DARKPINK = 152
TEXTCOLOR_PURPLE = 154
TEXTCOLOR_DARKORANGE = 156
TEXTCOLOR_RED = 180
TEXTCOLOR_PINK = 190
TEXTCOLOR_ORANGE = 192
TEXTCOLOR_DARKYELLOW = 205
TEXTCOLOR_YELLOW = 210
TEXTCOLOR_WHITE = 215
TEXTCOLOR_NONE = 255
Yes I am aware of that I just added that code for 1 of 2 reasons it shows how to add more values to an enum but it also shows how to registering them for use outside of the server.

I did not update any of your code, but thought that this additional code was relevant to the body of the thread. Thank you for quoting my post and letting me know something which is pretty obvious since TEXTCOLOR_xx is where I obtained the values for the SQ_COLOR_xx enums.
 
Back
Top