Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Private Chat[Room]"
#define VERSION "1.0"
#define AUTHOR "Alka"
#define CHAT_LEN_MAX 106
#define NO_PRIVACY 0
#define MAX_CHAT_ROOMS 5
#define ADVERTISE_RATE_TIME 180.0
new g_iPrivateChat[33];
new g_iPrivateRoom[33];
new g_iRoomOwner[MAX_CHAT_ROOMS + 1];
new g_iMaxPlayers;
new g_iSyncHud;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say", "clcmdHandleSay", -1, "");
register_clcmd("say_team", "clcmdHandleSayTeam", -1, "");
register_clcmd("say /pchelp", "clcmdShowHelp", -1, "");
g_iMaxPlayers = get_maxplayers();
g_iSyncHud = CreateHudSyncObj(0);
set_task(ADVERTISE_RATE_TIME, "taskAdvertise", 0, "", 0, "b", 0);
}
public taskAdvertise()
{
set_hudmessage(255, 150, 0, -1.0, 0.1, 0, 7.0, 7.0, 1.0, 1.0);
ShowSyncHudMsg(0, g_iSyncHud, "Type in chat /pchelp to learn how to use the Prive Chat[room].");
}
public client_connect(id)
{
g_iPrivateChat[id] = NO_PRIVACY;
g_iPrivateRoom[id] = NO_PRIVACY;
}
public client_disconnect(id)
{
if(g_iRoomOwner[g_iPrivateRoom[id]] == id)
{
resetChaters(g_iPrivateRoom[id]);
g_iRoomOwner[g_iPrivateRoom[id]] = 0;
}
if(g_iPrivateChat[id] != NO_PRIVACY)
{
g_iPrivateChat[g_iPrivateChat[id]] = NO_PRIVACY;
g_iPrivateChat[id] = NO_PRIVACY;
}
}
public clcmdHandleSay(id)
{
new szArgs[CHAT_LEN_MAX], szCommand[16], szRoom[8];
read_args(szArgs, sizeof szArgs - 1);
remove_quotes(szArgs);
if(!strlen(szArgs))
return 0;
parse(szArgs, szCommand, sizeof szCommand - 1, szArgs, sizeof szArgs - 1, szRoom, sizeof szRoom - 1);
if(equal(szCommand, "/private"))
{
if(equal(szArgs, "room"))
{
new iRoom = str_to_num(szRoom);
if(!(1 <= iRoom <= MAX_CHAT_ROOMS))
{
client_printc(id, "\gInvalid room number.");
return 1;
}
if(g_iRoomOwner[iRoom] != id && g_iRoomOwner[iRoom] > 0)
{
client_printc(id, "\gSomeone else is the owner of this chat room.To enter, ask for invitaion.");
return 1;
}
else if(!g_iRoomOwner[iRoom] && (g_iPrivateChat[id] == NO_PRIVACY))
{
g_iPrivateRoom[id] = iRoom;
g_iRoomOwner[iRoom] = id;
client_printc(id, "\gYou are entering private chat room \t#%d\g.To invite someone type \d'/invite <name>'", iRoom);
}
}
else
{
if(g_iPrivateChat[id] != NO_PRIVACY || g_iPrivateRoom[id] != NO_PRIVACY)
{
client_printc(id, "\gYou are already in a private [room] conversation.");
return 1;
}
new iPlayer = cmd_target(id, szArgs, 8);
if(!iPlayer)
{
client_printc(id, "\gInvalid player name.");
return 1;
}
else
{
new szPlName[32];
get_user_name(iPlayer, szPlName, sizeof szPlName - 1);
if(g_iPrivateChat[iPlayer] != NO_PRIVACY)
{
client_printc(id, "\t%s \gis already in a private conversation.", szPlName);
return 1;
}
else
{
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
g_iPrivateChat[id] = iPlayer;
g_iPrivateChat[iPlayer] = id;
client_printc(id, "\gYou are entering in a private conversation with \t%s.", szPlName);
client_printc(iPlayer, "\gYou are entering in a private conversation with \t%s.", szName);
client_printc(iPlayer, "\gUse your say_team key - usually \d'U' \g- to chat.");
}
}
}
}
else if(equal(szCommand, "/unprivate"))
{
if(equal(szArgs, "room"))
{
if(!g_iPrivateRoom[id])
{
client_printc(id, "\gYou are not in any private chat room.");
return 1;
}
else
{
if(g_iRoomOwner[g_iPrivateRoom[id]] == id)
{
resetChaters(g_iPrivateRoom[id]);
g_iRoomOwner[g_iPrivateRoom[id]] = 0;
g_iPrivateRoom[id] = 0;
}
else
{
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
for(new i = 1 ; i <= g_iMaxPlayers ; i++)
{
if(g_iPrivateRoom[i] != g_iPrivateRoom[id] || i == id)
continue;
client_printc(i, "\d(Room \t%i\d): \g%s \dis leaving the chat room.", g_iPrivateRoom[i], szName);
}
g_iPrivateRoom[id] = 0;
}
}
}
else
{
new iPlayer = g_iPrivateChat[id];
if(!iPlayer)
{
client_printc(id, "\gYou are not in any private chat.");
return 1;
}
else
{
new szPlName[32];
get_user_name(iPlayer, szPlName, sizeof szPlName - 1);
if(g_iPrivateChat[iPlayer] != NO_PRIVACY)
{
if(g_iPrivateChat[iPlayer] != id)
{
client_printc(id, "\t%s \gis not in a private conversation with you.", szPlName);
return 1;
}
else
{
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
g_iPrivateChat[id] = NO_PRIVACY;
g_iPrivateChat[iPlayer] = NO_PRIVACY;
client_printc(id, "\gYou have left the private conversation with \t%s.", szPlName);
client_printc(iPlayer, "\gYou have left the private conversation with \t%s.", szName);
}
}
}
}
}
else if(equali(szCommand, "/invite"))
{
if(g_iRoomOwner[g_iPrivateRoom[id]] != id)
{
client_printc(id, "\gYou can't invite someone if your not the owner of chat room.");
return 1;
}
else
{
new iPlayer = cmd_target(id, szArgs, 8);
if(!iPlayer)
{
client_printc(id, "\gInvalid player name.");
return 1;
}
new szPlName[32];
get_user_name(iPlayer, szPlName, sizeof szPlName - 1);
if(g_iPrivateRoom[iPlayer] != NO_PRIVACY || g_iPrivateChat[iPlayer] != NO_PRIVACY)
{
client_printc(id, "\t%s \gis already in a private chat [room].", szPlName);
return 1;
}
g_iPrivateRoom[iPlayer] = g_iPrivateRoom[id];
for(new i = 1 ; i <= g_iMaxPlayers ; i++)
{
if(g_iPrivateRoom[i] != g_iPrivateRoom[iPlayer] || i == iPlayer)
continue;
client_printc(i, "\d(Room \t%i\d): \g%s \dis entering the chat room.", g_iPrivateRoom[i], szPlName);
}
client_printc(iPlayer, "\gYou are entering private chat room \t#%d \gby invitation.", g_iPrivateRoom[id]);
client_printc(iPlayer, "\gUse your say_team key - usually \d'U' \g- to chat.");
}
}
return 0;
}
public clcmdHandleSayTeam(id)
{
new szArgs[CHAT_LEN_MAX], szBuffer[CHAT_LEN_MAX];
read_args(szArgs, sizeof szArgs - 1);
remove_quotes(szArgs);
if(!strlen(szArgs))
return 0;
if(g_iPrivateChat[id] != NO_PRIVACY)
{
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
formatex(szBuffer, sizeof szBuffer - 1, "\t%s \d(Private): %s", szName, szArgs);
client_printc(id, szBuffer);
client_printc(g_iPrivateChat[id], szBuffer);
return 1;
}
if(g_iPrivateRoom[id] != NO_PRIVACY)
{
new szName[32];
get_user_name(id, szName, sizeof szName - 1);
formatex(szBuffer, sizeof szBuffer - 1, "\t%s \d(Room \g%i\d): %s", szName, g_iPrivateRoom[id], szArgs);
for(new i = 1 ; i <= g_iMaxPlayers ; i++)
{
if(g_iPrivateRoom[i] != g_iPrivateRoom[id])
continue;
client_printc(i, szBuffer);
}
return 1;
}
return 0;
}
public clcmdShowHelp(id)
{
new szMotd[650], iLen;
iLen = formatex(szMotd, sizeof szMotd - 1,"<body bgcolor=#000000><font color=#87cefa><pre>");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "<center><h2><font color=^"red^">Private Chat[Room]</font></h2></center>^n^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "/private [name] - Start a private conversation with specified player.^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "/unprivate [name] - Leave the conversation with specified player.^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "/private room [number] - Create a private chat room.^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "/unprivate room - Leave the private chat room, including the chaters.^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "/invite [name] - Invite someone to your private chat room.^n^n");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "<font color=^"yellow^">[name] - The name/part of name of the person you want to chat.^n</font>");
iLen += formatex(szMotd[iLen], (sizeof szMotd - 1) - iLen, "<font color=^"yellow^">[number] - The number of the private chat room you want to create.</font>");
show_motd(id, szMotd, "Help");
}
stock resetChaters(iRoom)
{
for(new i = 1 ; i <= g_iMaxPlayers ; i++)
{
if(g_iPrivateRoom[i] != iRoom)
continue;
g_iPrivateRoom[i] = 0;
client_printc(i, "\gThe owner of chat room has left.You are no longer in this chat room.");
}
}
stock client_printc(id, const text[], {Float, Sql, Resul,_}:...) {
new szMsg[CHAT_LEN_MAX], iPlayers[32], iCount = 1;
vformat(szMsg, sizeof szMsg - 1, text, 3);
replace_all(szMsg, sizeof szMsg - 1, "\g","^x04");
replace_all(szMsg, sizeof szMsg - 1, "\d","^x01");
replace_all(szMsg, sizeof szMsg - 1, "\t","^x03");
if(id)
iPlayers[0] = id;
else
get_players(iPlayers, iCount, "ch");
for(new i = 0 ; i < iCount ; i++)
{
if(!is_user_connected(iPlayers[i]))
continue;
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, iPlayers[i]);
write_byte(iPlayers[i]);
write_string(szMsg);
message_end();
}
}
Instalare:
1. Fisierul Private Chat[Room].sma il puneti in addons/amxmodx/scripting
2. Fisierul Private Chat[Room].amxx il puneti in addons/amxmodx/plugins
3. Intrati in fisierul addons/amxmodx/configs/plugins.ini si adaugati la urma:
Code:
Private Chat[Room].amxx
Comenzi publice (se tasteaza in joc prin apasarea tastei Y):
/private <nume> - intri intr-o conversatie privata cu cineva
/unprivte <nume> - iesi din conversatie
/pchelp - iti arata meniul de convorbire private intr-un motd |