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
Welcome Message and Notifications [Abandoned]
Discussion in 'Plugin Support' started by Taffy, Oct 16, 2014.
-
-
the update did it, now everything is okay.
-
excellent news, thanks for info
-
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" }
BoomshayLast edited by a moderator: Oct 29, 2014 -
Wulf Community Admin
-
-
shall take a look at it
-
Taffy updated Welcome Message and Notifications with a new update entry:
Update to the welcome message to provide multiple lines support
-
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
-
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 -
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 -
[Oxide] 11:51 AM [Error] usernotification: [string "usernotification.lua"]:77: attempt to index global 'usermsg' (a nil value)
-
[DOUBLEPOST=1414776429][/DOUBLEPOST]
-
Taffy updated Welcome Message and Notifications with a new update entry:
Bugfix
-
Hi,
Config : http://pastebin.com/SJPg18Z0
[Info] error in calculation, linecompare is greater than linecount : 3Last edited by a moderator: Oct 31, 2014 -
6:28 PM [Info] error in calculation, linecompare is greater than linecount : 2
-
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
Last edited by a moderator: Oct 31, 2014 -
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" }
-
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()
endAttached Files:
-