• Very simple lua question here (Please make fun of me)
    3 replies, posted
Alright, so I started trying to teach myself lua the other night with The Garry's Mod Wiki , and everything was going well, but tonight I attempted to create an addon that when you type in a command, for this example, !SteamID , it will print your steamID in the console. Anyways, heres the code: [lua] function getSteamID ( ply, text, public, UserID ) if ( string.sub(text, 1, 8) == "!SteamID" ) then print( ply:SteamID().." is your SteamID!" ) end end hook.Add( "print", "getSteamID", getSteamID ) [/lua] Thanks in advance!
You're trying to use a hook which doesn't even exist, for a chat command you want to use the hook PlayerSay. Here's a list of hooks that exist in Garry's Mod. [url]http://wiki.garrysmod.com/page/Category:GM_Hooks[/url]
An example of how you could do this: [code] function GetSteamID(ply, text, public) newtext = string.lower(text) -- removes case sensitive shit; so a player can type !steamID and it will still work if ( string.sub(newtext, 1, 8) == "!steamid" ) then ply:ChatPrint("Your SteamID is: " ..ply:SteamID()) return "" -- removes the !steamid from chat if you want it otherwise just remove this line end end hook.Add("PlayerSay", "GetSteamID", GetSteamID) --1st = Actual Hook, 2nd = "Nickname for this hook", 3rd = The function this hook will use [/code]
Well, that would explain it. Thanks for the reply.
Sorry, you need to Log In to post a reply to this thread.