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

sendTextMessage to other channel instead of Default

Derlexy

Intermediate OT User
Joined
Jun 29, 2011
Messages
219
Reaction score
101
Hello guys. How can i send a message to a player on a specific channel? I have a bestiary system in my server, but i want to send all the messages related to it on a new channel ive created...

Im using the Nostalrius distro, its a TFS 1.2 server.

channels.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
    <channel id="2" name="Rule Violations" script="ruleviolations.lua" />
    <channel id="3" name="Tutor" script="tutor.lua" />
    <channel id="4" name="Game Chat" public="1" script="worldchat.lua" />
    <channel id="5" name="Real Chat" public="1" script="englishchat.lua" />
    <channel id="6" name="Trade" public="1" script="trade.lua" />
    <channel id="7" name="Help" public="1" script="help.lua" />
    <channel id="8" name="Gamemaster" script="gamemaster.lua" />
    <channel id="9" name="Bestiary" script="bestiary.lua" />
</channels>

scripts/bestiary.lua
Lua:
function onSpeak(player, type, message)
    player:sendCancelMessage("You cannot send messages on this channel.")
    return true
end

what i want to do (but in the channel ive created):
Lua:
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "[Bestiary]: You already killed " .. bestiaryGetPlayerTotalKills(player, monsterName) .. " " .. bestiaryGetPlural(monsterName) .. ". Kill a total of " .. bestiaryGetPlayerNeededKills(player, monsterName) .. " to achieve the " .. bestiaryGetNextRank(player, monsterName) .. " rank.")

Can someone help me?
 
player:sendChannelMessage(author, text, type, channelId)

if you need any function then use luascript.cpp then u just search for channel as I did and this appeard
 
Looking at the luascript.cpp for that specific repo, the function is declared as:
Lua:
player:channelSay(speaker, type, text, channelId)

You may also need to use openChannel too, depending on whether channelSay will automatically open the channel for you if not already open, but you should first test it out.
Lua:
player:openChannel(channelId)
 
player:sendChannelMessage(author, text, type, channelId)

if you need any function then use luascript.cpp then u just search for channel as I did and this appeard

Yeah, i've done that, but this function does not works the way i want... at least if im not doing anything wrong...

using the function:
Lua:
player:sendChannelMessage(killer, MESSAGE_STATUS_CONSOLE_ORANGE, "[Bestiary]: You already killed " .. bestiaryGetPlayerTotalKills(player, monsterName) .. " " .. bestiaryGetPlural(monsterName) .. ". Kill a total of " .. bestiaryGetPlayerNeededKills(player, monsterName) .. " to achieve the " .. bestiaryGetNextRank(player, monsterName) .. " rank.", 9)

result:
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/bestiary/creatureDeath.lua:onDeath
data/creaturescripts/scripts/bestiary/creatureDeath.lua:37: attempt to call method 'sendChannelMessage' (a nil value)
stack traceback:
        [C]: in function 'sendChannelMessage'
        data/creaturescripts/scripts/bestiary/creatureDeath.lua:37: in function <data/creaturescripts/scripts/bestiary/creatureDeath.lua:1>

This function requires a author, but im dont want to send a message from a player to another... I just want to make the orange console message to appear on the "Bestiary" channel i've created.

Looking at the luascript.cpp for that specific repo, the function is declared as:
Lua:
player:channelSay(speaker, type, text, channelId)

You may also need to use openChannel too, depending on whether channelSay will automatically open the channel for you if not already open, but you should first test it out.
Lua:
player:openChannel(channelId)

using the function:
Lua:
player:channelSay(killer, MESSAGE_STATUS_CONSOLE_ORANGE, "[Bestiary]: You already killed " .. bestiaryGetPlayerTotalKills(player, monsterName) .. " " .. bestiaryGetPlural(monsterName) .. ". Kill a total of " .. bestiaryGetPlayerNeededKills(player, monsterName) .. " to achieve the " .. bestiaryGetNextRank(player, monsterName) .. " rank.", 9)

result:
DgW0oTD.png


The bestiary channel is not global, its a dedicated channel that must have only the bestiary message of the player, not from all the players from the server.
 
channelSay eventually passes to ProtocolGame::AddCreatureSpeak

From here, you can see what specific parameter values you need to pass in order to get it sent to the right channel.
 
channelSay eventually passes to ProtocolGame::AddCreatureSpeak

From here, you can see what specific parameter values you need to pass in order to get it sent to the right channel.

I've tested the options, but every single one looks to require a "speaker". It worked, im able to send messages to the chat i've created, but only messages as if a player sent it. Looks like there is no option to send "game messages" through the channel... Maybe i'd have to create some in the sources?
 
Back
Top