• 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 Help Script channel

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
Hello, I'm trying to make an script to appear [Staff] before the nick if the player are Account tutor, could someone help?

tfs 1.2

Script:
Lua:
local CHANNEL_HELP = 7

local muted = Condition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT)
muted:setParameter(CONDITION_PARAM_SUBID, CHANNEL_HELP)
muted:setParameter(CONDITION_PARAM_TICKS, 3600000)

local exhausted = createConditionObject(CONDITION_CHANNELMUTEDTICKS)
setConditionParam(exhausted, CONDITION_PARAM_SUBID, CHANNEL_HELP)
setConditionParam(exhausted, CONDITION_PARAM_TICKS, 120000)

function onSpeak(player, type, message)
    local playerAccountType = player:getAccountType()
    if player:getLevel() <= 100 and playerAccountType == ACCOUNT_TYPE_NORMAL then
        player:sendCancelMessage("You may not speak into channels if you are level less than 100.")
        return false
    end

     if(getCreatureCondition(player, CONDITION_CHANNELMUTEDTICKS, CHANNEL_HELP)) and playerAccountType == ACCOUNT_TYPE_NORMAL then
         player:sendCancelMessage("You may only ask a question once every 2 minutes.")
            return false
        end
 
    if getPlayerGroupId(player) <= 1 then
        doAddCondition(player, exhausted)
    end
  
    if player:getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP) then
        player:sendCancelMessage("You are muted from the Help channel for using it inappropriately.")
        return false
    end

    if playerAccountType >= ACCOUNT_TYPE_TUTOR then
        if string.sub(message, 1, 6) == "!mute " then
            local targetName = string.sub(message, 7)
            local target = Player(targetName)
            if target ~= nil then
                if playerAccountType > target:getAccountType() then
                    if not target:getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP) then
                        target:addCondition(muted)
                        sendChannelMessage(CHANNEL_HELP, TALKTYPE_CHANNEL_R1, target:getName() .. " has been muted by " .. player:getName() .. " for using Help Channel inappropriately.")
                    else
                        player:sendCancelMessage("That player is already muted.")
                    end
                else
                    player:sendCancelMessage("You are not authorized to mute that player.")
                end
            else
                player:sendCancelMessage(RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE)
            end
            return false
        elseif string.sub(message, 1, 8) == "!unmute " then
            local targetName = string.sub(message, 9)
            local target = Player(targetName)
            if target ~= nil then
                if playerAccountType > target:getAccountType() then
                    if target:getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP) then
                        target:removeCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP)
                        sendChannelMessage(CHANNEL_HELP, TALKTYPE_CHANNEL_R1, target:getName() .. " has been unmuted by " .. player:getName() .. ".")
                    else
                        player:sendCancelMessage("That player is not muted.")
                    end
                else
                    player:sendCancelMessage("You are not authorized to unmute that player.")
                end
            else
                player:sendCancelMessage(RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE)
            end
            return false
        end
    -- HERE 
        local info = "Staff"
        sendChannelMessage(10, type, player:getName() .. " [" .. info .. "]: " .. message)
    end

    if type == TALKTYPE_CHANNEL_Y then

        if playerAccountType == ACCOUNT_TYPE_TUTOR then
            type = TALKTYPE_CHANNEL_O

            elseif playerAccountType >= ACCOUNT_TYPE_SENIORTUTOR then

            type = TALKTYPE_CHANNEL_O
        end
    elseif type == TALKTYPE_CHANNEL_O then
 
        if playerAccountType < ACCOUNT_TYPE_TUTOR and not getPlayerFlagValue(player, PlayerFlag_TalkOrangeHelpChannel) then
            type = TALKTYPE_CHANNEL_Y

        end
    elseif type == TALKTYPE_CHANNEL_O then

        if playerAccountType < ACCOUNT_TYPE_GAMEMASTER and not getPlayerFlagValue(player, PlayerFlag_CanTalkRedChannel) then

            if playerAccountType >= ACCOUNT_TYPE_TUTOR or getPlayerFlagValue(player, PlayerFlag_TalkOrangeHelpChannel) then

                type = TALKTYPE_CHANNEL_O
            else

                type = TALKTYPE_CHANNEL_Y
            end
        end
    end
    return type
end
 
Last edited by a moderator:
This function is only for message content.
You can change this information in player.h, something like this:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        author = getAccountType() >= ACCOUNT_TYPE_TUTOR ? "[Staff] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
    }
}

