I'm trying to have the server auto-run a command on newly joined players and then echo that command to any online admins.
This is what the command is supposed to do:
https://files.facepunch.com/forum/upload/338276/fbc24509-7ba5-4a94-ae00-0995edcaf98a/image.png
This is what I have so far, but it doesn't work, and even if it did, it won't echo to any online admins (The command I am trying to run is admin rank or higher to use)
function GM:PlayerInitialSpawn(ply)
for k, v in pairs(player.GetAll()) do
RunConsoleCommand("ulx gct "..v)
end
end
I'm completely unsure of how to go about this, and anything helps.
Thanks!
RunConsoleCommand("ulx gct "..v:SteamID())
ulx gct stands for "ulx getcommandtable", its the command I'm trying to get to autorun and send to admins.
hook.Add("PlayerInitialSpawn", "OnSpawnCheck", function(ply)
timer.Simple(60, function ()
for k,v in ipairs(player.GetAll()) do
if v:IsAdmin() == true then continue end
v:ConCommand("ulx gct " .. ply:Nick())
end
end)
end)
This is what I've made out of your code as I only want it to run on users. And the issue is that I need it to autorun on users, but with the code above I get this issue for non-admins:
You don't have access to this command, Zero!
No
-- A new player (ply) has had his inital spawn
hook.Add("PlayerInitialSpawn", "ulxGctSpawn", function(ply)
-- We begin looping through all players
for k,v in ipairs(player.GetAll()) do
-- We only wish to target admins as the command require admin powers
if v:IsAdmin() == false then continue end
-- We have found an admin and we ask the admin to execute the following
-- ulx gct [[steamid of the new player]]
v:ConCommand("ulx gct " .. ply:SteamID())
end
end)
The ulx gct command is targeted at the newly joined player, the command requires admin privileges which is why we do a for loop to only look for admins and then ask the admin to execute the ulx gct command with the newly spawned player as the target.
Oh I see now, it seems to be working, but when I add a simple timer on it for 60 seconds, it still runs instantly, can you help me with that?
and ply:SteamID makes ulx say that there was no target found or target has immunity, so I switched it to ply:Nick()
Also, say there are 4 admins on, will this command run for all 4 admins at the same time?
commands = {
"somecommand1",
"somecommand2",
"etc..",
}
hook.Add("Initialize","PlayerIntialize",function(ply)
for k,v in pairs(commands) do
ply:ConCommand(v)
end)
if im not mistaking when the player joins this should autorun all of the commands in the table
You edited out the continue on the admin check, that's why you're receiving the error. You don't need to have non admins run the ulx gct command.
hook.Add("PlayerInitialSpawn", "ulxGctSpawn", function(ply)
timer.Simple(60, function()
if ply:IsValid() == false then return end
for k,v in ipairs(player.GetAll()) do
if v:IsAdmin() == false then continue end
v:ConCommand("ulx gct " .. v:Nick())
-- You could also call the function directly
-- https://bit.ly/2QgqS1I
-- ulx.getcommandtable(v, ply)
end
end)
end)
Working perfect now, thanks a lot dubb.
Sorry, you need to Log In to post a reply to this thread.