• 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 0.X Information when staff login.

OTcreator

Active Member
Joined
Feb 14, 2022
Messages
425
Solutions
1
Reaction score
44
Hello!
I need script, when staff login to game on broadcast for TFS 1.4.2.
Someone like this:

Lua:
local groups =
{
    [2] = "Tutor",
    [3] = "Senior Tutor",
    [4] = "GM",
    [5] = "Community Manager",
    [6] = "God"
}

function onLogin(cid)
    if(groups[getPlayerGroupId(cid)] and isPlayerGhost(cid) ~= TRUE) then
        doBroadcastMessage(getCreatureName(cid) .. " has now logged in. Position: " .. getGroupInfo(groups[getPlayerGroupId(cid)]).name .. ")")
        return TRUE
    end
    return TRUE
end
 
Just look at "compat.lua" to see what needs to be changed from the old TFS 0x to the new TFS 1x. It's very easy and simple

Lua:
local groups = {
    [2] = "Tutor",
    [3] = "Senior Tutor",
    [4] = "GM",
    [5] = "Community Manager",
    [6] = "God"
}

function onLogin(cid)
    local player = Player(cid) 
    local playerGroupId = player:getGroup()
    
    if groups[playerGroupId] and not player:isInGhostMode() then
        local groupName = groups[playerGroupId]
        local playerName = player:getName()
        local playerGroupName = player:getGroup():getName()
        
        Game.broadcastMessage(playerName .. " has now logged in. Position: " .. playerGroupName .. ")", MESSAGE_STATUS_CONSOLE_RED)
        return true
    end
    return true
end
 
or this:
Lua:
function onLogin(player)
    if player:getGroup():getId() > 1 and not player:isInGhostMode() then
        for _, targetPlayer in ipairs(Game.getPlayers()) do
            targetPlayer:sendPrivateMessage(player, player:getName() .. " has now logged in. Position: " .. player:getGroup():getName() .. ")", TALKTYPE_BROADCAST)
        end
    end
    return true
end
 
Revscript

Lua:
local creatureEvent = CreatureEvent("Staff Login Message")

function creatureEvent.onLogin(player)
    if player:getGroup():getAccess() and not player:isInGhostMode() then
        Game.broadcastMessage(string.format("%s has now logged in. Role: %s", player:getName(), player:getGroup():getName()), MESSAGE_EVENT_ADVANCE)
    end
    return true
end

creatureEvent:register()
 
@Evil Puncker Can you tell me what is the difference between the two scripts?
The script was short and more practical, lol
the groupName variable was unused

the groups table could easily be changed to an player:getGroup():getId() check

cid -> player

Game.broadcastMessage
to the function we use in our default !broadcast talkaction because sometimes it doesn't work

two return trues weren't needed

playerName and playerGroupName variables not needed as we use them only once
 
the groupName variable was unused

the groups table could easily be changed to an player:getGroup():getId() check

cid -> player

Game.broadcastMessage
to the function we use in our default !broadcast talkaction because sometimes it doesn't work

two return trues weren't needed

playerName and playerGroupName variables not needed as we use them only once
I understand then.
Revscript

Lua:
local creatureEvent = CreatureEvent("Staff Login Message")

function creatureEvent.onLogin(player)
    if player:getGroup():getAccess() and not player:isInGhostMode() then
        Game.broadcastMessage(string.format("%s has now logged in. Role: %s", player:getName(), player:getGroup():getName()), MESSAGE_EVENT_ADVANCE)
    end
    return true
end

creatureEvent:register()
I like this revscript better
 
Back
Top