• 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 Death Channel with diferent colors

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
Hi! Is possible to have a Death Channel showing who die in diferent colors? Like a dead for 1-3 player, monster or field in white text, 4-8 in orange and 9 or more in red?

Like that:
death channel.png

Thanks!
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
TFS version? Post your death channel script or you don't have 1 already?
TFS 1.3

I don't have one, I just found something similar, but I wouldn't know how to modify and confirm it works.


Lua:
function onDeath(cid, corpse, deathList)


local strings = {""}
local t, position = 1, 1

local deathType = "killed"
local toSlain, toCrushed, toEliminated = 3, 9, 15

if #deathList >= toSlain and #deathList < toCrushed then
deathType = "slain"
elseif #deathList >= toCrushed and #deathList < toEliminated then
deathType = "crushed"
elseif #deathList >= toEliminated then
deathType = "eliminated"
end

for _, pid in ipairs(deathList) do
if isCreature(pid) == true then
strings[position] = t == 1 and "" or strings[position] .. ", "
strings[position] = strings[position] .. getCreatureName(pid) .. ""
t = t + 1
else
strings[position] = t == 1 and "" or strings[position] .. ", "
strings[position] = strings[position] .."a field item"
t = t + 1
end
end

for i, str in ipairs(strings) do
if(str:sub(str:len()) ~= ",") then
str = str .. "."
end

msg = getCreatureName(cid) .. " was " .. deathType .. " at level " .. getPlayerLevel(cid) .. " by " .. str
end

for _, oid in ipairs(getPlayersOnline()) do
doPlayerSendChannelMessage(oid, "Death channel", msg, TALKTYPE_CHANNEL_O, CHANNEL_DEATH)
end
return true
end
 

M0ustafa

1337
Senator
Joined
Mar 4, 2017
Messages
2,562
Solutions
315
Reaction score
1,134
Location
Egypt
Create a script name it death.lua here data\chatchannels\scripts and add this to it
Lua:
function canJoin()
    return true
end

function onSpeak()
    return false
