• DarkRP Chat commands
    14 replies, posted
I want to learn how to make commands that goto certin jobs e.g /cab <message> That then goes to any one online which is TEAM_CAB, where should i start or what should i do?
well, i would make something for you but I'm not on my computer at this second. Roughly, this is the way you'll do it: Start off with the PlayerSay hook, then determining it has the words "/cab" in it. scan for every player ( the player.GetAll table ) and see if that players team = TEAM_CAB. Then you might math.Random a key in that table. Get that player's position and set your players position by Player:SetPos( OtherPlayer:GetEyePos():Forward * 2 or something) end the functions
[QUOTE=Exploderguy;47280572]well, i would make something for you but I'm not on my computer at this second. Roughly, this is the way you'll do it: Start off with the PlayerSay hook, then determining it has the words "/cab" in it. scan for every player ( the player.GetAll table ) and see if that players team = TEAM_CAB. Then you might math.Random a key in that table. Get that player's position and set your players position by Player:SetPos( OtherPlayer:GetEyePos():Forward * 2 or something) end the functions[/QUOTE] Ok that makes sense but when you get to your computer would you be able to help me a bit more like where to put it ect
[QUOTE=Borris_Squad;47280652]Ok that makes sense but when you get to your computer would you be able to help me a bit more like where to put it ect[/QUOTE] server
[QUOTE=Invule;47280705]server[/QUOTE] ?
[QUOTE=Borris_Squad;47280712]?[/QUOTE] autorun/server/
[QUOTE=Invule;47280798]autorun/server/[/QUOTE] no
[QUOTE=Borris_Squad;47280873]no[/QUOTE] I woulda spoon fed you, but Exploderguy already told you everything you need to know. Now its your turn. Do what Exploderguy said, and put all of that in autorun/server [url]http://wiki.garrysmod.com/page/Main_Page[/url] Oh heres another tip, try gooling playersay hook, you'll get 2 examples.
[QUOTE=Exploderguy;47280572]well, i would make something for you but I'm not on my computer at this second. Roughly, this is the way you'll do it: Start off with the PlayerSay hook, then determining it has the words "/cab" in it. scan for every player ( the player.GetAll table ) and see if that players team = TEAM_CAB. Then you might math.Random a key in that table. Get that player's position and set your players position by Player:SetPos( OtherPlayer:GetEyePos():Forward * 2 or something) end the functions[/QUOTE] i cant find the Play.GetALL table
[code] //server util.AddNetworkString( "send_to_cab" ) function googling_playersay_hook_and_networking_is_hard( ply, text ) if ( text:sub( 1, 4 ) == "/cab" ) then for k,v in pairs( player.GetAll() ) do if ( v:Team() == TEAM_CAB ) then net.Start( "send_to_cab" ) net.WriteString( sub:text( 6 ) ) net.Send( v ) end end end end hook.Add( "PlayerSay", "google", googling_playersay_hook_and_networking_is_hard ) //client net.Receive( "send_to_cab", function( len, ply ) local cab = net.ReadString() chat.AddText( Color( 255, 255, 255, 255 ), cab ) end ) [/code] sry for any errors, quickly wrote it up.
[QUOTE=Invule;47362689][code] //server util.AddNetworkString( "send_to_cab" ) function googling_playersay_hook_and_networking_is_hard( ply, text ) if ( text:sub( 1, 4 ) == "/cab" ) then for k,v in pairs( player.GetAll() ) do if ( v:Team() == TEAM_CAB ) then net.Start( "send_to_cab" ) net.WriteString( sub:text( 6 ) ) net.Send( v ) end end end end hook.Add( "PlayerSay", "google", googling_playersay_hook_and_networking_is_hard ) //client net.Receive( "send_to_cab", function( len, ply ) local cab = net.ReadString() chat.AddText( Color( 255, 255, 255, 255 ), cab ) end ) [/code] sry for any errors, quickly wrote it up.[/QUOTE] so where should i put this autorun/server/? And what file name?
File name: dbuomrbris.lua
Use whatever filename you want But id suggest making a folder inside of addons and name it whatever then put a lua folder inside of the whatever folder then put a autorun folder inside of the lua folder then put a client folder inside of the autorun folder then put a server folder inside of the autorun folder then put the serverside code inside of the server side folder, and put the client side code inside of the client side folder.
[QUOTE=Invule;47367325]Use whatever filename you want But id suggest making a folder inside of addons and name it whatever then put a lua folder inside of the whatever folder then put a autorun folder inside of the lua folder then put a client folder inside of the autorun folder then put a server folder inside of the autorun folder then put the serverside code inside of the server side folder, and put the client side code inside of the client side folder.[/QUOTE] But what you made is not a chat command?
[QUOTE=Borris_Squad;47373937]But what you made is not a chat command?[/QUOTE] Yes? Did you look at the code? Did you try it?
Sorry, you need to Log In to post a reply to this thread.