Dev Playerinfo Addon

Discussion in 'Hobbies' started by Wilks, Apr 25, 2018.

  1. Wilks

    Wilks New Member

    Hey guys, I don't know if this is a shitpost or not but I was wondering if I could get some input from you.

    I've made a simple addon that displays some server adverts like a welcome message on first time connecting and player info on disconnect. It does this by checking a database file (sv.db) whether or not the player has ever joined before and then displays a message if it their first time on the server.

    I want to add some more features to this addon because it is pretty plain right now. Any ideas on some cool things I could add?

    Code:
    --[[----- Simple Join & Disconnect Messaged by Wilks -----]]--
    
    --Clientside Code
    
    net.Receive("JoinInfo", function()
        local PlayerName = net.ReadString()
        local firstTimeJoining = net.ReadBool()
        local color_broadcast = Color(178, 34, 34, 255)
    
        --first time joining message
        if firstTimeJoining == true then
            chat.AddText(color_broadcast, "[server_name] ", color_white, "Welcome to server_name ", PlayerName, "!")
        end
    end)
    
    net.Receive("DisconnectInfo", function()
        local DisconnectedPlayerName = net.ReadString()
        local DisconnectedPlayerID = net.ReadString()
    
        --disconnected player message (for admins)
        chat.AddText(color_broadcast, "[BG TTT] ", color_white, DisconnectedPlayerName, " (", DisconnectedPlayerID, ")", " has disconnected!" )
    end)
    
    --Serverside Code
    
    local Player = FindMetaTable("Player")
    util.AddNetworkString("JoinInfo")
    util.AddNetworkString("DisconnectInfo")
    
    function Player:ConnectData()
        local ID = self:SteamID()
        local name = self:Nick()
        local firstTimeJoining = false
    
        --checks if player has joined server before using sv.db database
        if self:GetPData("player_ReturningPlayer", 0) == 0 then
            firstTimeJoining = true
            self:SetPData("player_ReturningPlayer", 1)
            print("Player ", name, " for the first time!")
        else
            firstTimeJoining = false
            print("Player ", name, " has joined before.")
        end
    
        --sends join info to client
        net.Start("JoinInfo")
            net.WriteString(name)
            net.WriteBool(firstTimeJoining)
        net.Broadcast()
    
    end
    hook.Add("PlayerInitialSpawn", "SendPlayerConnectInfo", Player.ConnectData)
    
    function Player:DisconnectData()
        local DisconnectID = self:SteamID()
        local DisconnectName = self:Nick()
    
        --sends disconnect info to client
        net.Start("DisconnectInfo")
            net.WriteString(DisconnectName)
            net.WriteString(DisconnectID)
        net.Broadcast()
    end
    hook.Add("PlayerDisconnected", "SendPlayerDisconnectInfo", Player.DisconnectData)
     
    • Like Like x 2