Printing role specific text upon action

I did look at https://wiki.garrysmod.com/page/chat/AddText 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

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:

I am trying this:


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)

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.

do [lua] ply:ConCommand(“say_team text”)[/lua]

EDIT:

dosen’t work

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 Player:Team and then send it from the server with Player:ChatPrint.

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.


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)

Would work much better.

////
Just updated it again, noticed I did something wrong :confused:

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()


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)

Cannot spot the error, hmmm



for k,players in pairs(player.GetAll()) do
if v:IsTraitor() then


You never defined V -_-

Also, why are you doing



ply:ChatPrint( ply:Nick() .. " bought a bomb station!" )


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)

Alright, did you read OP?

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