· 7 years ago · Oct 26, 2018, 11:06 PM
1/* ===========================================================================
2
3 ----------------------------
4 -*- [ZP] Gameplay Custom -*-
5 ----------------------------
6
7 (c) 2017 - Taurus
8 Websites: http://8bits-gaming.com | http://cssick.com
9
10=========================================================================== */
11
12#include < amxmodx >
13#include < sqlx >
14#include < fakemeta >
15#define LIBRARY_GRENADE_FLARE "zp50_grenade_flare"
16#include < zp50_grenade_flare >
17#define LIBRARY_EFFECTS_LIGHTING "zp_effects_lighting"
18#include < zp_effects_lighting >
19#define LIBRARY_FLASHLIGHT "zp_flashlight"
20#include < zp_flashlight >
21#define LIBRARY_ITEM_ZOMBIE_MADNESS "zp50_item_zombie_madness"
22#include < zp50_item_zombie_madness >
23#include <zp_color>
24
25//#pragma semicolon 1;
26
27const _Offset_Linux = 5;
28const _Offset_CSMenu = 205;
29
30#define SQL_HOSTNAME "127.0.0.1"
31#define SQL_USERNAME "lgk"
32#define SQL_PASSWORD "HIOUyZwctgfMu0cP"
33#define SQL_DATABASE "zp_aps"
34
35// Pointer CVars! :)
36
37new g_iFlashlightCustom;
38new g_iMadnessAura;
39new g_szLightingOn[ 2 ];
40new g_szLightingOff[ 2 ];
41new bool:g_bIsLoaded[33]
42new Handle:g_hSQLTuple;
43new g_iFlare[33], g_iLighting[33], g_iFlashlight[33], g_iMadness[33]
44
45public plugin_init( )
46{
47 register_plugin( "[ZP] Gameplay Custom", ZP_VERSION_STRING, "Taurus" );
48
49 register_clcmd( "say /gameplay_custom", "ClientCommand_GameplayCustom" );
50 register_clcmd( "say gameplay_custom", "ClientCommand_GameplayCustom" );
51 register_clcmd( "say /fps", "ClientCommand_GameplayCustom" );
52 register_clcmd( "say fps", "ClientCommand_GameplayCustom" );
53
54 SQL_CreateDatabase()
55}
56
57public plugin_cfg( )
58{
59 // Get cvars
60 bind_pcvar_num( get_cvar_pointer( "zp_flashlight_custom" ), g_iFlashlightCustom );
61 bind_pcvar_num( get_cvar_pointer( "zp_zombie_madness_aura" ), g_iMadnessAura );
62 bind_pcvar_string( get_cvar_pointer( "zp_lighting_on" ), g_szLightingOn, charsmax( g_szLightingOn ) );
63 bind_pcvar_string( get_cvar_pointer( "zp_lighting_off" ), g_szLightingOff, charsmax( g_szLightingOff ) );
64}
65
66public plugin_natives( )
67{
68 register_library( "zp_gameplay_custom" );
69
70 register_native( "zp_gameplay_custom_show_menu", "_gameplay_custom_show_menu" );
71 set_module_filter( "module_filter" );
72 set_native_filter( "native_filter" );
73}
74
75public ClientCommand_GameplayCustom( id )
76{
77 show_menu_gameplay_custom( id );
78}
79
80
81// We are going to integrate this stuff to the main menu! SO!!! :D
82public _gameplay_custom_show_menu( plugin_id, iParameter )
83{
84 new id = get_param( 1 );
85
86 if( !is_user_connected( id ) )
87 {
88 log_error( AMX_ERR_NATIVE, "[ZP] Player is not in-game (%d)", id );
89 return false;
90 }
91
92 show_menu_gameplay_custom( id );
93 return true;
94}
95
96public module_filter( const module[ ] )
97{
98 if( equal( module, LIBRARY_GRENADE_FLARE ) || equal( module, LIBRARY_EFFECTS_LIGHTING ) || equal( module, LIBRARY_FLASHLIGHT ) || equal( module, LIBRARY_ITEM_ZOMBIE_MADNESS ) )
99 return PLUGIN_HANDLED;
100
101 return PLUGIN_CONTINUE;
102}
103
104public native_filter( const native_name[ ], id, trap )
105{
106 if( !trap )
107 return PLUGIN_HANDLED;
108
109 return PLUGIN_CONTINUE;
110}
111
112public _menu_gameplay_custom( id, menu_id, iKey )
113{
114 if( iKey == MENU_EXIT )
115 {
116 menu_destroy( menu_id );
117 return PLUGIN_HANDLED;
118 }
119
120 static szItemData[ 2 ], iDummy, item_id;
121 menu_item_getinfo( menu_id, iKey, iDummy, szItemData, charsmax( szItemData ), _, _, iDummy );
122
123 item_id = szItemData[ 0 ];
124
125 switch( item_id )
126 {
127 // Flare grenade aura
128 case 0:
129 {
130 if( LibraryExists( LIBRARY_GRENADE_FLARE, LibType_Library ) )
131 {
132 if(g_iFlare[id] > 1 )
133 {
134 g_iFlare[id] = 1
135 zp_grenade_flare_set_aura( id, true );
136 zp_color( id, "%L", id, "MSG_FLARE_AURA_ON" );
137 }
138 else
139 {
140 g_iFlare[id] = 0
141 zp_grenade_flare_set_aura( id, false );
142 zp_color( id, "%L", id, "MSG_FLARE_AURA_OFF" );
143 }
144
145 show_menu_gameplay_custom( id );
146 }
147 else
148 show_menu_gameplay_custom( id );
149 }
150
151 // Map lighting
152 case 1:
153 {
154 if( LibraryExists( LIBRARY_EFFECTS_LIGHTING, LibType_Library ) && ( g_szLightingOn[ 0 ] != '0' && ( g_szLightingOn[ 0 ] != g_szLightingOff[ 0 ] ) ) )
155 {
156 if( g_iLighting[id] > 1 )
157 {
158 g_iLighting[id] = 1
159 zp_lighting_set( id, true );
160 zp_color( id, "%L", id, "MSG_LIGHTING_ON" );
161 }
162 else
163 {
164 g_iLighting[id] = 0
165 zp_lighting_set( id, false );
166 zp_color( id, "%L", id, "MSG_LIGHTING_OFF" );
167 }
168
169 show_menu_gameplay_custom( id );
170 }
171 else
172 show_menu_gameplay_custom( id );
173 }
174
175 // Flashlight
176 case 2:
177 {
178 if( LibraryExists( LIBRARY_FLASHLIGHT, LibType_Library ) && g_iFlashlightCustom )
179 {
180 if( g_iFlashlight[id] > 1 )
181 {
182 g_iFlashlight[id] = 1
183 zp_flashlight_set_aura( id, true );
184 zp_color( id, "%L", id, "MSG_FLASHLIGHT_AURA_ON" );
185 }
186 else
187 {
188 g_iFlashlight[id] = 0
189 zp_flashlight_set_aura( id, false );
190 zp_color( id, "%L", id, "MSG_FLASHLIGHT_AURA_OFF" );
191 }
192
193 show_menu_gameplay_custom( id );
194 }
195 else
196 show_menu_gameplay_custom( id );
197 }
198
199 // Zombie Madness
200 case 3:
201 {
202 if( LibraryExists( LIBRARY_ITEM_ZOMBIE_MADNESS, LibType_Library ) && g_iMadnessAura )
203 {
204 if( g_iMadness[id] > 1 )
205 {
206 g_iMadness[id] = 1
207 zp_item_zombie_madness_set_aura( id, true );
208 zp_color( id, "%L", id, "MSG_MADNESS_AURA_ON" );
209 }
210 else
211 {
212 g_iMadness[id] = 0
213 zp_item_zombie_madness_set_aura( id, false );
214 zp_color( id, "%L", id, "MSG_MADNESS_AURA_OFF" );
215 }
216
217 show_menu_gameplay_custom( id );
218 }
219 else
220 show_menu_gameplay_custom( id );
221 }
222 }
223
224 SQL_InsertPlayer( id )
225 menu_destroy( menu_id );
226 return PLUGIN_HANDLED;
227}
228
229show_menu_gameplay_custom( id )
230{
231 static szMenuItem[ 128 ], szItemData[ 2 ];
232 formatex( szMenuItem, charsmax( szMenuItem ), "%s^n%L:\r", get_mode_name( ), id, "MENU_TITLE_GAMEPLAY_CUSTOM" );
233
234 new menu_id = menu_create( szMenuItem, "_menu_gameplay_custom" );
235
236 new const szMenuItemTranskey[ ][ ] =
237 {
238 "MSG_TOGGLE_FLARE_AURA",
239 "MSG_TOGGLE_MAP_LIGHTING",
240 "MSG_TOGGLE_FLASHLIGHT_AURA",
241 "MSG_TOGGLE_MADNESS_AURA"
242 };
243
244 for( new iLoop = 0; iLoop < sizeof( szMenuItemTranskey ); iLoop ++ )
245 {
246 switch( iLoop )
247 {
248 // Flare grenade aura
249 case 0:
250 {
251 if( LibraryExists( LIBRARY_GRENADE_FLARE, LibType_Library ) )
252 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iFlare[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
253 else
254 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
255 }
256
257 // Map lighting
258 case 1:
259 {
260 if( LibraryExists( LIBRARY_EFFECTS_LIGHTING, LibType_Library ) && ( g_szLightingOn[ 0 ] != '0' && ( g_szLightingOn[ 0 ] != g_szLightingOff[ 0 ] ) ) )
261 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iLighting[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
262 else
263 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
264 }
265
266 // Flashlight
267 case 2:
268 {
269 if( LibraryExists( LIBRARY_FLASHLIGHT, LibType_Library ) && g_iFlashlightCustom )
270 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iFlashlight[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
271 else
272 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
273 }
274
275 // Zombie Madness
276 case 3:
277 {
278 if( LibraryExists( LIBRARY_ITEM_ZOMBIE_MADNESS, LibType_Library ) && g_iMadnessAura )
279 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iMadness[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
280 else
281 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
282 }
283 }
284
285 szItemData[ 0 ] = iLoop;
286 szItemData[ 1 ] = 0;
287
288 menu_additem( menu_id, szMenuItem, szItemData );
289 }
290
291 if( menu_items( menu_id ) <= 0 )
292 {
293 menu_destroy( menu_id );
294 return;
295 }
296
297 // formatex( szMenuItem, charsmax( szMenuItem ), "%L", id, "MENU_BACK" );
298 // menu_setprop( menu_id, MPROP_BACKNAME, szMenuItem );
299
300 // formatex( szMenuItem, charsmax( szMenuItem ), "%L", id, "MENU_NEXT" );
301 // menu_setprop( menu_id, MPROP_NEXTNAME, szMenuItem );
302
303 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L", id, "MENU_EXIT" );
304 menu_setprop( menu_id, MPROP_EXITNAME, szMenuItem );
305 menu_setprop(menu_id, MPROP_NUMBER_COLOR, "\y")
306
307 set_pdata_int( id, _Offset_CSMenu, 0, _Offset_Linux );
308 menu_display( id, menu_id );
309}
310
311get_mode_name( )
312{
313 static szModeName[ 32 ];
314 formatex( szModeName, charsmax( szModeName ), "Legend Killers" );
315
316 return szModeName;
317}
318
319public client_disconnected(id)
320{
321 if (g_bIsLoaded[id])
322 {
323 SQL_UpdatePlayer(id)
324 g_bIsLoaded[id] = false
325 }
326}
327
328public client_putinserver(id)
329{
330 g_bIsLoaded[id] = true
331 SQL_InsertPlayer(id)
332}
333
334public plugin_end()
335{
336 if (g_hSQLTuple)
337 SQL_FreeHandle(g_hSQLTuple)
338}
339
340public SQL_ThreadQuery_Select( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
341{
342 if( iFailState != TQUERY_SUCCESS )
343 {
344 set_fail_state( szError );
345 return;
346 }
347
348 static id, iUser;
349 id = szData[ 0 ];
350 iUser = szData[ 1 ];
351
352 if( get_user_userid( id ) != iUser )
353 return;
354
355 new bFlare[33], bLighting[33], bFlashlight[33], bMadness[33]
356
357 bFlare[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "flare_aura" ) );
358 bLighting[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "lighting_map" ) );
359 bFlashlight[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "flashlight" ) );
360 bMadness[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "madness_aura" ) );
361
362 g_iFlare[id] = bFlare[ id ]
363 g_iLighting[id] = bLighting[ id ]
364 g_iFlashlight[id] = bFlashlight[ id ]
365 g_iMadness[id] = bMadness[ id ]
366
367 zp_grenade_flare_set_aura( id, (g_iFlare[ id ] < 1) ? false : true );
368 zp_lighting_set( id, (g_iLighting[ id ] < 1) ? false : true );
369 zp_flashlight_set_aura( id, (g_iFlashlight[ id ] < 1) ? false : true );
370 zp_item_zombie_madness_set_aura( id, (g_iMadness[ id ] < 1) ? false : true );
371
372 // Set that the data has been loaded
373 g_bIsLoaded[id] = true
374
375 SQL_FreeHandle( hQuery );
376}
377
378SQL_CreateDatabase( )
379{
380 g_hSQLTuple = SQL_MakeDbTuple( SQL_HOSTNAME, SQL_USERNAME, SQL_PASSWORD, SQL_DATABASE );
381
382 if( !g_hSQLTuple )
383 {
384 set_fail_state( "Could not make database tuple" );
385 SQL_FreeHandle( g_hSQLTuple );
386 return;
387 }
388
389 static szQuery[ 512 ];
390 formatex( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS `cs_zp_stats` ( `auth_id` VARCHAR( 32 ), `player_name` VARCHAR( 32 ), `flare_aura` INT( 11 ) NOT NULL DEFAULT 0, `lighting_map` INT( 11 ) NOT NULL DEFAULT 0, `flashlight` INT( 11 ) NOT NULL DEFAULT 0, `madness_aura` INT( 11 ) NOT NULL DEFAULT 0, UNIQUE( `auth_id` ) );" );
391 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Empty", szQuery );
392}
393
394SQL_InsertPlayer( id )
395{
396 static szAuth[ 32 ];
397 get_user_authid( id, szAuth, charsmax( szAuth ) );
398
399// if( !is_steam_valid( szAuth ) )
400// return;
401
402 static szName[ 64 ];
403 get_user_name( id, szName, charsmax( szName ) );
404
405 replace_all( szName, charsmax( szName ), "'", "''" );
406
407 static szData[ 2 ], szQuery[ 256 ];
408 szData[ 0 ] = id;
409 szData[ 1 ] = get_user_userid( id );
410
411 formatex( szQuery, charsmax( szQuery ), "INSERT INTO `cs_zp_stats` ( `auth_id`, `player_name` ) VALUES ( '%s', '%s' ) ON DUPLICATE KEY UPDATE `player_name` = '%s';", szAuth, szName, szName );
412 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Insert", szQuery, szData, sizeof( szData ) );
413}
414
415SQL_UpdatePlayer( id )
416{
417 static szAuth[ 32 ];
418 get_user_authid( id, szAuth, charsmax( szAuth ) );
419
420// if( !is_steam_valid( szAuth ) )
421// return;
422
423 static szName[ 64 ], szQuery[ 512 ];
424 get_user_name( id, szName, charsmax( szName ) );
425
426 replace_all( szName, charsmax( szName ), "'", "''" );
427
428 formatex( szQuery, charsmax( szQuery ), "UPDATE `cs_zp_stats` SET `player_name` = '%s', `flare_aura` = %d, `lighting_map` = %d, `flashlight` = %d, `madness_aura` = %d WHERE `auth_id` = '%s';", szName, g_iFlare[id], g_iLighting[id], g_iFlashlight[id], g_iMadness[id], szAuth );
429 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Empty", szQuery );
430}
431
432public SQL_ThreadQuery_Empty( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
433{
434 if( iFailState != TQUERY_SUCCESS )
435 {
436 set_fail_state( szError );
437 return;
438 }
439
440 SQL_FreeHandle( hQuery );
441}
442
443public SQL_ThreadQuery_Insert( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
444{
445 if( iFailState != TQUERY_SUCCESS )
446 {
447 set_fail_state( szError );
448 return;
449 }
450
451 static id, iUser;
452 id = szData[ 0 ];
453 iUser = szData[ 1 ];
454
455 if( get_user_userid( id ) != iUser )
456 return;
457
458 static szAuth[ 32 ], szQuery[ 256 ];
459 get_user_authid( id, szAuth, charsmax( szAuth ) );
460
461 formatex( szQuery, charsmax( szQuery ), "SELECT `flare_aura`, `lighting_map`, `flashlight`, `madness_aura` FROM `cs_zp_stats` WHERE `auth_id` = '%s';", szAuth );
462 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Select", szQuery, szData, iData );
463
464 SQL_FreeHandle( hQuery );
465}