Всем привет. Если выдать мут чата -то игрок все равно может писать в него и префикс не сохраняется при смене карты + если нажать пробел и отправить будет: Тег Игрок: FFFFFF. Как это можно исправить?
Код:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools_functions>
#include <clientprefs>
#include <adminmenu>
#define COLORTAG "\x07"
public Plugin:myinfo =
{
name = "Name/Prefix/Text Color",
author = "deti90x-css.ru",
version = "1.0"
}
new Handle:g_hMenuColor,
Handle:g_hMenuPref;
new Handle:g_hCookie[4];
new String:g_sColors[MAXPLAYERS+1][3][15],
String:g_sPrefix[MAXPLAYERS+1][100],
g_iTypeMenu[MAXPLAYERS+1];
new Handle:g_hDbLocal = INVALID_HANDLE;
new g_cTime[MAXPLAYERS+1];
new Handle:hTopMenu = INVALID_HANDLE;
new g_ChatTarget[MAXPLAYERS+1];
new g_ChatTargetUserId[MAXPLAYERS+1];
public OnPluginStart()
{
g_hCookie[0] = RegClientCookie("Shop Name Color", "Name Color", CookieAccess_Public);
g_hCookie[1] = RegClientCookie("Shop Text Color", "Text Color", CookieAccess_Public);
g_hCookie[2] = RegClientCookie("Shop Prefix Color", "Prefix Color", CookieAccess_Public);
g_hCookie[3] = RegClientCookie("Shop Prefix", "Prefix", CookieAccess_Public);
RegConsoleCmd("sm_color", MyColor_CMD);
RegConsoleCmd("sm_myprefix", MyPref_CMD);
//RegAdminCmd("sm_addchat", Command_addChat, ADMFLAG_ROOT);
g_hMenuPref = CreateMenu(MenuHandler_Pref);
SetMenuExitBackButton(g_hMenuPref, true);
AddMenuItem(g_hMenuPref, "", "Для установки префикса", ITEMDRAW_DISABLED);
AddMenuItem(g_hMenuPref, "", "введите в консоль:", ITEMDRAW_DISABLED);
AddMenuItem(g_hMenuPref, "", "sm_myprefix \"ваш префикс\"", ITEMDRAW_DISABLED);
AddMenuItem(g_hMenuPref, "", "Либо в чат:", ITEMDRAW_DISABLED);
AddMenuItem(g_hMenuPref, "", "!myprefix \"ваш префикс\"", ITEMDRAW_DISABLED);
ConnectSQL();
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{
OnAdminMenuReady(topmenu);
}
}
public OnAdminMenuReady(Handle:topmenu)
{
/* Block us from being called twice */
if (topmenu == hTopMenu)
{
return;
}
/* Save the Handle */
hTopMenu = topmenu;
/* Find the "Player Commands" category */
new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT)
{
AddToTopMenu(hTopMenu,
"sm_addchat",
TopMenuObject_Item,
AdminMenu_addChat,
player_commands,
"sm_addchat",
ADMFLAG_ROOT);
}
}
public AdminMenu_addChat(Handle:topmenu,
TopMenuAction:action,
TopMenuObject:object_id,
param,
String:buffer[],
maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "Выдать цветной чат");
}
else if (action == TopMenuAction_SelectOption)
{
DisplayChatTargetMenu(param);
}
}
DisplayChatTargetMenu(client)
{
new Handle:menu = CreateMenu(MenuHandler_ChatPlayerList);
decl String:title[100];
Format(title, sizeof(title), "Дать цветной чат игроку:");
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public MenuHandler_ChatPlayerList(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
}
}
else if (action == MenuAction_Select)
{
decl String:info[32], String:name[32];
new userid, target;
GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
userid = StringToInt(info);
if ((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "[SM] Игрок вышел");
}
else if (!CanUserTarget(param1, target))
{
PrintToChat(param1, "[SM] Игрок не доступен");
}
else
{
g_ChatTarget[param1] = target;
g_ChatTargetUserId[param1] = userid;
DisplayChatTimeMenu(param1);
}
}
}
DisplayChatTimeMenu(client)
{
new Handle:menu = CreateMenu(MenuHandler_ChatTimeList);
decl String:title[100];
Format(title, sizeof(title), "Выдать чат: %N", g_ChatTarget[client]);
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
AddMenuItem(menu, "0", "Навсегда");
AddMenuItem(menu, "10", "10 минут");
AddMenuItem(menu, "30", "30 минут");
AddMenuItem(menu, "60", "1 час");
AddMenuItem(menu, "240", "4 часа");
AddMenuItem(menu, "1440", "1 день");
AddMenuItem(menu, "10080", "1 неделю");
AddMenuItem(menu, "43200", "1 месяц");
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public MenuHandler_ChatTimeList(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
}
}
else if (action == MenuAction_Select)
{
decl String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
new time = StringToInt(info);
new target;
if((target = GetClientOfUserId(g_ChatTargetUserId[param1])) == 0)
{
PrintToChat(param1, "[SM] Игрок вышел");
}
else if (!CanUserTarget(param1, target))
{
PrintToChat(param1, "[SM] Игрок не доступен");
}
else
{
db_InsertPlayer(g_ChatTarget[param1], time);
}
}
}
public OnMapStart() ParseCFG();
public OnClientPostAdminCheck(client)
{
if (IsClientInGame(client))
{
for(new i=0; i<3;i++)
{
g_sColors[client][i][0] = '\0';
}
g_sPrefix[client][0] = '\0';
g_cTime[client] = -1;
db_selectPlayer(client);
}
}
LoadNameColor(client)
{
GetClientCookie(client, g_hCookie[0], g_sColors[client][0], sizeof(g_sColors[][]));
Format(g_sColors[client][0], sizeof(g_sColors[][]), "%s%s", COLORTAG, (g_sColors[client][0][0] == '\0') ? "FFFFFF":g_sColors[client][0]);
}
LoadPrefix(client)
{
GetClientCookie(client, g_hCookie[2], g_sColors[client][2], sizeof(g_sColors[][]));
Format(g_sColors[client][2], sizeof(g_sColors[][]), "%s%s", COLORTAG, (g_sColors[client][2][0] == '\0') ? "FFFFFF":g_sColors[client][2]);
GetClientCookie(client, g_hCookie[3], g_sPrefix[client], sizeof(g_sPrefix[]));
if(g_sPrefix[client][0] == '\0') strcopy(g_sPrefix[client], sizeof(g_sPrefix[]), "Префикс");
}
LoadTextColor(client)
{
GetClientCookie(client, g_hCookie[1], g_sColors[client][1], sizeof(g_sColors[][]));
Format(g_sColors[client][1], sizeof(g_sColors[][]), "%s%s", COLORTAG, (g_sColors[client][1][0] == '\0') ? "FFFFFF":g_sColors[client][1]);
}
ParseCFG()
{
if(g_hMenuColor != INVALID_HANDLE)
{
CloseHandle(g_hMenuColor);
g_hMenuColor = INVALID_HANDLE;
}
new Handle:hKV = CreateKeyValues("Colors");
decl String:sBuffer[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sBuffer, sizeof(sBuffer), "configs/chat_colors.cfg");
if(!FileToKeyValues(hKV, sBuffer)) SetFailState("Файл '%s' не найден!", sBuffer);
KvRewind(hKV);
g_hMenuColor = CreateMenu(MenuHandler_Color);
SetMenuExitBackButton(g_hMenuColor, true);
if(KvGotoFirstSubKey(hKV))
{
decl String:sName[100], String:sColor[100];
do
{
if(KvGetSectionName(hKV, sName, sizeof(sName)))
{
KvGetString(hKV, "Color", sColor, sizeof(sColor));
AddMenuItem(g_hMenuColor, sColor, sName);
}
} while(KvGotoNextKey(hKV));
}
CloseHandle(hKV);
}
public Action:MyColor_CMD(client, args)
{
if(client > 0)
{
if(g_cTime[client] == 0 || g_cTime[client] > GetTime()) SendChatMenu(client);
else PrintToChat(client, "Для покупки цветного чата писать \x04denik#4316");
}
return Plugin_Handled;
}
SendChatMenu(client)
{
new Handle:hChatMenu = CreateMenu(MenuHandler_ChatMenu);
SetMenuTitle(hChatMenu, "Управление чатом\n \n");
AddMenuItem(hChatMenu, "", "Цвет ника");
AddMenuItem(hChatMenu, "", "Цвет текста");
AddMenuItem(hChatMenu, "", "Цвет префикса");
AddMenuItem(hChatMenu, "", "Префикс");
DisplayMenu(hChatMenu, client, MENU_TIME_FOREVER);
}
public MenuHandler_ChatMenu(Handle:hMenu, MenuAction:action, client, option)
{
if (action == MenuAction_Select)
{
if(option == 3) DisplayMenu(g_hMenuPref, client, MENU_TIME_FOREVER);
else
{
g_iTypeMenu[client] = option;
DisplayMenu(g_hMenuColor, client, MENU_TIME_FOREVER);
}
}
else if (action == MenuAction_End) CloseHandle(hMenu);
}
public MenuHandler_Color(Handle:hMenu, MenuAction:action, client, option)
{
if (action == MenuAction_Select)
{
decl String:sInfo[100];
GetMenuItem(hMenu, option, sInfo, sizeof(sInfo));
SetClientCookie(client, g_hCookie[g_iTypeMenu[client]], sInfo);
FormatEx(g_sColors[client][g_iTypeMenu[client]], sizeof(g_sColors[][]), "%s%s", COLORTAG, sInfo);
} else if (action == MenuAction_Cancel && option == MenuCancel_ExitBack) SendChatMenu(client);
}
public MenuHandler_Pref(Handle:hMenu, MenuAction:action, client, option)
{
if (action == MenuAction_Cancel && option == MenuCancel_ExitBack) SendChatMenu(client);
}
public Action:MyPref_CMD(client, args)
{
if(client > 0)
{
if(g_cTime[client] == 0 || g_cTime[client] > GetTime())
{
decl String:sPrefis[100];
GetCmdArgString(sPrefis, sizeof(sPrefis));
SetClientCookie(client, g_hCookie[3], sPrefis);
strcopy(g_sPrefix[client], sizeof(g_sPrefix[]), sPrefis);
ReplyToCommand(client, "Вы установили себе префикс: %s", sPrefis);
}
}
}
public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
{
if(client > 0 && !IsFakeClient(client))
{
if(g_cTime[client] == 0 || g_cTime[client] > GetTime())
{
if(sArgs[1] == '@' || sArgs[1] == '/') return Plugin_Continue;
decl String:sText[192];
strcopy(sText, sizeof(sText), sArgs);
TrimString(sText);
StripQuotes(sText);
new iTeam = GetClientTeam(client);
decl String:sNameColor[50], String:sTextColor[210], String:sPrefix[100];
FormatEx(sNameColor, sizeof(sNameColor), "%s%N", g_sColors[client][0], client);
FormatEx(sTextColor, sizeof(sTextColor), "\x01: %s%s", g_sColors[client][1], sText);
FormatEx(sPrefix, sizeof(sPrefix), "%s%s", g_sColors[client][2], g_sPrefix[client]);
if(StrEqual(command, "say"))
{
FormatEx(sText, sizeof(sText), "\x01%s %s %s%s", (iTeam < 2) ? "*НАБЛЮДАТЕЛЬ*":((IsPlayerAlive(client)) ? "":"*УБИТ*"), sPrefix, sNameColor, sTextColor);
new Handle:h = StartMessageAll("SayText2");
if (h != INVALID_HANDLE)
{
BfWriteByte(h, client);
BfWriteByte(h, true);
BfWriteString(h, sText);
EndMessage();
}
} else if(StrEqual(command, "say_team"))
{
FormatEx(sText, sizeof(sText), "\x01%s %s %s %s%s", (iTeam < 2) ? "(Наблюдатель)":((iTeam == 2) ? "(Террорист)":"(Спецназовец)"), (iTeam < 2) ? "":((IsPlayerAlive(client)) ? "":"*УБИТ*"), sPrefix, sNameColor, sTextColor);
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == iTeam)
{
new Handle:h = StartMessageOne("SayText2", i);
if (h != INVALID_HANDLE)
{
BfWriteByte(h, client);
BfWriteByte(h, true);
BfWriteString(h, sText);
EndMessage();
}
}
}
}
return Plugin_Handled;
}
}
return Plugin_Continue;
}
new String:sql_createtable[] = "CREATE TABLE IF NOT EXISTS chat (steamid varchar(32) PRIMARY KEY, unix int(10));";
ConnectSQL()
{
decl String:szError[255];
g_hDbLocal = SQLite_UseDatabase("chat-local", szError, sizeof(szError));
SQL_FastQuery(g_hDbLocal, sql_createtable);
}
new String:sql_selectPlayer[] = "SELECT steamid, unix FROM chat WHERE steamid = '%s';";
db_selectPlayer(client)
{
decl String:szQuery[255], String:szSteamId[32];
GetClientAuthString(client, szSteamId, 32);
Format(szQuery, 255, sql_selectPlayer, szSteamId);
SQL_TQuery(g_hDbLocal, SQL_SelectPlayerCallback, szQuery, client);
}
public SQL_SelectPlayerCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl == INVALID_HANDLE)
{
LogError("[CHAT] SelectPlayer: Error loading player, Reason: %s", error);
}
else
{
new client = data;
if(SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
g_cTime[client] = SQL_FetchInt(hndl, 1);
if(g_cTime[client] == 0 || g_cTime[client] > GetTime())
{
LoadNameColor(client);
LoadPrefix(client);
LoadTextColor(client);
}
}
}
return 1;
}
new String:sql_insertPlayer[] = "INSERT OR REPLACE INTO chat (steamid, unix) VALUES('%s', '%d');";
db_InsertPlayer(client, time)
{
decl String:szQuery[255], String:szSteamId[32];
GetClientAuthString(client, szSteamId, 32);
time = time * 60;
if(time != 0)
{
if(g_cTime[client] < GetTime())
{
g_cTime[client] = GetTime();
}
g_cTime[client] += time;
}
else
{
g_cTime[client] = 0;
}
Format(szQuery, 255, sql_insertPlayer, szSteamId, g_cTime[client]);
SQL_FastQuery(g_hDbLocal, szQuery);
LoadNameColor(client);
LoadPrefix(client);
LoadTextColor(client);
}
Последнее редактирование: