Solved Chat prefixes

Discussion in 'Plugin Requests' started by Hirsty, Jan 23, 2015.

  1. Hey all - would love to see some sort of prefixes we can set to identify admins when on duty etc inc maybe VIP/custom set ones - as well as this if anyone is wanting to hook into a website with their plugin - willing to offer my services as a php dev to help with the other side of things :D
     
  2. Wulf

    Wulf Community Admin

  3. Not wanting chat name replaced wanting tag added such as [Owner] Hirsty
    [DOUBLEPOST=1422085905][/DOUBLEPOST]could probably make it myself but don't know lua :( tempted to go into plugin development though
     
  4. Wulf

    Wulf Community Admin

    I'll see what I can do.
     
  5. Yeah love the idea, I just started working on something similar for our ViPs on my server but can't quite get it working yet... (just too new to LUA and Rust plugins...)

    I wanted to create a plugin that changes the user name on join from original Name to Name ->ViP<- or something like that. With a config file that would contain all the SteamId's of the VIPs etc.
    The same for admins.

    Thanks,
    - TheDoc
    [DOUBLEPOST=1422375519,1422312341][/DOUBLEPOST]Ok so I got this working in a way.... but it only works with the actual player name, I want to use the SteamID but I can't figure out how to do that.

    function PLUGIN:OnPlayerConnected(player)
    if not player then return end
    if not player.connection then return end

    local steamID = rust.UserIDFromConnection(player.connection)
    print(" connected SteamID1 (" .. steamID .. ")") -- DOES NOT WORK

    local playerID = rust.UserIDFromPlayer( player ) -- DOES NOT WORK
    print(" connected SteamID2 (" .. playerID .. ")")

    if (playerID == 76561197983994692) then
    local userDispName = ( "[Admin]" .. player.connection.username )
    player.connection.username = userDispName
    print(" connected (" .. userDispName .. ")")
    end

    -- IF I do just this, it works...
    if(player.connection.username == "TheDoc") then
    local userDispName = ( player.connection.username .. " >ViP< ")
    player.connection.username = userDispName
    print(" connected (" .. userDispName .. ")")
    end

    end

    Please advise...

    Thanks!
    -TheDoc
     
  6. My original legacy Chat Handler plugin had an option to specify groups and set name prefixes for each group.
    If there would be some kind of permission system like the old flags plugin i could eventually port that feature to the experimental version of Chat Handler.
     
  7. I think when you put " " around a variable, it turns that variable name into a string. So you are essentially passing the word ".. steamID .." in instead of passing the variable (.. steamID ..). If this hasn't been answered by the time I get home from work, I'll see what I can figure out as I cant debug rust till then.
     
  8. I tested again and the following actually works:

    Code:
    local steamID = rust.UserIDFromConnection(player.connection)
      print(" connected SteamID1 (" .. steamID .. ")")
    I missed it before somehow.

    Testing now with that and will see how it works out... now I need to learn how to load SteamID's from a config file...
     
    Last edited by a moderator: Jan 27, 2015
  9. playerID needs to be player.connection.username

    -----------------------
    local steamID = rust.UserIDFromConnection(player.connection)
    print(" connected SteamID1 (" .. steamID .. ")")

    local playerID = player.connection.username
    print(" connected SteamID2 (" .. playerID .. ")")
    ------------------------

    My console output was:
    connected SteamID1 (steam id number)
    connected SteamID2 (Criticalmass)
    [DOUBLEPOST=1422392805][/DOUBLEPOST]PLUGIN.Title = "cm-Test"
    PLUGIN.Version = V(0, 0, 1)
    PLUGIN.Description = "Test"
    PLUGIN.Author = "Criticalmass"
    PLUGIN.Url = ""
    PLUGIN.HasConfig = false

    function PLUGIN:Init()
    end

    function PLUGIN:OnPlayerConnected(player)
    if not player then return end
    if not player.connection then return end

    local steamID = rust.UserIDFromConnection(player.connection)
    print(" connected SteamID1 (" .. steamID .. ")")

    local playerID = player.connection.username
    print(" connected SteamID2 (" .. steamID .. " : " .. playerID .. ")")
    end
    [DOUBLEPOST=1422393240][/DOUBLEPOST]Something to keep in mind is the actual Oxide hook is "OnPlayerConnected(Facepunch/Network.Message packet)". To me using (player) gives a false impression you are trying to use "Assembly-CSharp/BasePlayer player" rather than "Facepunch/Network.Message packet". I'm a total noob so maybe this is only confusing to me.
     
    Last edited by a moderator: Jan 27, 2015
  10. Dude, I be honest... I don't know what I'm doing here... just experimenting and stealing code from other plugins to make this one work.

    Ok so I got it working with the following:

    Code:
       local steamID = rust.UserIDFromConnection(player.connection)   if (steamID == "76561197283992692") then
         local userDispName = ( "[Admin]" .. player.connection.username )   
         player.connection.username = userDispName
         print(" connected (" .. userDispName .. ")")
       end
    
    But it does not work if I do it like this:

    Code:
      local steamID = rust.UserIDFromConnection(player.connection)  local thedocId = "76561197283924692"   if (steamID ==thedocId ) then
         local userDispName = ( "[Admin]" .. player.connection.username )   
         player.connection.username = userDispName
         print(" connected (" .. userDispName .. ")")
       end
    
    Why?

    Also it works with I type a chat message with the new prefix but ppl can't see it until I TP to them... any ideas how to force that to show up right away?

    Thanks,
    -TheDoc
     
  11. any developers care to take me under there wing :3 pretty sure shouldnt be too hard with myself having experience in jaca, C++, VB, Delphi and PHP as well as a few others then maybe i could help :3
     
  12. Join the irc channel http://oxidemod.org/threads/is-there-an-oxide-irc-channel.74/
     
  13. Cant atm im at work >.>
     
  14. Ok so I need some assistance from some Sr. Plugin Developers here please.

    Here my final function:

    Code:
    function PLUGIN:OnPlayerConnected(player)
        if not player then return end
        if not player.connection then return end    local steamID = rust.UserIDFromConnection(player.connection)
    --    local name = player.connection.username
       
    --    print(" connected SteamID (" .. steamID .. ")")
    --    print(" connected name (" .. name .. ")")-- Hate this IF but can't get anything else working yet    if (steamID ==     "9999999999999991"
            or steamID == "9999999999999992"
            or steamID == "9999999999999993"
            or steamID == "9999999999999994"
            or steamID == "9999999999999995"
            or steamID == "9999999999999996"
            or steamID == "9999999999999997"
            or steamID == "9999999999999998"
            or steamID == "9999999999999999"
            or steamID == "9999999999999990"
            or steamID == "9999999999999911"
            or steamID == "9999999999999912"
        ) then
            local userDispName = ( player.connection.username .. " ->ViP<-")
            player.connection.username = userDispName
            --print(" connected (" .. userDispName .. ")")
        end
       
    end
    1. I would like to move the ViP SteamID into a config file, but don't know how to do that quite yet.
    2. How do I load them into a table and then replace this crazy IF statement with a small function call that would iterate over the table and check if the ID connected exists in that list.
    3. Also it works with I type a chat message with the new prefix but ppl can't see it until I TP to them... any ideas how to force that to show up right away?
    4. I also wanted to do this for Admins on server (and I got it working the same crazy IF statement, but I'm unable to use the player.IsAdmin() call to validate the Admin ID... why?

    I also tried using this function for it, and it does not work either: (guessing the player object is not the same as I'm getting in my OnPlayerConnected(player) )

    Code:
    local function IsAdmin(player)
        return player:GetComponent("BaseNetworkable").net.connection.authLevel >= admin.Auth_LVL
    end
    
    Thanks guys!

    -TheDoc
     
  15. 1 - You can find examples for this in almost every plugin.
    2 - To iterate through a table and check for matches one possibility would be:
    Code:
    for key, value in pairs(table) do
        if table[key].steamID == steamID then
            -- do something
        end
    end
    Be aware that the line with the if statement depends on your table structure.
    3 - Maybe something to do with the global/local chat
    4 - This function isnt working for you because "player" in your OnPlayerConnected() hook isnt a BasePlayer type. The IsAdmin() function you posted requires a BasePlayer.
     
  16. Cool thx. Working on it now...

    4. How do I get BasePlayer?
    [DOUBLEPOST=1422568098,1422469274][/DOUBLEPOST]Ok so I got the config file thing working...

    function PLUGIN:LoadDefaultConfig()

    Code:
    function PLUGIN:LoadDefaultConfig()
        self.Config.Settings = self.Config.Settings or {}
        self.Config.Settings.VipTag = self.Config.Settings.VipTag or " ->ViP<-"
        self.Config.Settings.AdminTag = self.Config.Settings.AdminTag or "[Admin] "
        self.Config.Settings.AddVipTag = self.Config.Settings.AddVipTag or "true"
        self.Config.Settings.AddAdminTag = self.Config.Settings.AddAdminTag or "true"
        self.Config.Vips = self.Config.Vips or {
            "9999999999999991",
            "9999999999999992",
            "9999999999999993",
            "9999999999999994"
        }    self.Config.Admins = self.Config.Admins or {
            "1999999999999991",
            "1999999999999992",
            "1999999999999993",
            "1999999999999994"
        }
        self:SaveConfig()
    end
    
    And it creates the file as needed, but when I try using the variables in the code nothing works....
    What am I doing wrog???

    Here the IsAdmin() function (same function for VIPs)

    Code:
    local function IsAdmin(steamID)
        for _, value in pairs(self.Config.Admins) do
            print("*** Value = " .. value .. " SteamId= " .. steamID )
            if steamID == value then
                return true
            end
        end
    end
    
    And here an example how I'm calling it from the code...

    Code:
        if self.Config.Settings.AddAdminTag == "true" then
            if IsAdmin(steamID) then
            ) then
                local userDispName = ( self.Config.Settings.AdminTag .. packet.connection.username )
                packet.connection.username = userDispName
            end
        end
    
    Anyone got an answer for me?

    Thanks,
    -TheDoc
     
    Last edited by a moderator: May 17, 2015
  17. You cant use the self.Config variables in a local function.

    Maybe you should post your whole plugin code so we can see what you're doing and help you with ideas how to realise it.
    I could post you the code but you would learn more if we just give you some hints and you get to it yourself.
     
  18. Wulf

    Wulf Community Admin

    Well, you can if you pass self to it. ;)
     
  19. Sure, please teach me! Here you go...

    It's all working w/o using the config file and if you un-comment the if or statement and remove the of IsVip(steamId)

    -TheDoc
     

    Attached Files:

  20. Ok you got me on this. Anyways he cant because he didnt :p
    [DOUBLEPOST=1422619550][/DOUBLEPOST]
    Like Wulf said you need to pass the self variable to your local functions to use it there.
    For example: local function IsVIP(steamID, self) and call it like IsVIP(steamID, self)