DarkRP:Group Chat

From Official DarkRP Wiki
Revision as of 21:24, 22 December 2011 by FPtje (talk | contribs) (Created page with " '''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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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: <lua> 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) </lua>

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:

<lua> 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 </lua>

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:

<lua> 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 </lua>

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.

<lua> 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 </lua>

Firstly, copy and paste this bit in below the gang chat, so the code should now look like this:

<lua> 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) </lua>

Then we want to edit the bit we just pasted to suit our other jobs, for example:

<lua> 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) </lua>

Here I have set up a third group chat for the hobos.