-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadvertisements.sp
More file actions
160 lines (131 loc) · 4.91 KB
/
advertisements.sp
File metadata and controls
160 lines (131 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Database g_Database = null;
#define SQL_TABLENAME "ebans"
#define WEBSITEURL "\x03www.efrag.gg"
#define DISCORDURL "\x03www.efrag.gg/discord"
#define STOREURL "\x03www.efrag.gg/store"
#define SERVERTYPE "all"
#define PREFIX "\x01\x0B\x01[\x03eFrag\x01]"
#define ADVERTISEMENT_TIME 90.0
#define MAX_ADS 64
#define MAX_COLORS 14
enum Type { CHAT = 0, HINT = 1, CENTER = 2 };
enum EColorCodes { EColorCodes_Name = 0, EColorCodes_Hex }
char g_Colors[MAX_COLORS][EColorCodes][] = {
{"{WHITE}", "\x08"},
{"{DEFAULT}", "\x08"},
{"{RED}", "\x0F"},
{"{RED2}", "\x0F"},
{"{GREEN}", "\x04"},
{"{GREEN2}", "\x06"},
{"{BLUE}", "\x0C"},
{"{LIGHTBLUE}", "\x0B"},
{"{GRAY}", "\x0A"},
{"{GRAY2}", "\x08"},
{"{GOLD}", "\x10"},
{"{ORANGE}", "\x10"},
{"{PINK}", "\x0E"},
{"{PURPLE}", "\x03"},
};
/*
CREATE TABLE `efrag_adverts` (
`id` INT(7) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`message` VARCHAR(255) NOT NULL,
`color` VARCHAR(255) NOT NULL DEFAULT "{RED}",
`position` tinyint NOT NULL,
`vip` tinyint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
*/
public Plugin myinfo = {
name = "efrag.gg | Advertisements",
author = "zwolof",
description = "Send chat advertisements",
version = "1.0.0",
url = "www.efrag.gg"
};
enum struct Advertisement_t {
char message[256];
char color[64];
bool vip;
int position;
}
ArrayList g_alAdvertisements = null;
public void OnPluginStart() {
Database.Connect(SQL_ConnectCallback, SQL_TABLENAME);
g_alAdvertisements = new ArrayList(sizeof(Advertisement_t));
}
public void OnPluginEnd() {
delete g_alAdvertisements;
}
public void SQL_ConnectCallback(Database db, const char[] error, any data) {
if(db == null) {
SetFailState("T_Connect returned invalid Database Handle");
return;
}
g_Database = db;
SQL_FetchAds();
}
void SQL_FetchAds() {
char szQuery[1024];
g_Database.Format(szQuery, sizeof(szQuery), "SELECT * FROM `efrag_adverts_v1` WHERE servertype = '%s' OR servertype = 'all' ORDER BY id ASC;", SERVERTYPE);
g_Database.Query(SQL_FetchAds_Callback, szQuery);
}
public int SQL_FetchAds_Callback(Database db, DBResultSet results, const char[] szError, any data) {
if(db == null || results == null) {
LogError("[SQL] Select Query failure: %s", szError);
return;
}
if(results.RowCount <= 0) {
LogError("[SQL] Select Query failure: %s", szError);
return;
}
int message, position, vip, color;
results.FieldNameToNum("message", message);
results.FieldNameToNum("position", position);
results.FieldNameToNum("vip", vip);
results.FieldNameToNum("color", color);
Advertisement_t ad;
while(results.FetchRow()) {
results.FetchString(message, ad.message, sizeof(Advertisement_t::message));
results.FetchString(color, ad.color, sizeof(Advertisement_t::color));
ad.vip = results.FetchInt(vip);
ad.position = results.FetchInt(position);
g_alAdvertisements.PushArray(ad, sizeof(Advertisement_t));
}
CreateTimer(ADVERTISEMENT_TIME, AdvertisementTimer_CallBack, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action AdvertisementTimer_CallBack(Handle tmr, any data) {
static int currentAd = 0;
if(g_alAdvertisements.Length == 0) {
return Plugin_Continue;
}
Advertisement_t ad; g_alAdvertisements.GetArray(currentAd, ad, sizeof(Advertisement_t));
Colorize(ad.message, sizeof(Advertisement_t::message));
Colorize(ad.color, sizeof(Advertisement_t::color));
ReplaceString(ad.message, sizeof(Advertisement_t::message), "{WEBSITE}", WEBSITEURL, true);
ReplaceString(ad.message, sizeof(Advertisement_t::message), "{DISCORD}", DISCORDURL, true);
ReplaceString(ad.message, sizeof(Advertisement_t::message), "{STORE}", STOREURL, true);
ReplaceString(ad.message, sizeof(Advertisement_t::message), "{PREFIX}", PREFIX, true);
ReplaceString(ad.message, sizeof(Advertisement_t::message), "{COLOR}", ad.color, true);
char sMultipleLines[9][1024];
int iCount = ExplodeString(ad.message, "\\n", sMultipleLines, sizeof(sMultipleLines), sizeof(sMultipleLines[]));
for(int i = 1; i <= MaxClients; i++) {
if(!IsClientInGame(i) || IsFakeClient(i)) {
continue;
}
if(ad.vip && CheckCommandAccess(i, "sm_vip", ADMFLAG_CUSTOM6, true)) {
continue;
}
PrintToChat(i, " %s▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬", ad.color);
for(int y = 0; y < iCount; y++) {
PrintToChat(i, " \x01\x0B\x08%s", sMultipleLines[y]);
}
PrintToChat(i, " %s▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬", ad.color);
}
currentAd = (currentAd == g_alAdvertisements.Length - 1) ? 0 : currentAd + 1;
return Plugin_Continue;
}
stock void Colorize(char[] str, int maxlen) {
for (int i = 0; i < sizeof(g_Colors); i++) {
ReplaceString(str, maxlen, g_Colors[i][EColorCodes_Name], g_Colors[i][EColorCodes_Hex]);
}
}