• 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.3] Broadcast a welcome message when a new account logs in for the first time

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
7,030
Solutions
256
Reaction score
2,115
Location
Norway
GitHub
Znote
File install path: data/scripts/welcome.lua

When a player logs in for the first time (on an account), broadcast a message to every player online, welcoming them to the server.
This gives existing players a chance to welcome and help them get started on the server.

I believe persistent account/global storage was recently fixed on otland/forgottenserver, but this script was created before then, so I used an additional SQL table to keep track of account firstlogin status.

This does not broadcast a new welcome message if the same account creates and logins with a second character. Only the first account login.
You can see this script in action/demo at: AcidsOT.

Lua:
local welcomeplayer = CreatureEvent("welcomeplayer")

-- Auto install tables if we dont got them yet (first install)
db.query([[
    CREATE TABLE IF NOT EXISTS `znote_global_storage` (
      `key` varchar(32) NOT NULL,
      `value` TEXT NOT NULL,
      UNIQUE (`key`)
    ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
]])

-- Determine if this is first time player logs in
local function isFirstLogin(player)
    local resultId = db.storeQuery("SELECT `value` FROM `znote_global_storage` WHERE `key`='1stLog_"..player:getAccountId().."' LIMIT 1;")
    if resultId ~= false then
        local time = result.getDataInt(resultId, "value")
        result.free(resultId)
        return false
    end
    return true
end

-- Broadcast a welcome MESSAGE_EVENT_ADVANCE message to every player online welcoming the new player
function welcomeplayer.onLogin(player)
    if isFirstLogin(player) then
        print("\nWelcome to our newest member ["..player:getName().."]!\n")
        db.query("INSERT INTO `znote_global_storage` (`key`,`value`) VALUES ('1stLog_"..player:getAccountId().."', '"..os.time().."');")
        local players = Game.getPlayers()
        local playerName = player:getName()
        for _, onlineplayer in ipairs(players) do
            onlineplayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Welcome to our newest member ["..playerName.."]!\nFeel free to use help channel for questions.")
        end
    end
    return true
end

welcomeplayer:register()
 
Last edited:
Back
Top