· 6 years ago · Jan 16, 2020, 11:50 PM
1ublic plugin_init() {
2 register_plugin(PLUGIN, VERSION, AUTHOR)
3
4 RegisterHam(Ham_Spawn, "player", "Player_Spawn_Post", 1)
5
6 register_logevent("start_kola", 2, "1=Round_Start")
7 register_logevent("skoncene_kolo", 2, "1=Round_End")
8 register_event("DeathMsg","EventDeathMsg","a")
9
10 register_clcmd("jointeam 2", "cmd_jointeam")
11 register_clcmd("jointeam 02", "cmd_jointeam")
12 register_clcmd("jointeam 1", "cmd_jointeam")
13 register_clcmd("jointeam 01", "cmd_jointeam")
14 register_clcmd("jointeam 5", "cmd_jointeam")
15 register_clcmd("jointeam 6", "cmd_jointeam")
16 register_clcmd("jointeam", "cmd_jointeam")
17
18 set_task(1.0, "MySql_Init")
19
20}
21public MySql_Init()
22{
23 // we tell the API that this is the information we want to connect to,
24 // just not yet. basically it's like storing it in global variables
25 g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
26
27 // ok, we're ready to connect
28 new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
29 if(SqlConnection == Empty_Handle)
30
31 // stop the plugin with an error message
32 set_fail_state(g_Error)
33
34 new Handle:Queries
35
36 new Port[6];
37 get_cvar_string("port", Port, 5);
38
39 // we must now prepare some random queries
40 Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s_bank (sid varchar(32),`amount` BIGINT(20), `idhrace` BIGINT(20) PRIMARY KEY NOT NULL AUTO_INCREMENT)",Port)
41
42
43 if(!SQL_Execute(Queries))
44 {
45 //error = 1
46 // if there were any problems
47 SQL_QueryError(Queries,g_Error,charsmax(g_Error))
48 set_fail_state(g_Error)
49 }
50
51 // close the handle
52 SQL_FreeHandle(Queries)
53
54
55
56 // you free everything with SQL_FreeHandle
57 SQL_FreeHandle(SqlConnection)
58
59 return 1;
60}
61
62
63public cmd_jointeam(id)
64{
65 if (roundend)
66 {
67 if (cs_get_user_team(id) == CS_TEAM_SPECTATOR)
68 {
69 return PLUGIN_HANDLED
70 }
71 }
72}
73
74public client_putinserver(id)
75{
76 if (is_user_bot(id))
77 return PLUGIN_CONTINUE
78
79 money[id] = 25
80 cs_set_user_money(id, 0)
81 ochrana_proti_bugovani[id] = 0
82 ochrana_proti_bugovani3[id] = 0
83
84 Load_MySql2(id)
85 kontrola_teamu(id)
86
87 return PLUGIN_CONTINUE
88}
89
90public kontrola_teamu(id)
91{
92 if(!is_user_connected(id))
93 return PLUGIN_CONTINUE
94
95 if(is_user_bot(id))
96 return PLUGIN_CONTINUE
97
98 if (is_user_alive(id))
99 {
100 set_task (2.0, "kontrola_teamu", id)
101 }
102 else
103 {
104 set_task (0.1, "kontrola_teamu", id)
105
106 if (!ochrana_proti_bugovani[id])
107 return PLUGIN_CONTINUE
108
109 if (!ochrana_proti_bugovani3[id])
110 return PLUGIN_CONTINUE
111
112 cs_set_user_money(id, money[id])
113 }
114 return PLUGIN_CONTINUE
115}
116
117public client_disconnect(id)
118{
119 if (is_user_bot(id))
120 return PLUGIN_CONTINUE
121
122 Save_MySql(id)
123
124 ochrana_proti_bugovani[id] = 0
125 ochrana_proti_bugovani3[id] = 0
126
127 return PLUGIN_CONTINUE
128}
129
130public EventDeathMsg()
131{
132 new Victim = read_data(2)
133 if(is_user_connected(Victim))
134 {
135 if (ochrana_proti_bugovani[Victim])
136 {
137 money[Victim] = cs_get_user_money(Victim)
138 }
139 }
140
141}
142
143public start_kola()
144{
145 roundend = 0
146
147 new players[32], player, pnum;
148 get_players(players, pnum, "ac");
149
150 for(new i = 0; i < pnum; i++)
151 {
152 player = players[i];
153
154 if(is_user_bot(player))
155 return PLUGIN_CONTINUE
156
157 if(is_user_alive(player))
158 return PLUGIN_CONTINUE
159
160 if (!ochrana_proti_bugovani[player])
161 return PLUGIN_CONTINUE
162
163 cs_set_user_money(player, money[player])
164 }
165 return PLUGIN_CONTINUE
166}
167
168public skoncene_kolo()
169{
170 roundend = 1
171
172 new players[32], player, pnum;
173 get_players(players, pnum, "a");
174
175 for(new i = 0; i < pnum; i++)
176 {
177 player = players[i];
178
179 set_task (0.1, "uloz_penize", player)
180 }
181}
182
183public uloz_penize(id)
184{
185 if(is_user_bot(id))
186 return PLUGIN_CONTINUE
187
188 if (!is_user_alive(id))
189 return PLUGIN_CONTINUE
190
191 if (!ochrana_proti_bugovani[id])
192 return PLUGIN_CONTINUE
193
194 if (!ochrana_proti_bugovani3[id])
195 return PLUGIN_CONTINUE
196
197 money[id] = cs_get_user_money(id)
198
199 return PLUGIN_CONTINUE
200}
201
202public Player_Spawn_Post(id)
203{
204 if(!is_user_connected(id))
205 return PLUGIN_CONTINUE
206
207 if(is_user_bot(id))
208 return PLUGIN_CONTINUE
209
210 cs_set_user_money(id, money[id])
211
212 ochrana_proti_bugovani3[id] = 1
213
214 return PLUGIN_CONTINUE
215}
216
217public plugin_end()
218{
219 // free the tuple - note that this does not close the connection,
220 // since it wasn't connected in the first place
221 SQL_FreeHandle(g_SqlTuple)
222}
223
224
225public Load_MySql2(id)
226{
227 new szSteamId[32], szTemp[512]
228
229 get_user_authid(id, szSteamId, charsmax(szSteamId))
230
231 new Data[1]
232 Data[0] = id
233
234 new Port[6];
235 get_cvar_string("port", Port, 5);
236 //we will now select from the table `tutorial` where the steamid match
237 format(szTemp,charsmax(szTemp),"SELECT * FROM `%s_bank` WHERE (`%s_bank`.`sid` = '%s')" ,Port,Port,szSteamId)
238 SQL_ThreadQuery(g_SqlTuple,"register_client2",szTemp,Data,1)
239
240}
241
242public register_client2(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
243{
244 if(FailState == TQUERY_CONNECT_FAILED)
245 {
246 log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
247 }
248 else if(FailState == TQUERY_QUERY_FAILED)
249 {
250 log_amx("Load Query failed. [%d] %s", Errcode, Error)
251 }
252
253 new id
254 id = Data[0]
255
256 if(SQL_NumResults(Query) < 1)
257 {
258 //.if there are no results found
259
260 new szSteamId[32]
261 get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
262
263 if (!is_user_connected(id))
264 return PLUGIN_HANDLED
265
266 // if its still pending we can't do anything with it
267 if (equal(szSteamId,"ID_PENDING"))
268 return PLUGIN_HANDLED
269
270 if (equal(szSteamId,""))
271 return PLUGIN_HANDLED
272
273 if (is_user_bot(id))
274 return PLUGIN_HANDLED
275
276 new szTemp[512]
277
278 new Port[6];
279 get_cvar_string("port", Port, 5);
280 // now we will insturt the values into our table.
281 format(szTemp,charsmax(szTemp),"INSERT INTO `%s_bank` ( `sid` , `amount`, `idhrace` )VALUES ('%s','0','0');",Port,szSteamId)
282 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
283
284 money[id] = 0
285 cs_set_user_money(id, money[id])
286 ochrana_proti_bugovani[id] = 1
287 }
288 else
289 {
290 money[id] = SQL_ReadResult(Query, 1)
291 cs_set_user_money(id, money[id])
292 ochrana_proti_bugovani[id] = 1
293 }
294
295 return PLUGIN_HANDLED
296}
297
298public Save_MySql(id)
299{
300 if(is_user_bot(id))
301 return PLUGIN_CONTINUE
302
303 if (!ochrana_proti_bugovani[id])
304 return PLUGIN_CONTINUE
305
306 if (!ochrana_proti_bugovani3[id])
307 return PLUGIN_CONTINUE
308
309 if (ban_do_hry(id) == 1)
310 return PLUGIN_CONTINUE
311
312 money[id] = cs_get_user_money(id)
313
314 new szTemp[512]
315 new szSteamId[32]
316 get_user_authid(id, szSteamId, charsmax(szSteamId))
317
318 new Port[6];
319 get_cvar_string("port", Port, 5);
320 // Here we will update the user hes information in the database where the steamid matches.
321 format(szTemp,charsmax(szTemp),"UPDATE `%s_bank` SET `amount` = '%i' WHERE `%s_bank`.`sid` = '%s';",Port,money[id],Port,szSteamId)
322 SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
323
324 ochrana_proti_bugovani[id] = 0
325 ochrana_proti_bugovani3[id] = 0
326
327 return PLUGIN_CONTINUE
328}
329
330public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
331{
332 SQL_FreeHandle(Query)
333
334 return PLUGIN_HANDLED
335}