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!.
[CODE]
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 )
[/CODE]
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
[QUOTE=EmilGran;48270886]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!.
[CODE]
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 )
[/CODE][/QUOTE]
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
[QUOTE=EmilGran;48271002]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[/QUOTE]
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!:
[CODE]
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 )
[/CODE]
[editline]23rd July 2015[/editline]
Actually i updated my code and it is:
[CODE]
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 )
[/CODE]
[editline]23rd July 2015[/editline]
Do you think you can help me JamesxX?
[QUOTE=EmilGran;48271029]This is my code now!:
[CODE]
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 )
[/CODE]
[editline]23rd July 2015[/editline]
Actually i updated my code and it is:
[CODE]
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 )
[/CODE]
[editline]23rd July 2015[/editline]
Do you think you can help me JamesxX?[/QUOTE]
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 [URL="http://www.lua.org/pil/"]PIL[/URL] 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
[QUOTE=EmilGran;48271145]You mean the book? Wich book?
Btw. Thanks for the code!
Is there any gmod thing in that book?
-Emil[/QUOTE]
Maybe the [URL="http://www.lua.org/pil/contents.html"]online version[/URL]? And for gmod related stuff, use the [URL="wiki.garrysmod.com"]gmod wiki[/URL], however you should get to grips with the syntax before you go further.
[QUOTE=EmilGran;48270886]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!.
[CODE]
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 )
[/CODE][/QUOTE]
You wrote [code]if ply:isAdmin() then[/code]
It's actually [code]if ply:IsAdmin() then[/code]
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
Sorry, you need to Log In to post a reply to this thread.