DarkRP:Group Chat
From GMod Wiki
This page has been nominated for deletion. Deletion is due within approximately 30 days from nomination, unless the deletion has been disputed on the talk page. See more pages nominated for deletion here. Reason for deletion: Not what Garry wants the wiki to be used for Last Edit was made on 11/16/2011 |
NOTE: This tutorial is not a customizable feature of DarkRP, it's a direct edit of the DarkRP code and so you should be VERY careful whilst editing it. Also, this tutorial was created using the DarkRP SVN Revision 596, the code may vary slightly with earlier versions, however the editing of it should be quite similar. I'd suggest you back-up your main.lua somewhere before you do this, just in case it doesn't work and you don't know what to change back.
Here I'm going to show you how you can create your own group chats, or add jobs to the current ones.
Go to DarkRP/gamemode/main.lua, open up your editors find box, and put in /g.
You should find:
local function GroupMsg(ply, args) if args == "" then return "" end local DoSay = function(text) if text == "" then return end local t = ply:Team() local audience = {} if t == TEAM_POLICE or t == TEAM_CHIEF or t == TEAM_MAYOR then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_POLICE or vt == TEAM_CHIEF or vt == TEAM_MAYOR then table.insert(audience, v) end end elseif t == TEAM_MOB or t == TEAM_GANG then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_MOB or vt == TEAM_GANG then table.insert(audience, v) end end end for k, v in pairs(audience) do local col = team.GetColor(ply:Team()) TalkToPerson(v, col, LANGUAGE.group..ply:Nick(),Color(255,255,255,255), text, ply) end end return args, DoSay end AddChatCommand("/g", GroupMsg)
This is the code we're going to be working with.
Editing the current group chats:
In the code above, two group chats are set up, the default ones, the gang chat and the police chat.
Let's say we want to add our custom team, TEAM_SWAT to the police group chat.
The specific bit of code for the police group chat is:
if t == TEAM_POLICE or t == TEAM_CHIEF or t == TEAM_MAYOR then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_POLICE or vt == TEAM_CHIEF or vt == TEAM_MAYOR then table.insert(audience, v) end end
Firstly we need to add "or t == TEAM_SWAT" into the first if function between the 'TEAM_MAYOR' and 'then'.
Then we need to add "or vt == TEAM_SWAT" into the second if function between the 'TEAM_MAYOR' and 'then'.
The final code should look like:
if t == TEAM_POLICE or t == TEAM_CHIEF or t == TEAM_MAYOR or t == TEAM_SWAT then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_POLICE or vt == TEAM_CHIEF or vt == TEAM_MAYOR or vt == TEAM_SWAT then table.insert(audience, v) end end
To create your own group chat:
To add your own group chat, we're simply going to copy and paste the default extra group chat, the gang chat, and edit it slightly.
elseif t == TEAM_MOB or t == TEAM_GANG then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_MOB or vt == TEAM_GANG then table.insert(audience, v) end end end
Firstly, copy and paste this bit in below the gang chat, so the code should now look like this:
local function GroupMsg(ply, args) if args == "" then return "" end local DoSay = function(text) if text == "" then return end local t = ply:Team() local audience = {} if t == TEAM_POLICE or t == TEAM_CHIEF or t == TEAM_MAYOR then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_POLICE or vt == TEAM_CHIEF or vt == TEAM_MAYOR then table.insert(audience, v) end end elseif t == TEAM_MOB or t == TEAM_GANG then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_MOB or vt == TEAM_GANG then table.insert(audience, v) end end elseif t == TEAM_MOB or t == TEAM_GANG then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_MOB or vt == TEAM_GANG then table.insert(audience, v) end end end for k, v in pairs(audience) do local col = team.GetColor(ply:Team()) TalkToPerson(v, col, LANGUAGE.group..ply:Nick(),Color(255,255,255,255), text, ply) end end return args, DoSay end AddChatCommand("/g", GroupMsg)
Then we want to edit the bit we just pasted to suit our other jobs, for example:
local function GroupMsg(ply, args) if args == "" then return "" end local DoSay = function(text) if text == "" then return end local t = ply:Team() local audience = {} if t == TEAM_POLICE or t == TEAM_CHIEF or t == TEAM_MAYOR then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_POLICE or vt == TEAM_CHIEF or vt == TEAM_MAYOR then table.insert(audience, v) end end elseif t == TEAM_MOB or t == TEAM_GANG then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_MOB or vt == TEAM_GANG then table.insert(audience, v) end end elseif t == TEAM_HOBO then for k, v in pairs(player.GetAll()) do local vt = v:Team() if vt == TEAM_HOBO then table.insert(audience, v) end end end for k, v in pairs(audience) do local col = team.GetColor(ply:Team()) TalkToPerson(v, col, LANGUAGE.group..ply:Nick(),Color(255,255,255,255), text, ply) end end return args, DoSay end AddChatCommand("/g", GroupMsg)
Here I have set up a third group chat for the hobos.