We’ve currently implemented the following code to attempt to print this to console, but it doesn’t seem to work.
function SpawnedProp(ply, model, ent)
for _,play in pairs(player.GetAll()) do
if play:IsAdmin() then
print(ply:Name() .. "(" .. ply:SteamID() .. ") has spawned " .. model )
end
end
end
hook.Add("PlayerSpawnedProp", "playerSpawnedProp", SpawnedProp)
Your code refers to ‘ply’ (a nil value). You used ply where you should have used play. Although I recommend changing your play references to ply since ply is a more common name for player variables.
Here’s your code fixed:
[lua]
function SpawnedProp(ply, model, ent)
for _,ply in pairs(player.GetAll()) do
if ply:IsAdmin() then
print(ply:Name() … “(” … ply:SteamID() … ") has spawned " … model )
end
end
end
Hmm, this still doesn’t seem to want to print to the console. It doesn’t print anything, actually. When I’m trying to get it to print everything any user spawns.
I think this line,
if ply:IsAdmin() then
Could possibly be the issue, is that saying that it only shows admins prop’s being spawned?
[lua]
local function SpawnedProp(ply, model, ent)
for _, v in pairs(player.GetAll()) do
if v:IsAdmin() then
v:ChatPrint(ply:Name() … “(” … ply:SteamID() … ") has spawned " … model )
end
end
end
What the OP had was mostly right, but he won’t see it anywhere except either the dedicated server’s console or his own one if it’s a listen server. What I did was changed the print function to player:ChatPrint() so that all admins would see it. I also made the unique string for that hook less likely to cause compatibility problems, and also localised the function because it has quite a generic name.
I can look to find if there’s a way to send only to admins though.
Edit:
Player:PrintMessage(HUD_PRINTCONSOLE,Message)
So loop through players. If they’re an admin, run this on them. Note only Player and Message require changing. Keep HUD_PRINTCONSOLE.
local function SpawnedProp(ply, model, ent)
local Players = player.GetAll()
for _,Ply in pairs(Players) do
if (Ply:IsAdmin()) then
Ply:PrintMessage(HUD_PRINTCONSOLE,"Player "..Ply:Nick() .."("..Ply:SteamID()..") has spawned "..model)
end
end
end
hook.Add("PlayerSpawnedProp", "playerSpawnedProp", SpawnedProp)