-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zp_ammo_save_file.sma
205 lines (178 loc) · 4.26 KB
/
zp_ammo_save_file.sma
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
#include <amxmodx>
#include <amxmisc>
#include <zombieplague>
new oldAmmo[33]
new saveBots
new saveType
new saveCust
new saveDest
new saveName
new saveMins
public plugin_init()
{
register_plugin("[ZP] Save Ammo To File", "1.4", "EfeDursun125")
saveBots = register_cvar("zp_ammo_save_bots", "1")
saveType = register_cvar("zp_ammo_save_type", "0")
saveCust = register_cvar("zp_ammo_save_folder_custom_enable", "0")
saveDest = register_cvar("zp_ammo_save_folder_custom", "C:\ExampleFolder\cstrike\addons\amxmodx\configs")
saveName = register_cvar("zp_ammo_save_folder_name", "AmmoSaveFILE")
saveMins = register_cvar("zp_ammo_save_minimum", "20")
}
public client_putinserver(id)
{
if (get_pcvar_num(saveBots) == 1 || !is_user_bot(id))
set_task(2.22222, "client_load_ammo", id)
}
public client_load_ammo(id)
{
if (!is_user_connected(id))
return
new playerName[255]
if (get_pcvar_num(saveType) == 1)
get_user_authid(id, playerName, charsmax(playerName))
else if (get_pcvar_num(saveType) == 2)
get_user_ip(id, playerName, charsmax(playerName))
else
get_user_name(id, playerName, charsmax(playerName))
if (strlen(playerName) < 3)
return
trim(playerName)
oldAmmo[id] = zp_get_user_ammo_packs(id)
// some tags can cause errors...
// define it here to save memory space
new const unsupportedTags[][] =
{
"|",
"<",
">",
"!",
"?",
"#", // not gives error but saving as ¼
"¼",
"*",
".",
",",
";",
":",
"ä",
"ü",
"ç",
"ö",
"ş",
"İ",
"ğ",
"'",
"&",
"%"
}
new i
for (i = 0; i < charsmax(unsupportedTags); i++)
replace_all(playerName, charsmax(playerName), unsupportedTags[i], "")
trim(playerName)
new path[255]
if (get_pcvar_num(saveCust) != 1)
get_configsdir(path, charsmax(path))
else
{
new name[96]
get_pcvar_string(saveDest, name, charsmax(name))
format(path, charsmax(path), "%s", name)
}
new folderName[64]
get_pcvar_string(saveName, folderName, charsmax(folderName))
format(path, charsmax(path), "%s/%s", path, folderName)
if (!dir_exists(path))
mkdir(path)
format(path, charsmax(path), "%s/%s.ammo", path, playerName)
new file = fopen(path, "rt+")
if (!file)
return
new text[255]
fgets(file, text, charsmax(text))
trim(text)
zp_set_user_ammo_packs(id, str_to_num(text))
fclose(file)
// again
oldAmmo[id] = zp_get_user_ammo_packs(id)
}
#if AMXX_VERSION_NUM > 182
public client_disconnected(id)
#else
public client_disconnect(id)
#endif
{
client_save_ammo(id)
}
public client_save_ammo(id)
{
if (get_pcvar_num(saveBots) != 1 && is_user_bot(id))
return
new ammoPacks = zp_get_user_ammo_packs(id)
new minLimit = get_pcvar_num(saveMins)
if (ammoPacks < minLimit && oldAmmo[id] < minLimit) // avoid create too many files
return
new playerName[255]
if (get_pcvar_num(saveType) == 1)
get_user_authid(id, playerName, charsmax(playerName))
else if (get_pcvar_num(saveType) == 2)
get_user_ip(id, playerName, charsmax(playerName))
else
get_user_name(id, playerName, charsmax(playerName))
if (strlen(playerName) < 3)
return
trim(playerName)
// some tags can cause errors...
// define it here to save memory space
new const unsupportedTags[][] =
{
"|",
"<",
">",
"!",
"?",
"#", // not gives error but saving as ¼
"¼",
"*",
".",
",",
";",
":",
"ä",
"ü",
"ç",
"ö",
"ş",
"İ",
"ğ",
"'",
"&",
"%"
}
new i
for (i = 0; i < charsmax(unsupportedTags); i++)
replace_all(playerName, charsmax(playerName), unsupportedTags[i], "")
trim(playerName)
new path[255]
if (get_pcvar_num(saveCust) != 1)
get_configsdir(path, charsmax(path))
else
{
new name[96]
get_pcvar_string(saveDest, name, charsmax(name))
format(path, charsmax(path), "%s", name)
}
new folderName[64]
get_pcvar_string(saveName, folderName, charsmax(folderName))
format(path, charsmax(path), "%s/%s", path, folderName)
if (!dir_exists(path))
mkdir(path)
format(path, charsmax(path), "%s/%s.ammo", path, playerName)
new value[256]
num_to_str(ammoPacks, value, charsmax(value))
trim(value)
new file = fopen(path, "wt+")
if (!file)
return
fprintf(file, value)
fclose(file)
}