1. Code:
    [Oxide] 6:55 PM [Error] usernotification: [string "usernotification.lua"]:43: attempt to index field 'cmd' (a nil value)
      at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0
      at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in <filename unknown>:0
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
     
    Last edited by a moderator: Oct 29, 2014
  2. Well, this is a weird one. I am not seeing this at all on my server. Can you provide details on version of plugin and what other plugin you have installed. The 1.0.6 version should have resolved this now but if you are still having these errors perhaps some sort of conflict with another plugin.
     
  3. the update did it, now everything is okay.
     
  4. excellent news, thanks for info :)
     
  5. Code:
    {
      "AllUserMessageBye": "USERNAME has disconnected",
      "ShowConnected": true,
      "ChatName": "SERVER",
      "AllUserMessage": "USERNAME has connected",
      "ShowDisconnected": true,
      "UserMessage": "Hi USERNAME! Welcome to the RIP Max Loot server",
      "UserMessage": "Please have fun and be respectful!",
      "UserMessage": "Enjoy the many plugins we have such as Kits, TP, & More!",
      "UserMessage": "For all help information please do /help"
    }
    Is this wrong coding? it used to just have one UserMesage line, can i not just add some lol. Im a newb coder.

    Boomshay
     
    Last edited by a moderator: Oct 29, 2014
  6. Wulf

    Wulf Community Admin

    Merged with plugin's thread. In the future, please post plugin specific questions in their discussion area, and also use code tags when posting configs or errors.
     
  7. It's currently not possible to do that since the code does not support printing multiple messages, perhaps @Taffy could implement this feature :)
     
  8. shall take a look at it :)
     
  9. Taffy updated Welcome Message and Notifications with a new update entry:

    Update to the welcome message to provide multiple lines support

     
  10. hi,

    (old .json deleted)
    When a player joins the server:
    Code:
        12:42 PM [Error] usernotification: [string "usernotification.lua"]:78: attempt to index global 'usermsg' (a nil value)
          at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0
          at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in <filename unknown>:0
          at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
          at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
     
  11. Hi, Was not necessary to delete your old config

    Please can you post your config so I can see it?

    --edit--
    just deleted my config and works fine. Make sure that you have the following line1 in you config file.

    "UserMessages": {
    "Line1": "Hi USERNAME! Welcome to the server. type /help for commands"
    }
    If there is no line1 you would get the error you mentioned.
     
    Last edited by a moderator: Oct 31, 2014
  12. My .json

    http://pastebin.com/SJPg18Z0

    (I always removed (for safety) the old .json.)

    EDIT : solved => Adding lines in the lua plugin bug.

    Code:
                self.Config.UserMessages = self.Config.UserMessages or
                    {
                    Line1        =    "My Line 1",
                    Line2        =    "My Line 2"
                    }
     
    Last edited by a moderator: Oct 31, 2014
  13. [Oxide] 11:51 AM [Error] usernotification: [string "usernotification.lua"]:77: attempt to index global 'usermsg' (a nil value)
     
  14. Glad you solved it, not quiet sure what you are saying though :p[DOUBLEPOST=1414776429][/DOUBLEPOST]
    Can you paste a copy of your config please[DOUBLEPOST=1414792701,1414776393][/DOUBLEPOST]Noticed problem in code which would cause the error mentioned. Joys of counting and not resetting variables, will upload an updated version shortly.
     
  15. Taffy updated Welcome Message and Notifications with a new update entry:

    Bugfix

     
  16. Last edited by a moderator: Oct 31, 2014
  17. 6:28 PM [Info] error in calculation, linecompare is greater than linecount : 2
     
  18. Fuck me! OK, back to the drawing board.

    Can you try add the following?

    Code:
    function PLUGIN:OnRunCommand( arg , ply , cmd )
        -- Sanity checks
        if (not arg) then return end
        if (not arg.connection) then return end
        if (not arg.connection.player) then return end
        if (not arg.cmd) then return end
        if (not arg.cmd.name) then return end
        local ply = arg.connection.player
        DName = ply.displayName
        if (arg.cmd.name == "wakeup") then -- user has pressed the wake up button
            --print ("wakeup button pressed")  
            if self.DisplayedWelcome[DName] == nil then
                if LineCompare > LineCount then
                    print ("error in calculation, linecompare is greater than linecount : " .. LineCompare)
                else
                    while LineCompare <= LineCount do
                        LineNo="Line" ..(LineCompare)
                        usermsg = (self.Config.UserMessages[LineNo])
                        usermsg = usermsg:gsub("USERNAME",DName)
                        ply:ChatMessage(usermsg)  -- sends the message to the connecting player
                        self.DisplayedWelcome[DName] = DName
                        LineCompare = LineCompare + 1
                    end
                end
            end
            LineCompare = 1
        end
    end
    The bottom LineCompare = 1 to the OnRunCommand
     
    Last edited by a moderator: Oct 31, 2014
  19. Taffy, why don't you write a ShowMessage(player, message) function where the message can be either a string or a table, and when it's a table it automatically sends all values from that table? Would spare you some headaches with resetting values and that way the message could just be saved as:
    Code:
    MultipleLineMessage = { "line1 content","line2 content" }
     
  20. Maybe i've found a solution. I've rewritten the lua file a little bit.

    Changes marked in red (REMOVED) and green (ADDED):
    PLUGIN.Name = "usernotification"
    PLUGIN.Title = "User Connection Notification"
    PLUGIN.Version = V(1, 0, 8)
    PLUGIN.Description = "Welcome message"
    PLUGIN.Author = "Taffy"
    PLUGIN.HasConfig = true
    PLUGIN.ResourceId = 652

    function PLUGIN:Init()
    --self:LoadData()
    self.DisplayedWelcome = {}
    self:LoadDefaultConfig()
    -- work out how many Lines exist for the welcome message --self.Config.UserMessages
    LineCount = 0
    --LineCompare = 1 -- REMOVED
    for k , v in pairs(self.Config.UserMessages) do
    LineCount = LineCount + 1
    end
    end

    function PLUGIN:LoadDefaultConfig()
    self.Config.ChatName="SERVER"
    self.Config.UserMessages = self.Config.UserMessages or
    {
    Line1 = "Hi USERNAME! Welcome to the server"
    }
    self.Config.AllUserMessage="USERNAME has connected"
    self.Config.AllUserMessageBye="USERNAME has disconnected"
    self.Config.ShowConnected=true
    self.Config.ShowDisconnected=true
    --amendments for multiple line support. Below will only process if old config entry identified and then rectify the entries to follow new format
    if (self.Config.UserMessage) then
    --Single line entry found. Grab it and add to new multiple line format
    self.Config.UserMessages =
    {
    Line1 = self.Config.UserMessage
    }
    --now remove the old entry
    self.Config.UserMessage = nil
    -- Save and reload the configuration
    self:SaveConfig()
    end
    end

    function PLUGIN:OnPlayerInit( ply )
    if(self.Config.ShowConnected) then
    DName = ( ply.displayName ) -- ADDED
    --tmpuser= ( ply.displayName ) -- REMOVED
    self.DisplayedWelcome[DName] = {} -- ADDED
    self.DisplayedWelcome[DName].DName = DName -- ADDED
    self.DisplayedWelcome[DName].LineCompare = 1 -- ADDED

    --print ("player connected, sending global message")
    --Send message to all connected users
    allusermsg = (self.Config.AllUserMessage)
    allusermsg = allusermsg:gsub("USERNAME",DName)
    global.ConsoleSystem.Broadcast("chat.add \"" .. self.Config.ChatName .. "\" \"" .. allusermsg .. "\"")
    end
    end

    ---testing for when player clicks wake up

    function PLUGIN:OnRunCommand( arg , ply , cmd )
    -- Sanity checks
    if (not arg) then return end
    if (not arg.connection) then return end
    if (not arg.connection.player) then return end
    if (not arg.cmd) then return end
    if (not arg.cmd.name) then return end
    local ply = arg.connection.player
    DName = ( ply.displayName )
    if (arg.cmd.name == "wakeup") then -- user has pressed the wake up button
    --print ("wakeup button pressed")
    if self.DisplayedWelcome[DName].DName ~= nil then
    --if LineCompare > LineCount then -- REMOVED
    if self.DisplayedWelcome[DName].LineCompare > LineCount then -- ADDED
    --print ("error in calculation, linecompare is greater than linecount : " .. LineCompare) -- REMOVED
    print ("error in calculation, linecompare is greater than linecount : " .. self.DisplayedWelcome[DName].LineCompare) -- ADDED
    else
    --while LineCompare <= LineCount do -- REMOVED
    while self.DisplayedWelcome[DName].LineCompare <= LineCount do -- ADDED
    --LineNo="Line" ..(LineCompare) -- REMOVED
    LineNo="Line" ..(self.DisplayedWelcome[DName].LineCompare) -- ADDED
    usermsg = (self.Config.UserMessages[LineNo])
    usermsg = usermsg:gsub("USERNAME",DName)
    --ply:ChatMessage(usermsg) -- sends the message to the connecting player -- REMOVED
    ply:SendConsoleCommand("chat.add \""..self.Config.ChatName.."\" \""..usermsg.."\"") -- sends the message to the connecting player -- ADDED
    --self.DisplayedWelcome[DName] = DName -- REMOVED
    --LineCompare = LineCompare + 1 -- REMOVED
    self.DisplayedWelcome[DName].LineCompare = self.DisplayedWelcome[DName].LineCompare + 1 -- ADDED
    end
    end
    end
    end
    end


    function PLUGIN:OnPlayerDisconnected(ply,connection)
    if (ply.displayName and self.Config.ShowDisconnected) then
    --tmpuser = ( ply.displayName ) -- REMOVED
    DName = ( ply.displayName ) -- ADDED
    allusermsg = (self.Config.AllUserMessageBye)
    --allusermsg = allusermsg:gsub("USERNAME",tmpuser) -- REMOVED
    allusermsg = allusermsg:gsub("USERNAME",DName) -- ADDED
    global.ConsoleSystem.Broadcast("chat.add \"" .. self.Config.ChatName .. "\" \"" .. allusermsg .. "\"")
    else return
    end
    --if (self.DisplayedWelcome[tmpuser] ~= nil) then -- REMOVED
    -- self.DisplayedWelcome[tmpuser] = nil -- REMOVED
    --end -- REMOVED
    --LineCompare = 1 -- REMOVED

    end

    function PLUGIN:LoadData()

    end

    function PLUGIN:SaveData()

    end
     

    Attached Files: