Ulysses
General => Developers Corner => Topic started by: AKTS on February 11, 2015, 03:01:40 PM
-
I'm editing a damagelog system to add all types of new logs. Everything I've added so far has been pretty simple: take the hooks for the event and make it append the logs with the relevant information when the event is executed. I've kind of run into a wall when I try to make something run when a console command is executed. I can't find any relevant hooks, so I tried to do something like this:
// I didn't append anything just so I could get this to run and properly notify.
function allcp(msg)
for i, v in pairs(player.GetAll()) do
v:ChatPrint(msg)
end
end
local crun = concommand.Run
function concommand.Run(ply, cmd, args)
if !IsValid(ply) then return crun(ply,cmd,args) end
if !cmd then return crun(ply,cmd,args) end
if args and args ~= "" then
allcp(ply:Name() .. " has executed this command: " .. cmd .. " " .. tostring(args) .. ".")
else
allcp(ply:Name() .. " has executed this command: " .. cmd .. ".")
end
return crun(ply, cmd, args)
end
This just doesn't work in general. To see where it breaks, I took out the returns and figured out the problem. Apparently ply is not valid, so it simply returns (I got an error that the method "Name" was a nil value). Oddly enough, this does notify if the command is not run from the console, but by a script running the command. For example, this appears in my chat automatically:
AKTS has executed this command: fas2_handrig_applynow
Does anyone have any suggestions as to how to go about doing this? I'm at an impasse at the moment.
-
–Snip–
-
ply:Nick(), not ply:Name().
That's probably the script breaker right there.
First off, thanks for responding!
I've used :Name() as opposed to :Nick() for a while now, and it seems to work everywhere else from ULX commands to other logs within the system I use. Also the documentation
(http://wiki.garrysmod.com/page/Player/Name) for GMOD says that ply:Nick(), ply:Name(), and ply:GetName() are all identical, so I never bothered to change my habit. Changing it from "Name" to "Nick" did not seem to resolve the problem.
-
In shared code, of course, Console can never be a player.
ULX uses static string "Console" for logging when ply !IsValid for commands run in shared space from server console.
Unless the actual addon/code is passing what player accessed the command through the consolecommand, I really don't think there's a way to show who ran the code that the serverside script then ran from console.
I could be wrong.
-
In shared code, of course, Console can never be a player.
ULX uses static string "Console" for logging when ply !IsValid for commands run in shared space from server console.
Unless the actual addon/code is passing what player accessed the command through the consolecommand, I really don't think there's a way to show who ran the code that the serverside script then ran from console.
I could be wrong.
Darn, that's a shame. I suppose it's the least-needed log though, so there's really no harm in not having it. I've seen it done elsewhere, but I'm going to not bother with it any more if it's going to take this amount of time.
EDIT: Oops no cursies.
-
ply:Nick(), not ply:Name().
That's probably the script breaker right there.
Not to be rude, you're wrong though. Player:Name() (http://wiki.garrysmod.com/page/Player/Name), Player:Nick() (http://wiki.garrysmod.com/page/Player/Nick), and with exceptions to Player:GetName() (http://wiki.garrysmod.com/page/Player/GetName) are all the same thing. It's just mainstream to use :Nick, instead of :Name, and :GetName is more strictly use for entities; which is sometimes also known as a player.
-
Not to be rude, you're wrong though. Player:Name() (http://wiki.garrysmod.com/page/Player/Name), Player:Nick() (http://wiki.garrysmod.com/page/Player/Nick), and with exceptions to Player:GetName() (http://wiki.garrysmod.com/page/Player/GetName) are all the same thing. It's just mainstream to use :Nick, instead of :Name, and :GetName is more strictly use for entities; which is sometimes also known as a player.
Was informed about that prior. Apologies—I'd been so used to Nick(). Note to self: don't help after coming home exhausted from high school.
-
Was informed about that prior. Apologies—I'd been so used to Nick(). Note to self: don't help after coming home exhausted from high school.
Ahhh. High School, how I miss those days :( College is not as fun.