Advertisements: split casuals and vips

This commit is contained in:
Dogan 2019-08-13 21:35:45 +02:00
parent 1818a3a8b1
commit 7b669792a3

View File

@ -7,13 +7,13 @@
#pragma newdecls required
#pragma semicolon 1
#define PL_VERSION "2.0.2"
#define UPDATE_URL "http://ErikMinekus.github.io/sm-advertisements/update.txt"
#define PL_VERSION "3.0.0"
#define UPDATE_URL "http://ErikMinekus.github.io/sm-advertisements/update.txt"
public Plugin myinfo =
{
name = "Advertisements",
author = "Tsunami",
author = "Tsunami + Dogan",
description = "Display advertisements",
version = PL_VERSION,
url = "http://www.tsunami-productions.nl"
@ -23,9 +23,11 @@ public Plugin myinfo =
/**
* Globals
*/
KeyValues g_hAdvertisements;
KeyValues g_hAdvertisementsRegular;
KeyValues g_hAdvertisementsVIP;
ConVar g_hEnabled;
ConVar g_hFile;
ConVar g_hFileRegular;
ConVar g_hFileVIP;
ConVar g_hInterval;
Handle g_hTimer;
@ -36,11 +38,13 @@ Handle g_hTimer;
public void OnPluginStart()
{
CreateConVar("sm_advertisements_version", PL_VERSION, "Display advertisements", FCVAR_NOTIFY);
g_hEnabled = CreateConVar("sm_advertisements_enabled", "1", "Enable/disable displaying advertisements.");
g_hFile = CreateConVar("sm_advertisements_file", "advertisements.txt", "File to read the advertisements from.");
g_hEnabled = CreateConVar("sm_advertisements_enabled", "1", "Enable/disable displaying advertisements.");
g_hFileRegular = CreateConVar("sm_advertisements_file_regular", "advertisements_regular.txt", "File to read the regular advertisements from.");
g_hFileVIP = CreateConVar("sm_advertisements_file_vip", "advertisements_VIP.txt", "File to read the vip advertisements from.");
g_hInterval = CreateConVar("sm_advertisements_interval", "30", "Amount of seconds between advertisements.");
g_hFile.AddChangeHook(ConVarChange_File);
g_hFileRegular.AddChangeHook(ConVarChange_File);
g_hFileVIP.AddChangeHook(ConVarChange_File);
g_hInterval.AddChangeHook(ConVarChange_Interval);
RegServerCmd("sm_advertisements_reload", Command_ReloadAds, "Reload the advertisements");
@ -59,6 +63,26 @@ public void OnMapStart()
g_hTimer = CreateTimer(g_hInterval.IntValue * 1.0, Timer_DisplayAd, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_DisplayAd(Handle timer)
{
if (!g_hEnabled.BoolValue) {
return Plugin_Handled;
}
Timer_DisplayAdRegulars();
Timer_DisplayAdVIP();
return Plugin_Continue;
}
public bool IsVIP(int client)
{
if(CheckCommandAccess(client, "", ADMFLAG_CUSTOM1))
return true;
else
return false;
}
public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "updater")) {
@ -100,19 +124,15 @@ public int Handler_DoNothing(Menu menu, MenuAction action, int param1, int param
/**
* Timers
*/
public Action Timer_DisplayAd(Handle timer)
public void Timer_DisplayAdRegulars()
{
if (!g_hEnabled.BoolValue) {
return;
}
char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[16];
g_hAdvertisements.GetString("center", sCenter, sizeof(sCenter));
g_hAdvertisements.GetString("chat", sChat, sizeof(sChat));
g_hAdvertisements.GetString("hint", sHint, sizeof(sHint));
g_hAdvertisements.GetString("menu", sMenu, sizeof(sMenu));
g_hAdvertisements.GetString("top", sTop, sizeof(sTop));
g_hAdvertisements.GetString("flags", sFlags, sizeof(sFlags), "none");
g_hAdvertisementsRegular.GetString("center", sCenter, sizeof(sCenter));
g_hAdvertisementsRegular.GetString("chat", sChat, sizeof(sChat));
g_hAdvertisementsRegular.GetString("hint", sHint, sizeof(sHint));
g_hAdvertisementsRegular.GetString("menu", sMenu, sizeof(sMenu));
g_hAdvertisementsRegular.GetString("top", sTop, sizeof(sTop));
g_hAdvertisementsRegular.GetString("flags", sFlags, sizeof(sFlags), "none");
int iFlags = ReadFlagString(sFlags);
bool bAdmins = StrEqual(sFlags, ""),
bFlags = !StrEqual(sFlags, "none");
@ -122,7 +142,7 @@ public Action Timer_DisplayAd(Handle timer)
CRemoveColors(sCenter, sizeof(sCenter));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
if (IsClientInGame(i) && !IsFakeClient(i) && !IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
PrintCenterText(i, sCenter);
@ -139,7 +159,7 @@ public Action Timer_DisplayAd(Handle timer)
CRemoveColors(sHint, sizeof(sHint));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
if (IsClientInGame(i) && !IsFakeClient(i) && !IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
PrintHintText(i, sHint);
@ -155,7 +175,7 @@ public Action Timer_DisplayAd(Handle timer)
hPl.CurrentKey = 10;
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
if (IsClientInGame(i) && !IsFakeClient(i) && !IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
hPl.Send(i, Handler_DoNothing, 10);
@ -172,7 +192,7 @@ public Action Timer_DisplayAd(Handle timer)
CAddWhiteSpace(sChat, sizeof(sChat));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
if (IsClientInGame(i) && !IsFakeClient(i) && !IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (bTeamColor) {
@ -196,7 +216,7 @@ public Action Timer_DisplayAd(Handle timer)
hKv.SetNum("time", 10);
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
if (IsClientInGame(i) && !IsFakeClient(i) && !IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
CreateDialog(i, hKv, DialogType_Msg);
@ -206,9 +226,117 @@ public Action Timer_DisplayAd(Handle timer)
delete hKv;
}
if (!g_hAdvertisements.GotoNextKey()) {
g_hAdvertisements.Rewind();
g_hAdvertisements.GotoFirstSubKey();
if (!g_hAdvertisementsRegular.GotoNextKey()) {
g_hAdvertisementsRegular.Rewind();
g_hAdvertisementsRegular.GotoFirstSubKey();
}
}
public void Timer_DisplayAdVIP()
{
char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[16];
g_hAdvertisementsVIP.GetString("center", sCenter, sizeof(sCenter));
g_hAdvertisementsVIP.GetString("chat", sChat, sizeof(sChat));
g_hAdvertisementsVIP.GetString("hint", sHint, sizeof(sHint));
g_hAdvertisementsVIP.GetString("menu", sMenu, sizeof(sMenu));
g_hAdvertisementsVIP.GetString("top", sTop, sizeof(sTop));
g_hAdvertisementsVIP.GetString("flags", sFlags, sizeof(sFlags), "none");
int iFlags = ReadFlagString(sFlags);
bool bAdmins = StrEqual(sFlags, ""),
bFlags = !StrEqual(sFlags, "none");
if (sCenter[0]) {
ProcessVariables(sCenter);
CRemoveColors(sCenter, sizeof(sCenter));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
PrintCenterText(i, sCenter);
DataPack hCenterAd;
CreateDataTimer(1.0, Timer_CenterAd, hCenterAd, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
hCenterAd.WriteCell(i);
hCenterAd.WriteString(sCenter);
}
}
}
if (sHint[0]) {
ProcessVariables(sHint);
CRemoveColors(sHint, sizeof(sHint));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
PrintHintText(i, sHint);
}
}
}
if (sMenu[0]) {
ProcessVariables(sMenu);
CRemoveColors(sMenu, sizeof(sMenu));
Panel hPl = new Panel();
hPl.DrawText(sMenu);
hPl.CurrentKey = 10;
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
hPl.Send(i, Handler_DoNothing, 10);
}
}
delete hPl;
}
if (sChat[0]) {
bool bTeamColor = StrContains(sChat, "{teamcolor}", false) != -1;
ProcessVariables(sChat);
CProcessVariables(sChat, sizeof(sChat));
CAddWhiteSpace(sChat, sizeof(sChat));
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (bTeamColor) {
CSayText2(i, sChat, i);
} else {
PrintToChat(i, sChat);
}
}
}
}
if (sTop[0]) {
int iStart = 0,
aColor[4] = {255, 255, 255, 255};
ParseTopColor(sTop, iStart, aColor);
ProcessVariables(sTop[iStart]);
KeyValues hKv = new KeyValues("Stuff", "title", sTop[iStart]);
hKv.SetColor4("color", aColor);
hKv.SetNum("level", 1);
hKv.SetNum("time", 10);
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsVIP(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
CreateDialog(i, hKv, DialogType_Msg);
}
}
delete hKv;
}
if (!g_hAdvertisementsVIP.GotoNextKey()) {
g_hAdvertisementsVIP.Rewind();
g_hAdvertisementsVIP.GotoFirstSubKey();
}
}
@ -236,19 +364,32 @@ public Action Timer_CenterAd(Handle timer, DataPack pack)
*/
void ParseAds()
{
delete g_hAdvertisements;
g_hAdvertisements = CreateKeyValues("Advertisements");
delete g_hAdvertisementsRegular;
delete g_hAdvertisementsVIP;
g_hAdvertisementsRegular = CreateKeyValues("AdvertisementsRegular");
g_hAdvertisementsVIP = CreateKeyValues("AdvertisementsVIP");
char sFile[64], sPath[PLATFORM_MAX_PATH];
g_hFile.GetString(sFile, sizeof(sFile));
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/%s", sFile);
char sFileRegular[64], sPath[PLATFORM_MAX_PATH];
char sFileVIP[64];
g_hFileRegular.GetString(sFileRegular, sizeof(sFileRegular));
g_hFileVIP.GetString(sFileVIP, sizeof(sFileVIP));
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/%s", sFileRegular);
if (!FileExists(sPath)) {
SetFailState("File Not Found: %s", sPath);
}
g_hAdvertisements.ImportFromFile(sPath);
g_hAdvertisements.GotoFirstSubKey();
g_hAdvertisementsRegular.ImportFromFile(sPath);
g_hAdvertisementsRegular.GotoFirstSubKey();
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/%s", sFileVIP);
if (!FileExists(sPath)) {
SetFailState("File Not Found: %s", sPath);
}
g_hAdvertisementsVIP.ImportFromFile(sPath);
g_hAdvertisementsVIP.GotoFirstSubKey();
}
void ProcessVariables(char sText[1024])