[B]How do I target someone in server console with [U]concommand.Add[/U]? [/B]
I'm sorry... What?
If I want to make a command in server console: "nadmin_setgroup", how would I make it so it targets someone.
Use the arguments of the function you pass to concommand.Add and search a player according to what the arguments are.
Say you get a nickname for a player, just run with a loop in player.GetAll() and compare the v:Nick() to your argument. If its equal then you can assume you found the player and you may perform anything on v (the player, assuming in the loop you called it v)
[QUOTE=VortexZ;47404886]If I want to make a command in server console: "nadmin_setgroup", how would I make it so it targets someone.[/QUOTE]
[code]
concommand.Add("test_target_person", function( ply, cmd, args )
local Target = NULL
for k,v in pairs( player.GetAll() ) do
if( string.find( string.lower( v:GetName() ), string.lower( args[1] ) ) != nil ) then
Target = v
break
end
end
if( IsValid( Target ) ) then
Target:Say("Run the command test_target_person <name> in console to make <name> say this message!")
else
print("Couldn't find target with partial name:", args[1] )
end
end )
[/code]
or something like that
Pass the player as an argument
How do I make it runnable only from server console. Because everytime I type the command in normal console I get error:
[lua]
[ERROR] addons/nadmin/lua/autorun/cmds.lua:29: attempt to call method 'SetUserGroup' (a nil value)
1. unknown - addons/nadmin/lua/autorun/cmds.lua:29
2. unknown - lua/includes/modules/concommand.lua:54
[/lua]
[lua]
if IsValid( ply ) then return end
[/lua]
Thanks :)
Sorry, you need to Log In to post a reply to this thread.