Hello, Im trying to make a chat command that when someone types !optout it runs a console command and prints "You have opted out"
The console command I want it to run is: jb_hasmic 0
My current code:
[CODE]function jb_optout(ply, text, public)
if ( string.find( bind, "undo" ) ) then
RunConsoleCommand("jb_hasmic",0)
ply:ChatPrint("You have opted out.")
end
end[/CODE]
Any help would be appreicated.
[lua]local function PonyFag(ply, text)
if string.sub(text, 1, 7) == "!optout" then
if ply != LocalPlayer() then return true end
RunConsoleCommand("jb_hasmic", 0)
chat.AddText("You have opted out.")
end
end
hook.Add("OnPlayerChat", "marshmellowybuttholes", PonyFag)[/lua]
client side
Lol Thanks.. But where do i put this exactly? lua/autorun?[QUOTE=zerothefallen;42889523][lua]local function PonyFag(ply, text)
if string.sub(text, 1, 7) == "!optout" then
if ply != LocalPlayer() then return true end
RunConsoleCommand("jb_hasmic", 0)
chat.AddText("You have opted out.")
end
end
hook.Add("OnPlayerChat", "marshmellowybuttholes", PonyFag)[/lua]
client side[/QUOTE]
[QUOTE=Bordermick;42889727]Lol Thanks.. But where do i put this exactly? lua/autorun?[/QUOTE]
Any clientside script. Like in any file in lua/autorun/client, a gamemode's cl_init.lua, etc.
ServerSide *cough, cough*
init.lua
[CODE]function chatCommand( Player, text)
if( string.Explode( " ", text )[1] == "!optout" ) then
RunConsoleCommand( "jd_hasmic 0" )
Player:ChatPrint("You have been opted out")
end
end[/CODE]
[QUOTE=incognitocob;42889763]Any clientside script. Like in any file in lua/autorun/client, a gamemode's cl_init.lua, etc.[/QUOTE]
It dosent seem to be working I dont understand whats wrong.
[QUOTE=Bordermick;42889850]It dosent seem to be working I dont understand whats wrong.[/QUOTE]
Are you running it on a server or singleplayer?
Talking about the guys code not my p.s
[QUOTE=PropGamer123;42889861]Are you running it on a server or singleplayer?
Talking about the guys code not my p.s[/QUOTE]On a server
[QUOTE=Bordermick;42889893]On a server[/QUOTE]
Are you running a gamemode if so
Open up your cl_Init.lua in gamemode/"gamemodename"/cl_init.lua open that .lua and copy and paste the code in.
For my instead of opening the cl_init.lua open the init.lua and copy and paste my code in.
[QUOTE=Bordermick;42889850]It dosent seem to be working I dont understand whats wrong.[/QUOTE]
Try PlayerSay. It's serverside (put it in lua/autorun/server).
[lua]local function ChatCommands( ply, text )
local gettext = string.Explode(" ", string.sub(text, 1, string.len(text)) )
if gettext[1] == "!optout" then
ply:ConCommand( "jb_hasmic 0" )
end
end
hook.Add( "PlayerSay", "optout", ChatCommands )[/lua]
Try that.
Thank you so much! This one worked! Just one last thing.. Would you be able to make it print "You have opted out." whenever you issue the command?[QUOTE=incognitocob;42889950]Try PlayerSay. It's serverside (put it in lua/autorun/server).
[lua]local function ChatCommands( ply, text )
local gettext = string.Explode(" ", string.sub(text, 1, string.len(text)) )
if gettext[1] == "!optout" then
ply:ConCommand( "jb_hasmic 0" )
end
end
hook.Add( "PlayerSay", "optout", ChatCommands )[/lua]
Try that.[/QUOTE]
[QUOTE=Bordermick;42890049]Thank you so much! This one worked! Just one last thing.. Would you be able to make it print "You have opted out." whenever you issue the command?[/QUOTE]
Add chat.AddText:
[lua]chat.AddText( Color( 255, 255, 255 ), "You have opted out." )[/lua]
It's client side though.
So would it look like this?
[lua]local function ChatCommands( ply, text )
local gettext = string.Explode(" ", string.sub(text, 1, string.len(text)) )
if gettext[1] == "!optout" then
ply:ConCommand( "jb_hasmic 0" )
chat.AddText( Color( 255, 255, 255 ), "You have opted out." )
end
end
hook.Add( "PlayerSay", "optout", ChatCommands )[/lua]
It's client side.
So do i put the whole file into client side?... lua/autorun/client?[QUOTE=incognitocob;42890090]It's client side.[/QUOTE]
Just add this after ply:ConCommand( "jb_hasmic 0" ):
[lua]ply:PrintMessage( HUD_PRINTTALK, "You have opted out." )[/lua]
This works perfectly! Thanks for all your help. I really appreciate it.[QUOTE=incognitocob;42890108]Just add this after ply:ConCommand( "jb_hasmic 0" ):
[lua]ply:PrintMessage( HUD_PRINTTALK, "You have opted out." )[/lua][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.