[HELP]Command help?

Hello Facepunch Members.

I have tried to make a command, if the player is dead then a admin can do !sp so he will spawn! please help me dosen’t work!.



hook.Add( "PlayerSay", "testcommand", function( ply, text, public )
        text = string.lower( text )
        if ( text == "!sp" ) then
            if ply:isAdmin() then
                    ply:Kill()
                    return ""
        end
end )


Do you get any errors? Are you using ULX?

Yes im using ulx and yes im getting an error, but i think i need some more code
do you think you can make a code for me?
Thanks for reply!

-Emil

You’re missing an end.

[lua]
hook.Add( “PlayerSay”, “testcommand”, function( ply, text, public )
text = string.lower( text )
if ( text == “!sp” ) then
if ply:isAdmin() then
ply:Kill()
return “”
end
end
end )
[/lua]

But this code kills the person who runs the chat command if he is an admin, not spawn someone.

James xX i dont think you understand what i want it to do!.

If the player is dead, you know got the red screen, then if the player is afk, i can do !sp then he will spawn!
Thanks for reply!.

-Emil

I do get what you want, which is why I told you the code you provided kills the person running the chat command, not spawn a player.

This is my code now!:



hook.Add( "PlayerSay", "testcommand", function( ply, text, public )
        text = string.lower( text )
        if ( text == "!kill" ) then
			if GM:PlayerDeath() then
                ply:Kill()
				ply:Alive()
                return ""
        end
end )



[editline]23rd July 2015[/editline]

Actually i updated my code and it is:



hook.Add( "PlayerSay", "testcommand", function( ply, text, public )
        text = string.lower( text )
        if ( text == "!sp" ) then
			if GM:PlayerDeath() then
				function GM:PlayerSpawn(ply)
					MsgN(ply:Nick() .."has been force spawned!")
                return ""
        end
end )


[editline]23rd July 2015[/editline]

Do you think you can help me JamesxX?

You probably want something like this:

[lua]
function FindPlayer(info)
local pls = player.GetAll()

-- Find by Index Number (status in console)
for k, v in pairs(pls) do
	if tonumber(info) == v:UserID() then
		return v
	end
end

-- Find by RP Name
for k, v in pairs(pls) do
	if string.find(string.lower(v:GetNWString("rpname")), string.lower(tostring(info))) ~= nil then
		return v
	end
end

-- Find by Partial Nick
for k, v in pairs(pls) do
	if string.find(string.lower(v:Name()), string.lower(tostring(info))) ~= nil then
		return v
	end
end
return nil

end

hook.Add( “PlayerSay”, “testcommand”, function( ply, text, public )
if ( string.lower( string.sub( text, 0, 2 ) ) == “!sp” and ply:IsAdmin() ) then
local target = FindPlayer( string.sub( text, 4 ) )
if ( target ) then
target:Spawn( )
end
end
end )
[/lua]

Note that the code is untested, I provided it so you can learn the syntax and the method. You should read up on the PIL because you seem to lack some understanding in lua syntax.

You mean the book? Wich book?
Btw. Thanks for the code!
Is there any gmod thing in that book?

-Emil

Maybe the online version? And for gmod related stuff, use the gmod wiki, however you should get to grips with the syntax before you go further.

You wrote


if ply:isAdmin() then

It’s actually


if ply:IsAdmin() then

Do you see the error?

I’d recommend doing this command through ULX if you’re using ULX. It is unbelievably easier and doesn’t require an extra manual function on the playersay hook