I wanted to create a simple steam ID teller, that prints the Steam ID of a name i typed in chat.. Fx
[lua]
function() IDPrint
//The name i want here Get.SteamID()
Chat.print("The Steam ID Is ="..SteamID())
[/lua]
How do I make so the Lua takes the name I want of a player(By typing it on keyboard to chat fx. !SteamID Bob).
I really can't seem to find anything like this anywhere, so I'm asking and looking forward to a quick reply :) Thanks!
I haven't tested this code, but it should be a good example of what your looking for :
[lua]
function idlookup( ply, text, team )
if (string.sub(string.lower(text), 1, 9) == "!steamid " then
for k , v in pairs(player.GetAll()) do
if string.lower(v:Nick()) == string.sub(string.lower(text), 10) then
ply:SendLua("chat.AddText(Color(200,200,255),"..tostring( v:SteamID())..")")
end
end
end
end
hook.Add( "PlayerSay", "idlookup", idlookup );
[/lua]
Just a quick example, could use a bit of optimization.
[lua]function idlookup( ply, text, team )
if (string.sub(string.lower(text), 1, 9) == "!steamid " then
for k , v in pairs(player.GetAll()) do
if string.lower(v:Nick()) == string.sub(string.lower(text), 10) then
ply:SendLua("chat.AddText(Color(200,200,255),\""..tostring( v:SteamID()).."\")")
end
end
end
end
hook.Add( "PlayerSay", "idlookup", idlookup );[/lua]
You forgot to add \" either side of the steamid.
Wow thanks guys! This looks good, I will give it a go. Thanks :)
Ok I have changed around a bit, now I just want to know how to make the lua file print something in console when it sees a chat command like "#SteamID"
Seeing as you've already pretty much got the code to do that, I'll just point you in the right direction:
[b][url=http://wiki.garrysmod.com/?title=Player.PrintMessage]Player.PrintMessage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] with HUD_PRINTCONSOLE
[lua]
local function GetPlayerObject( partial )
local str = tostring( string.Trim( string.lower( partial ) ) );
local pTab = player.GetAll();
for i = 1, #pTab do
local ply = pTab[i];
if( string.find(ply:Name(), str) ) then
return ply;
end
end
return nil;
end
local function SteamIDLookup(p, text, te)
local Offset = "!SteamID";
local ChatArray = string.Explode(" ", text);
if( ChatArray[1] == Offset ) then
local pOb = GetPlayerObject( ChatArray[2] );
if( pOb ) then
p:SendLua("chat.AddText(Color(0, 0, 0), '[ID Lookup]', Color(0, 255, 0), 'Player '..pOb:Name()..'s SteamID is '..tostring( pOb:SteamID() ) );
else
p:SendLua("chat.AddText(Color(0, 0, 0), '[ID Lookup]', Color(0, 255, 0), 'Player not found!');
end
return "";
end
end
hook.Add("PlayerSay", "SteamIDLookup", SteamIDLookup)
[/lua]
Untested, as you can see it is more a bit more complicated then the others, the other code given here will work fine I just gave you this so you can learn from it. Obviously their is more practical to use in small application.
Okey, this is beginning to get akward. Seems like no matter what I try it won't give me the SteamID at all, not in console nor in chat. I'm sure I'm typing it right! :/
Player: !SteamID Player
..Nothing :((
What are you typing in chat exactly?
!SteamID Name
Sorry, you need to Log In to post a reply to this thread.