-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWeaponTags.sp
210 lines (169 loc) · 6 KB
/
WeaponTags.sp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <sourcemod>
#include <sdktools>
#include <adt_trie>
//TODO test and fix line erorrs below
/**
African | 208k: ah quick question
African | 208k: Format(query, sizeof(query),
"SELECT * FROM wtags WHERE SteamID= %s", steamID);
African | 208k: do i need to put quotes around the %s
African | 208k: cuz that would explain why it isnt querying right
Headline: Format(query, sizeof(query),
"SELECT * FROM wtags WHERE SteamID= \"%s\"", steamID);
Headline: should work fine
use '%s', variable
*/
//using steam id 64
/**
ShtSpk ۞[۞P۞T۞: One guy said this on alliedmod
ShtSpk ۞[۞P۞T۞: I think nametags can be added via it "m_szCustomName"
*/
StringMap map[MAXPLAYERS + 1];
Handle g_db;
char newName[128];
char steamID[128];
char errorMSG[] = "ERROR: Database can't be connected to";
char QUERY_CreateTable[] = "CREATE TABLE IF NOT EXISTS wtags (SteamID VARCHAR(34) NOT NULL PRIMARY KEY, weapon_negev CHAR(30), \
weapon_m249 CHAR(30), weapon_bizon CHAR(30), weapon_p90 CHAR(30), weapon_scar20 CHAR(30), weapon_g3gs1 CHAR(30), \
weapon_m4a1 CHAR(30), weapon_m4a1_silencer CHAR(30), weapon_ak47 CHAR(30), weapon_aug CHAR(30), \
weapon_galilar CHAR(30), weapon_awp CHAR(30), weapon_sg556 CHAR(30), weapon_ump45 CHAR(30), \
weapon_mp7 CHAR(30), weapon_famas CHAR(30), weapon_mp9 CHAR(30), weapon_mac10 CHAR(30), \
weapon_ssg08 CHAR(30), weapon_nova CHAR(30), weapon_xm1014 CHAR(30), weapon_sawedoff CHAR(30), \
weapon_mag7 CHAR(30), weapon_elite CHAR(30), weapon_deagle CHAR(30), weapon_tec9 CHAR(30), \
weapon_fiveseven CHAR(30), weapon_cz75a CHAR(30), weapon_glock CHAR(30), weapon_usp_silencer CHAR(30), \
weapon_p250 CHAR(30), weapon_hkp2000 CHAR(30), weapon_bayonet CHAR(30), weapon_knife_gut CHAR(30), \
weapon_knife_flip CHAR(30), weapon_knife_m9_bayonet CHAR(30), weapon_knife_karambit CHAR(30), weapon_knife_tactical CHAR(30), \
weapon_knife_butterfly CHAR(30), weapon_c4 CHAR(30), weapon_knife_falchion CHAR(30), weapon_knife_push CHAR(30), \
weapon_revolver CHAR(30), weapon_knife_survival_bowie CHAR(30), weapon_knife CHAR(30));";
public Plugin myinfo =
{
name = "Weapon Tags",
author = "AfricanSpaceJesus",
description = "To set custom tags on weapons",
version = "1.0",
url = "http://steamcommunity.com/id/swagattack835/"
};
public void OnPluginStart()
{
HookEvent("item_equip", Event_Item_Equipped);
RegConsoleCmd("sm_settag", setTag);
if (SQL_CheckConfig("wtags"))
{
SQL_TConnect(SQLCallback_Connect, "wtags", _);
}
else
{
PrintToServer("<wtags> datbase cfg doesn't exist in databases.cfg");
}
}
public OnClientPostAdminCheck(int client)
{
map[client] = CreateTrie();
getTags(client);
}
public OnClientDisconnect(int client)
{
ClearTrie(map[client]);
}
public void getTags(int client)
{
//add tags for client to the stringmap
GetClientAuthId(client, AuthId_SteamID64, steamID, sizeof(steamID));
char query[128];
Format(query, sizeof(query),
"SELECT * FROM wtags WHERE SteamID= '%s';", steamID);
SQL_TQuery(g_db, SQLCallback_Tags, query, client, DBPrio_Normal);
}
public Action setTag(int client, int args)
{
//set name for weapon
GetCmdArg(1, newName, sizeof(newName));
int ent = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); //getting weapon ent index
SetEntPropString(ent, Prop_Send, "m_szCustomName", newName); //setting new name
//get weapon name and add to table in that weapons slot based upon the clients steamid
char wep[30];
GetClientAuthId(client, AuthId_SteamID64, steamID, sizeof(steamID));
GetClientWeapon(client, wep, sizeof(wep));
SetTrieString(map[client], wep, newName, true); //add to trie
char query[128];
Format(query, sizeof(query),
"SELECT * FROM wtags WHERE SteamID= '%s';", steamID);
SQL_TQuery(g_db, SQLCallback_Check, query, client, DBPrio_Normal);
return Plugin_Handled;
}
public Action Event_Item_Equipped(Event event, const char[] name, bool dontBroadcast)
{
char wep[128]; // actual default name
char wepName[128]; // name on weapon
int client = GetClientOfUserId(GetEventInt(event, "userid"));
GetClientWeapon(client, wep, sizeof(wep));
int ent = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); //getting weapon ent index
GetEntPropString(ent, Prop_Send, "m_szCustomName", wepName, sizeof(wepName));
if (StrEqual(wepName, wep))
{
bool x = GetTrieString(map[client], wep, newName, sizeof(newName));
if (x)
SetEntPropString(ent, Prop_Send, "m_szCustomName", newName); //setting new name
}
}
//no results needed
public void SQLCallback_Void(Handle owner, Handle db, const char[] error, any data)
{
if (db == null) // I should be checking to see if results is null, too.
{
LogError("Error (%i): %s", data, error);
}
}
//connecting callback
public void SQLCallback_Connect(Handle owner, Handle db, const char[] error, any data)
{
if (db == null)
{
SQL_TConnect(SQLCallback_Connect, "wtags");
}
else
{
g_db = owner;
SQL_TQuery(g_db, SQLCallback_Void, QUERY_CreateTable, DBPrio_Normal);
}
}
//for getting tags
public void SQLCallback_Tags(Handle owner, Handle results, const char[] error, int client)
{
if (results == null)
return;
char wepname[128];
char colname[128];
SQL_FetchRow(results);
int columns = SQL_GetFieldCount(results);
for (int i = 0; i <= columns; i++)
{
SQL_FetchString(results, i, wepname, sizeof(wepname));
SQL_FieldNumToName(results, i, colname, sizeof(colname));
if (!StrEqual(wepname, ""))
SetTrieString(map[client], colname, wepname, true);
}
}
// for adding correct info for the wep
public void SQLCallback_Check(Handle owner, Handle results, const char[] error, int client)
{
if (results == null)
return;
char info[256];
char query[256];
char wep[30];
GetClientWeapon(client, wep, sizeof(wep));
SQL_FetchRow(results);
SQL_FetchString(results, 0, info, sizeof(info));
if (StrEqual(info, ""))
{
Format(query, sizeof(query),
"INSERT INTO wtags(SteamID, '%s') VALUES ('%s', '%s');", wep, steamID, newName);
}
else
{
Format(query, sizeof(query),
"UPDATE wtags SET '%s'='%s' WHERE SteamID='%s';", wep, newName, steamID);
}
SQL_TQuery(g_db, SQLCallback_Void, query, DBPrio_Normal);
}