How to make a command

Hey how do i make a command so when i type the command in console, lets say the command is “123”. Ok, so when i type 123 in console it executes that command and does this

[lua]hook.Add( “PlayerLoadout”, “Assault kit”, function( ply )

if ply:SteamID() == "STEAM_0:1:156583373" then -- This line

   ply:Give( "m9k_m416" )

end

end )[/lua]

I want it to add a steamid to that line, So when i type 123 add STEAM_0:example in console it adds “or “STEAM_0:example”” to the line so the code would be this:

[lua]hook.Add( “PlayerLoadout”, “Assault kit”, function( ply )

if ply:SteamID() == "STEAM_0:1:156583373" or "STEAM_0:example" then -- This line

   ply:Give( "m9k_m416" )

end

end )[/lua]

Would this work?

[lua]kit_name = Assault Kit

hook.Add( “PlayerLoadout”, “{kit_name}”, function( ply )

if ply:SteamID() == "STEAM_0:1:156583373" or "STEAM_0:example" then -- This line

   ply:Give( "m9k_m416" )

end

end )

if function(command) = command:( “kit add {kit_name} {STEAMID}” ) executed then
add ( or “{STEAMID}” ) to line 2 before ( “then” )[/lua]

You can’t add a line to your code. Your best bet here for simplicity is to:

  • On ConCommand, write the Steam ID in args[1] to a file using file.Write, making sure to seperate the Steam ID with a symbol such as ‘;’ so you can split them up later.
  • On Hook, file.Read the file and explode the given string at the symbol using string.Explode.
  • Loop through the exploded string, executing the give command on each entry, obviously converting the Steam ID to a player object using player.GetBySteamID.

file.Write

file.Read

string.Explode

player.GetBySteamID



function SlayerLegendz(ply)
    if ply:SteamID() == "STEAM_0:1:156583373" then
	ply:Give( "m9k_m416" )
    end
end
concommand.Add("123", SlayerLegendz)


This doesn’t have anything for ADDING steam id’s

At least it demonstrates how to use concommand.Add.

Still need the code… Anyone give me atleast a link to figure this out?

Semajnad gave a very good approach and the relevant resources to read about the functions required.

There are plenty of links that have already been given to you in this thread that will tell you how to do this. Look at those links, you may have to do trial and error to figure this out. Bottom line is that no one here is going to spoon feed you the code you are going to have to work this out for yourself. Enough people have already pointed you in the right direction.

No one is going to make this for you. It’s simple, actually study the links given or deal with not having the command. It’s just as simple as that.

an easy option would be making the kits into ulx commands, and then allowing steamids the permission for the command