• 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+ Help to finish function sendColorText for otclient and client 12 official

beenii

Active Member
Joined
Jul 26, 2010
Messages
488
Solutions
1
Reaction score
32
I was using this function

Animated Text - Lua - 1.3


I'm trying to tweak it to work with all clients

Lua:
local function sendColorText(message, color, pos, send, cid)
    local player = Player(cid)
    if not player then
        return
    end
    -- this could also be handled inside of the calling function instead
    local clientid = player:getClient()['os']
    -- if the player is using otclient
    if clientid > 5 then
        local msg = NetworkMessage()
        msg:addByte(0x84)
        msg:addPosition(pos)
        msg:addByte(color)
        msg:addString(message)
        msg:sendToPlayer(player:getId())
        end
        if clientid <= 5 then
        player:say(message, MESSAGE_POTION, false, nil, pos)
        
        -- if send and next(send) then
            -- for i = 1, #send do
                -- if pos:getDistance(send[i]:getPosition()) <= 7 then
                  
                -- end
            -- end
        -- end
        return true
    end
end

i edited on this part color green:

if clientid > 5 then -- if otclient send msj in color
local msg = NetworkMessage()
msg:addByte(0x84)
msg:addPosition(pos)
msg:addByte(color)
msg:addString(message)
msg:sendToPlayer(player:getId()) -- player:getid() only shown to the connected player, not for everyone
end
if clientid <= 5 then -- if client 12 send message potion
player:say(message, MESSAGE_POTION, false, nil, pos)


original function: (if 2 players are in the same area, one with an otclient and the other with an official client 12, The official customer 12, his client crashes)


Lua:
local function sendColorText(message, color, pos, send, cid)
    local player = Player(cid)
    if not player then
        return
    end
    -- this could also be handled inside of the calling function instead
    local clientid = player:getClient()['os']
    -- if the player is using otclient
    if clientid > 3 then
        local msg = NetworkMessage()
        msg:addByte(0x84)
        msg:addPosition(pos)
        msg:addByte(color)
        msg:addString(message)
        if send and next(send) then
            for i = 1, #send do
                if pos:getDistance(send[i]:getPosition()) <= 7 then
                    msg:sendToPlayer(send[i])
                end
            end
        end
    end
end
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,072
Solutions
107
Reaction score
1,141
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
data/lib/core/position.lua
Lua:
function Position:sendAnimatedText(text, color, player)
    local spectators = player and {player} or Game.getSpectators(self, false, true)
    if #spectators == 0 then
        return
    end

    local newtworkMessage = NetworkMessage()
    newtworkMessage:addByte(0x84)
    newtworkMessage:addPosition(self)
    newtworkMessage:addByte(color or TEXTCOLOR_NONE)
    newtworkMessage:addString(text)
    for _, spectator in pairs(spectators) do
        if spectator:getClient().os > CLIENTOS_FLASH then
            newtworkMessage:sendToPlayer(spectator)
        else
            spectator:say(text, TALKTYPE_MONSTER_SAY, false, 0, self)
        end
    end
    newtworkMessage:delete()
    return true
end

example of use:
Lua:
-- for all spectators
position:sendAnimatedText("Hello World!", TEXTCOLOR_YELLOW)
-- for specific spectator
position:sendAnimatedText("Hello World!", TEXTCOLOR_YELLOW, player)
 
OP
OP
beenii

beenii

Active Member
Joined
Jul 26, 2010
Messages
488
Solutions
1
Reaction score
32
data/lib/core/position.lua
Lua:
function Position:sendAnimatedText(text, color, player)
    local spectators = player and {player} or Game.getSpectators(self, false, true)
    if #spectators == 0 then
        return
    end

    local newtworkMessage = NetworkMessage()
    newtworkMessage:addByte(0x84)
    newtworkMessage:addPosition(self)
    newtworkMessage:addByte(color or TEXTCOLOR_NONE)
    newtworkMessage:addString(text)
    for _, spectator in pairs(spectators) do
        if spectator:getClient().os > CLIENTOS_FLASH then
            newtworkMessage:sendToPlayer(spectator)
        else
            spectator:say(text, TALKTYPE_MONSTER_SAY, false, 0, self)
        end
    end
    newtworkMessage:delete()
    return true
end

example of use:
Lua:
-- for all spectators
position:sendAnimatedText("Hello World!", TEXTCOLOR_YELLOW)
-- for specific spectator
position:sendAnimatedText("Hello World!", TEXTCOLOR_YELLOW, player)


i try to make it work, but when 2 players are in the same place with different client, the player with the official client is crashed


I don't know how the "getSpectators" works, it seems that it gets confused when there are several players in the same place, it can't identify each one

Lua:
local config = {
    interval = 1500,
    texts = {
        { pos = Position(32346, 32222, 7), text = "Temple!", effects = { CONST_ME_TELEPORT, CONST_ME_DRAWBLOOD } },
        { pos = Position(32349, 32219, 7), text = "Bosses!", effects = { CONST_ME_ICEAREA, CONST_ME_ENERGYHIT } },
        { pos = Position(32348, 32219, 7), text = "Hunt!", effects = { CONST_ME_ENERGYAREA, CONST_ME_ENERGYHIT } },
        { pos = Position(32350, 32219, 7), text = "Quest!", effects = { CONST_ME_ENERGYAREA, CONST_ME_ENERGYHIT } }
    }
}

local textOnMapColor = GlobalEvent("TextOnMapColor")

function textOnMapColor.onThink(interval)
for k, info in pairs(config.texts) do
info.pos:sendAnimatedText(info.text, TEXTCOLOR_YELLOW)
 end
return true   
end

textOnMapColor:interval(config.interval)
textOnMapColor:register()
 
Top