Or check channel id:

C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        author = getAccountType() >= ACCOUNT_TYPE_TUTOR && channel == 7 ? "[Staff] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
    }
}
 
This function is only for message content.
You can change this information in player.h, something like this:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        author = getAccountType() >= ACCOUNT_TYPE_TUTOR ? "[Staff] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
    }
}

Or check channel id:

C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        author = getAccountType() >= ACCOUNT_TYPE_TUTOR && channel == 7 ? "[Staff] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
    }
}

Wow, very nice, thanks.
This is correctly?:

C++:
if (client) {
        author = getAccountType() == ACCOUNT_TYPE_TUTOR ? "[Tutor] " + author : author or author = getAccountType() == ACCOUNT_TYPE_GOD ? "[God] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
 
Wow, very nice, thanks.
This is correctly?:

C++:
if (client) {
        author = getAccountType() == ACCOUNT_TYPE_TUTOR ? "[Tutor] " + author : author or author = getAccountType() == ACCOUNT_TYPE_GOD ? "[God] " + author : author;
        client->sendChannelMessage(author, text, type, channel);
C++:
author = getAccountType() == ACCOUNT_TYPE_GOD ? "[God] " + author : getAccountType() == ACCOUNT_TYPE_GOD ? "[Tutor] " + author : author;
 
C++:
author = getAccountType() == ACCOUNT_TYPE_GOD ? "[God] " + author : getAccountType() == ACCOUNT_TYPE_GOD ? "[Tutor] " + author : author;
hello, thanks. I got one error look please?:

C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
             if (client) {
       
        author = getAccountType() == ACCOUNT_TYPE_GOD ? "[God] " + author : getAccountType() == ACCOUNT_TYPE_GOD ? "[Tutor] " + author : author;
        }
        }

VvJ5iSB.png
 
Actually you don't need to do this as long as your server has function to send channel message. At least in TFS 1.3 there is function sendChannelMessage(channelId, type, message)

All you need to do is return false in the onSpeak event and send the new message instead using sendChannelMessage.

sendChannelMessage(channelId, type, "[God] " .. message)

Just like that and change channelId and put this right before the "return type" and change it to "return false"
 
Last edited:
hello, thanks. I got one error look please?:

Simplify this:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        if (getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[God] " + author;
        } else if (getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[Tutor] " + author;
        }

        client->sendChannelMessage(author, text, type, channel);
    }
}
 
Simplify this:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        if (getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[God] " + author;
        } else if (getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[Tutor] " + author;
        }

        client->sendChannelMessage(author, text, type, channel);
    }
}

thanks again, but another error:
u8XDEJZ.png
 
//sendChannelMessage(channelId, type, message)

if playerAccountType >= ACCOUNT_TYPE_TUTOR then

sendChannelMessage(channelId, type, "[Staff] " .. message)

return false
end
 
Lua:
local prefixes = {
    [1] = "[Tutor]",
    [2] = "[GM]",
    [3] = "[GOD]"
}

function onSpeak(player, type, message)
    local groupId = player:getGroup():getId()
    sendChannelMessage(7, TALKTYPE_CHANNEL_R1, prefixes[groupId] .. " " .. message)
    return false
end
change channel id (7 in here) to whatever
 
thanks again, but another error:

:( My mistake:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[God] " + author;
        } else if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[Tutor] " + author;
        }

        client->sendChannelMessage(author, text, type, channel);
    }
}
 
:( My mistake:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[God] " + author;
        } else if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            author = "[Tutor] " + author;
        }

        client->sendChannelMessage(author, text, type, channel);
    }
}

thanks, again :p got another error look please:
wHUXxBH.png
 
I tried adding the script that said, when we talk it appears two msg, one on top of the other.
I tried to modify a constant value, lol, I'm newbie sorry:

Just try this:
C++:
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel) {
    if (client) {
        if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            const std::string& newAuthor = "[God] " + author;
            client->sendChannelMessage(newAuthor, text, type, channel);
        } else if (this->getAccountType() == ACCOUNT_TYPE_GOD) {
            const std::string& newAuthor = "[Tutor] " + author;
            client->sendChannelMessage(newAuthor, text, type, channel);
        } else {
            client->sendChannelMessage(author, text, type, channel);
        }
    }
}
 
Back
Top