end
and in data\chatchannels\chatchannels.xml
XML:
<channel id="yourchannelid" name="Deaths" script="death.lua" />
then in data\creaturescripts\scripts create a script name it deathschannel.lua and add this to it
Lua:
function onDeath(cid, corpse)
    local creature = Creature(cid)
    local damageMap = creature:getDamageMap()
    for creatureId, damage in pairs(damageMap) do
        local thing = Creature(creatureId)
    end
    i = 0
    str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
    for _, pid in pairs(damageMap) do
        i = i + 1
        if (i == 1) then
            if(#damageMap <= 1) then
                str = str.." was killed by "
            elseif(#damageMap > 1 and #damageMap <= 4) then
                str = str.." was slain by "
            elseif(#damageMap > 4 and #damageMap <= 7) then
                str = str.." was crushed by "
            elseif(#damageMap > 7 and #damageMap <= 10) then
                str = str.." was eliminated by "
            elseif(#damageMap > 10) then
                str = str.." was annihilated by "
            end
        elseif (i == #damageMap) then
            str = str.." and "
        else
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end
    str = str.."."
    if(#damageMap <= 1) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 1 and #damageMap <= 4) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 4 and #damageMap <= 7) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 7 and #damageMap <= 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if (isMonster(pid)) then
    str = str.."a "..getCreatureName(pid):lower()
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    return true
end
and in data\creaturescripts\creaturescripts.xml add this
XML:
<event type="death" name="DeathsChannel" script="deathschannel.lua" />
You'll have to edit the script and change those lines
Lua:
sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
9 is your channel id and TALKTYPE_CHANNEL_R1 is the color
C++:
    registerEnum(TALKTYPE_SAY)
    registerEnum(TALKTYPE_WHISPER)
    registerEnum(TALKTYPE_YELL)
    registerEnum(TALKTYPE_PRIVATE_FROM)
    registerEnum(TALKTYPE_PRIVATE_TO)
    registerEnum(TALKTYPE_CHANNEL_Y)
    registerEnum(TALKTYPE_CHANNEL_O)
    registerEnum(TALKTYPE_PRIVATE_NP)
    registerEnum(TALKTYPE_PRIVATE_PN)
    registerEnum(TALKTYPE_BROADCAST)
    registerEnum(TALKTYPE_CHANNEL_R1)
    registerEnum(TALKTYPE_PRIVATE_RED_FROM)
    registerEnum(TALKTYPE_PRIVATE_RED_TO)
    registerEnum(TALKTYPE_MONSTER_SAY)
    registerEnum(TALKTYPE_MONSTER_YELL)
Not tested
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
Create a script name it death.lua here data\chatchannels\scripts and add this to it
Lua:
function canJoin()
    return true
end

function onSpeak()
    return false
end
and in data\chatchannels\chatchannels.xml
XML:
<channel id="yourchannelid" name="Deaths" script="death.lua" />
then in data\creaturescripts\scripts create a script name it deathschannel.lua and add this to it
Lua:
function onDeath(cid, corpse)
    local creature = Creature(cid)
    local damageMap = creature:getDamageMap()
    for creatureId, damage in pairs(damageMap) do
        local thing = Creature(creatureId)
    end
    i = 0
    str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
    for _, pid in pairs(damageMap) do
        i = i + 1
        if (i == 1) then
            if(#damageMap <= 1) then
                str = str.." was killed by "
            elseif(#damageMap > 1 and #damageMap <= 4) then
                str = str.." was slain by "
            elseif(#damageMap > 4 and #damageMap <= 7) then
                str = str.." was crushed by "
            elseif(#damageMap > 7 and #damageMap <= 10) then
                str = str.." was eliminated by "
            elseif(#damageMap > 10) then
                str = str.." was annihilated by "
            end
        elseif (i == #damageMap) then
            str = str.." and "
        else
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end
    str = str.."."
    if(#damageMap <= 1) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 1 and #damageMap <= 4) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 4 and #damageMap <= 7) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 7 and #damageMap <= 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if (isMonster(pid)) then
    str = str.."a "..getCreatureName(pid):lower()
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    return true
end
and in data\creaturescripts\creaturescripts.xml add this
XML:
<event type="death" name="DeathsChannel" script="deathschannel.lua" />
You'll have to edit the script and change those lines
Lua:
sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
9 is your channel id and TALKTYPE_CHANNEL_R1 is the color
C++:
    registerEnum(TALKTYPE_SAY)
    registerEnum(TALKTYPE_WHISPER)
    registerEnum(TALKTYPE_YELL)
    registerEnum(TALKTYPE_PRIVATE_FROM)
    registerEnum(TALKTYPE_PRIVATE_TO)
    registerEnum(TALKTYPE_CHANNEL_Y)
    registerEnum(TALKTYPE_CHANNEL_O)
    registerEnum(TALKTYPE_PRIVATE_NP)
    registerEnum(TALKTYPE_PRIVATE_PN)
    registerEnum(TALKTYPE_BROADCAST)
    registerEnum(TALKTYPE_CHANNEL_R1)
    registerEnum(TALKTYPE_PRIVATE_RED_FROM)
    registerEnum(TALKTYPE_PRIVATE_RED_TO)
    registerEnum(TALKTYPE_MONSTER_SAY)
    registerEnum(TALKTYPE_MONSTER_YELL)
Not tested
I will test! Thanks bro!
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
Create a script name it death.lua here data\chatchannels\scripts and add this to it
Lua:
function canJoin()
    return true
end

function onSpeak()
    return false
end
and in data\chatchannels\chatchannels.xml
XML:
<channel id="yourchannelid" name="Deaths" script="death.lua" />
then in data\creaturescripts\scripts create a script name it deathschannel.lua and add this to it
Lua:
function onDeath(cid, corpse)
    local creature = Creature(cid)
    local damageMap = creature:getDamageMap()
    for creatureId, damage in pairs(damageMap) do
        local thing = Creature(creatureId)
    end
    i = 0
    str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
    for _, pid in pairs(damageMap) do
        i = i + 1
        if (i == 1) then
            if(#damageMap <= 1) then
                str = str.." was killed by "
            elseif(#damageMap > 1 and #damageMap <= 4) then
                str = str.." was slain by "
            elseif(#damageMap > 4 and #damageMap <= 7) then
                str = str.." was crushed by "
            elseif(#damageMap > 7 and #damageMap <= 10) then
                str = str.." was eliminated by "
            elseif(#damageMap > 10) then
                str = str.." was annihilated by "
            end
        elseif (i == #damageMap) then
            str = str.." and "
        else
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end
    str = str.."."
    if(#damageMap <= 1) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 1 and #damageMap <= 4) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 4 and #damageMap <= 7) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 7 and #damageMap <= 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if(#damageMap > 10) and not (isMonster(pid)) then
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    if (isMonster(pid)) then
    str = str.."a "..getCreatureName(pid):lower()
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    end
    return true
end
and in data\creaturescripts\creaturescripts.xml add this
XML:
<event type="death" name="DeathsChannel" script="deathschannel.lua" />
You'll have to edit the script and change those lines
Lua:
sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
9 is your channel id and TALKTYPE_CHANNEL_R1 is the color
C++:
    registerEnum(TALKTYPE_SAY)
    registerEnum(TALKTYPE_WHISPER)
    registerEnum(TALKTYPE_YELL)
    registerEnum(TALKTYPE_PRIVATE_FROM)
    registerEnum(TALKTYPE_PRIVATE_TO)
    registerEnum(TALKTYPE_CHANNEL_Y)
    registerEnum(TALKTYPE_CHANNEL_O)
    registerEnum(TALKTYPE_PRIVATE_NP)
    registerEnum(TALKTYPE_PRIVATE_PN)
    registerEnum(TALKTYPE_BROADCAST)
    registerEnum(TALKTYPE_CHANNEL_R1)
    registerEnum(TALKTYPE_PRIVATE_RED_FROM)
    registerEnum(TALKTYPE_PRIVATE_RED_TO)
    registerEnum(TALKTYPE_MONSTER_SAY)
    registerEnum(TALKTYPE_MONSTER_YELL)
Not tested

I made all that steps, Death channel appeared on game, but dont showing deaths, and when I open it they show this:

Screenshot_1.png
 

M0ustafa

1337
Senator
Joined
Mar 4, 2017
Messages
2,562
Solutions
315
Reaction score
1,134
Location
Egypt
Did you change the channel-id? in Channels.xml? and on the scripts? Any errors on console? Looks like you just copied help-channel or you have duplicate id between Help-channel and Death-channel.
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
Did you change the channel-id? in Channels.xml? and on the scripts? Any errors on console? Looks like you just copied help-channel or you have duplicate id between Help-channel and Death-channel.
Screenshot_2.png

I try find this messenger on all data pack: "Welcome to the help channel."
Because my current Help Channel dont send this, and I didn't find anything
But, looking on the client executable code I found that exactly messenger.
 

M0ustafa

1337
Senator
Joined
Mar 4, 2017
Messages
2,562
Solutions
315
Reaction score
1,134
Location
Egypt
Just change channel id to different number, 9 is identified as Help channel in client so any channel with this id will have default Help channel message.
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
I change to 10 and dont receive more that msg of help channel like "Welcome to help", but when someone die or kill others, nothing happening on Death Channel.
 
OP
OP
masterash

masterash

Member
Joined
Jan 2, 2013
Messages
32
Reaction score
9
show us your current channels.xml and the lua script, or we can't help you.
chatchannels.xml
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel id="2" name="Tutor" script="tutor.lua" />
<channel id="3" name="World Chat" public="1" script="worldchat.lua" />
<channel id="4" name="English Chat" public="1" script="englishchat.lua" />
<channel id="5" name="Trade" public="1" script="advertising.lua" />
<channel id="6" name="Trade-Rookgaard" public="1" script="advertising-rook.lua" />
<channel id="7" name="Help" public="1" script="help.lua" />
<channel id="8" name="Gamemaster" script="gamemaster.lua" />
<channel id="10" name="Death Channel" script="death.lua" />
</channels>

deathchannel.lua
function onDeath(cid, corpse)
local creature = Creature(cid)
local damageMap = creature:getDamageMap()
for creatureId, damage in pairs(damageMap) do
local thing = Creature(creatureId)
end
i = 0
str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
for _, pid in pairs(damageMap) do
i = i + 1
if (i == 1) then
if(#damageMap <= 1) then
str = str.." was killed by "
elseif(#damageMap > 1 and #damageMap <= 3) then
str = str.." was slain by "
elseif(#damageMap > 3 and #damageMap <= 7) then
str = str.." was crushed by "
elseif(#damageMap > 7 and #damageMap <= 10) then
str = str.." was eliminated by "
elseif(#damageMap > 10) then
str = str.." was annihilated by "
end
elseif (i == #damageMap) then
str = str.." and "
else
str = str..", "
end

if not(isPlayer(pid) or isMonster(pid)) then
str = str.."a field"
elseif isSummon(pid) then
str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
elseif isPlayer(pid) then
str = str..""..getCreatureName(pid)
elseif isMonster(pid) then
str = str.."a "..getCreatureName(pid):lower()
end
end
str = str.."."
if(#damageMap <= 1) and not (isMonster(pid)) then
sendChannelMessage(10, TALKTYPE_CHANNEL_R1, str)
end
if(#damageMap > 1 and #damageMap <= 3) and not (isMonster(pid)) then
sendChannelMessage(10, TALKTYPE_CHANNEL_R1, str)
end
if(#damageMap > 3 and #damageMap <= 9) and not (isMonster(pid)) then
sendChannelMessage(10, TALKTYPE_CHANNEL_R1, str)
end
if(#damageMap > 9) and not (isMonster(pid)) then
sendChannelMessage(10, TALKTYPE_CHANNEL_R1, str)
end
if (isMonster(pid)) then
str = str.."a "..getCreatureName(pid):lower()
sendChannelMessage(10, TALKTYPE_CHANNEL_R1 str)
end
return true
end
creaturescripts.xml
<!-- Death Channel -->
<event type="death" name="DeathsChannel" script="deathschannel.lua" />
I am using TFS 1.3

Running that I dont have any error on distro, but dont work. The Death Channel can be open on game, but nothing happning.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,669
Solutions
405
Reaction score
3,782
Try a super simple version of the script for testing.

This will post a message to every channel, except 9.. and will also print a message to the console.

If you don't see a message in the console, then it's erroring on startUp.

If you don't see the message in the Death channel, check any of the other channels to see if it successfully posted there.


Lua:
function onDeath(cid, corpse)
    print("Someone has died. -- Server Console.")
    for i = 1, 10 do
        if i ~= 9 then
            sendChannelMessage(i, TALKTYPE_CHANNEL_R1, "Someone has died. " .. i)
        end
    end
    return true
end
 

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,956
Solutions
52
Reaction score
649
The problem is he wants everyone on the server to see the messages im sure. The code now is set up so only people that damage the thing that dies will get a message. Maybe he can say if this is the case.
 
Top