• Printing role specific text upon action
    13 replies, posted
I did look at [url]https://wiki.garrysmod.com/page/chat/AddText[/url] and since i'm still learning lua, i am unable to put it together. Example: upon purchasing a weapon on TTT, text will be placed in the traitor chat, including the person who purchased it's name. I am not looking to be spoonfed but a little help would be great
make the player use say_team concommand? it'd make the player say it in the team chat, includes the name? Its the simplest solution
[QUOTE=whitestar;49626250]make the player use say_team concommand? it'd make the player say it in the team chat, includes the name? Its the simplest solution[/QUOTE] I see. Is there a function or hook for when a user purchases a traitor weapon?
If you're ever unsure or in search of a hook, google it's name along with ttt or gmod or gmod wiki and you'll usually find a page with it You're in luck, you can find exactly what you want here: [url]http://ttt.badking.net/guides/hooks[/url]
I am trying this: [CODE]function TestFunction(ply, equipment, is_item) if ( equipment == "weapon_ttt_bomb_station" ) then RunConsoleCommand("say_team" ..ply:Nick().. "has bought a bomb station!") end end hook.Add("TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction)[/CODE] RunConsoleCommand: Command has invalid characters! (say_teamseabedshas bought a bomb station! (' ')) The first parameter of this function should contain only the command, the second parameter should contain arguments.
[QUOTE=seabeds;49626713]I am trying this: [CODE]function TestFunction(ply, equipment, is_item) if ( equipment == "weapon_ttt_bomb_station" ) then RunConsoleCommand("say_team" ..ply:Nick().. "has bought a bomb station!") end end hook.Add("TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction)[/CODE] RunConsoleCommand: Command has invalid characters! (say_teamseabedshas bought a bomb station! (' ')) The first parameter of this function should contain only the command, the second parameter should contain arguments.[/QUOTE] do [lua] ply:ConCommand("say_team text")[/lua] EDIT: dosen't work
[QUOTE=seabeds;49626713]I am trying this: [CODE]function TestFunction(ply, equipment, is_item) if ( equipment == "weapon_ttt_bomb_station" ) then RunConsoleCommand("say_team" ..ply:Nick().. "has bought a bomb station!") end end hook.Add("TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction)[/CODE] RunConsoleCommand: Command has invalid characters! (say_teamseabedshas bought a bomb station! (' ')) The first parameter of this function should contain only the command, the second parameter should contain arguments.[/QUOTE] You shouldn't make the player say it, what I'd do is do a for loop through all the players checking if they're on a certain team using [url=http://wiki.garrysmod.com/page/Player/Team]Player:Team[/url] and then send it from the server with [url=http://wiki.garrysmod.com/page/Player/ChatPrint]Player:ChatPrint[/url]. ... The reason your code didn't work is because ".." doesn't create a space it just joins the two strings. And with RunConsoleCommand you need to seperate the arguments with a comma, instead. [CODE]function TestFunction(ply, equipment, is_item) if ( equipment == "weapon_ttt_bomb_station" ) then RunConsoleCommand("say_team", ply:Nick().. " has bought a bomb station!") end end hook.Add("TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction)[/CODE] Would work much better. //// Just updated it again, noticed I did something wrong :/
[QUOTE=Promptitude;49629528]You shouldn't make the player say it, what I'd do is do a for loop through all the players checking if they're on a certain team using [url=http://wiki.garrysmod.com/page/Player/Team]Player:Team[/url] and then send it from the server with [url=http://wiki.garrysmod.com/page/Player/ChatPrint]Player:ChatPrint[/url]. ... The reason your code didn't work is because ".." doesn't create a space it just joins the two strings. And with RunConsoleCommand you need to seperate the arguments with a comma, instead. [CODE]function TestFunction(ply, equipment, is_item) if ( equipment == "weapon_ttt_bomb_station" ) then RunConsoleCommand("say_team", ply:Nick(), "has bought a bomb station!") end end hook.Add("TTTOrderedEquipment", "MyTTTEquipmentHook", TestFunction)[/CODE] Would work much better.[/QUOTE] Upon using that version, i receive the same error.
How can i have a loop to check player's teams? That way i can use chatprint
use a for loop and loop through player.GetAll(), then check the team with value:Team()
[CODE]hook.Add("ChatWarning", "Bomb", function(ply) if ply:HasEquipmentItem(EQUIP_BOMBSTATION) then for k,players in pairs(player.GetAll()) do if v:IsTraitor() then ply:ChatPrint( ply:Nick() .. " bought a bomb station!" ) end end end end)[/CODE] Cannot spot the error, hmmm
[CODE] for k,players in pairs(player.GetAll()) do if v:IsTraitor() then [/CODE] You never defined V -_- Also, why are you doing [CODE] ply:ChatPrint( ply:Nick() .. " bought a bomb station!" ) [/CODE] That isn't going to work properly since you're printing it to the player's chat who bought the bomb thing (a ton of times for every traitor on the server)
[QUOTE=MPan1;49636120][CODE] for k,players in pairs(player.GetAll()) do if v:IsTraitor() then [/CODE] You never defined V -_- Also, why are you doing [CODE] ply:ChatPrint( ply:Nick() .. " bought a bomb station!" ) [/CODE] That isn't going to work properly since you're printing it to the player's chat who bought the bomb thing (a ton of times for every traitor on the server)[/QUOTE] Alright, did you read OP?
[QUOTE=seabeds;49636133]Alright, did you read OP?[/QUOTE] Yeah, I did? I'm not spoonfeeding you if that's what you mean since I'm not really telling you what to do, just pointing out what the problem is [editline]30th January 2016[/editline] Also, (this might be wrong since I don't know about TTT), but the ChatWarning hook probably wouldn't be called when a player buys a bomb station unless it does some kind of warning for some odd reason
Sorry, you need to Log In to post a reply to this thread.