· 7 years ago · Oct 26, 2018, 11:12 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] > 0 )
133 {
134 zp_grenade_flare_set_aura( id, true );
135 zp_color( id, "%L", id, "MSG_FLARE_AURA_ON" );
136 }
137 else
138 {
139 zp_grenade_flare_set_aura( id, false );
140 zp_color( id, "%L", id, "MSG_FLARE_AURA_OFF" );
141 }
142
143 show_menu_gameplay_custom( id );
144 }
145 else
146 show_menu_gameplay_custom( id );
147 }
148
149 // Map lighting
150 case 1:
151 {
152 if( LibraryExists( LIBRARY_EFFECTS_LIGHTING, LibType_Library ) && ( g_szLightingOn[ 0 ] != '0' && ( g_szLightingOn[ 0 ] != g_szLightingOff[ 0 ] ) ) )
153 {
154 if( g_iLighting[id] > 0 )
155 {
156 zp_lighting_set( id, true );
157 zp_color( id, "%L", id, "MSG_LIGHTING_ON" );
158 }
159 else
160 {
161 zp_lighting_set( id, false );
162 zp_color( id, "%L", id, "MSG_LIGHTING_OFF" );
163 }
164
165 show_menu_gameplay_custom( id );
166 }
167 else
168 show_menu_gameplay_custom( id );
169 }
170
171 // Flashlight
172 case 2:
173 {
174 if( LibraryExists( LIBRARY_FLASHLIGHT, LibType_Library ) && g_iFlashlightCustom )
175 {
176 if( g_iFlashlight[id] > 0 )
177 {
178 zp_flashlight_set_aura( id, true );
179 zp_color( id, "%L", id, "MSG_FLASHLIGHT_AURA_ON" );
180 }
181 else
182 {
183 zp_flashlight_set_aura( id, false );
184 zp_color( id, "%L", id, "MSG_FLASHLIGHT_AURA_OFF" );
185 }
186
187 show_menu_gameplay_custom( id );
188 }
189 else
190 show_menu_gameplay_custom( id );
191 }
192
193 // Zombie Madness
194 case 3:
195 {
196 if( LibraryExists( LIBRARY_ITEM_ZOMBIE_MADNESS, LibType_Library ) && g_iMadnessAura )
197 {
198 if( g_iMadness[id] > 0 )
199 {
200 zp_item_zombie_madness_set_aura( id, true );
201 zp_color( id, "%L", id, "MSG_MADNESS_AURA_ON" );
202 }
203 else
204 {
205 zp_item_zombie_madness_set_aura( id, false );
206 zp_color( id, "%L", id, "MSG_MADNESS_AURA_OFF" );
207 }
208
209 show_menu_gameplay_custom( id );
210 }
211 else
212 show_menu_gameplay_custom( id );
213 }
214 }
215
216 SQL_InsertPlayer( id )
217 menu_destroy( menu_id );
218 return PLUGIN_HANDLED;
219}
220
221show_menu_gameplay_custom( id )
222{
223 static szMenuItem[ 128 ], szItemData[ 2 ];
224 formatex( szMenuItem, charsmax( szMenuItem ), "%s^n%L:\r", get_mode_name( ), id, "MENU_TITLE_GAMEPLAY_CUSTOM" );
225
226 new menu_id = menu_create( szMenuItem, "_menu_gameplay_custom" );
227
228 new const szMenuItemTranskey[ ][ ] =
229 {
230 "MSG_TOGGLE_FLARE_AURA",
231 "MSG_TOGGLE_MAP_LIGHTING",
232 "MSG_TOGGLE_FLASHLIGHT_AURA",
233 "MSG_TOGGLE_MADNESS_AURA"
234 };
235
236 for( new iLoop = 0; iLoop < sizeof( szMenuItemTranskey ); iLoop ++ )
237 {
238 switch( iLoop )
239 {
240 // Flare grenade aura
241 case 0:
242 {
243 if( LibraryExists( LIBRARY_GRENADE_FLARE, LibType_Library ) )
244 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iFlare[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
245 else
246 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
247 }
248
249 // Map lighting
250 case 1:
251 {
252 if( LibraryExists( LIBRARY_EFFECTS_LIGHTING, LibType_Library ) && ( g_szLightingOn[ 0 ] != '0' && ( g_szLightingOn[ 0 ] != g_szLightingOff[ 0 ] ) ) )
253 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iLighting[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
254 else
255 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
256 }
257
258 // Flashlight
259 case 2:
260 {
261 if( LibraryExists( LIBRARY_FLASHLIGHT, LibType_Library ) && g_iFlashlightCustom )
262 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iFlashlight[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
263 else
264 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
265 }
266
267 // Zombie Madness
268 case 3:
269 {
270 if( LibraryExists( LIBRARY_ITEM_ZOMBIE_MADNESS, LibType_Library ) && g_iMadnessAura )
271 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L \y[%L]", id, szMenuItemTranskey[ iLoop ], id, (g_iMadness[id] > 0) ? "MSG_ENABLED" : "MSG_DISABLED" );
272 else
273 formatex( szMenuItem, charsmax( szMenuItem ), "\d%L", id, szMenuItemTranskey[ iLoop ] );
274 }
275 }
276
277 szItemData[ 0 ] = iLoop;
278 szItemData[ 1 ] = 0;
279
280 menu_additem( menu_id, szMenuItem, szItemData );
281 }
282
283 if( menu_items( menu_id ) <= 0 )
284 {
285 menu_destroy( menu_id );
286 return;
287 }
288
289 // formatex( szMenuItem, charsmax( szMenuItem ), "%L", id, "MENU_BACK" );
290 // menu_setprop( menu_id, MPROP_BACKNAME, szMenuItem );
291
292 // formatex( szMenuItem, charsmax( szMenuItem ), "%L", id, "MENU_NEXT" );
293 // menu_setprop( menu_id, MPROP_NEXTNAME, szMenuItem );
294
295 formatex( szMenuItem, charsmax( szMenuItem ), "\r%L", id, "MENU_EXIT" );
296 menu_setprop( menu_id, MPROP_EXITNAME, szMenuItem );
297 menu_setprop(menu_id, MPROP_NUMBER_COLOR, "\y")
298
299 set_pdata_int( id, _Offset_CSMenu, 0, _Offset_Linux );
300 menu_display( id, menu_id );
301}
302
303get_mode_name( )
304{
305 static szModeName[ 32 ];
306 formatex( szModeName, charsmax( szModeName ), "Legend Killers" );
307
308 return szModeName;
309}
310
311public client_disconnected(id)
312{
313 if (g_bIsLoaded[id])
314 {
315 SQL_UpdatePlayer(id)
316 g_bIsLoaded[id] = false
317 }
318}
319
320public client_putinserver(id)
321{
322 g_bIsLoaded[id] = true
323 SQL_InsertPlayer(id)
324}
325
326public plugin_end()
327{
328 if (g_hSQLTuple)
329 SQL_FreeHandle(g_hSQLTuple)
330}
331
332public SQL_ThreadQuery_Select( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
333{
334 if( iFailState != TQUERY_SUCCESS )
335 {
336 set_fail_state( szError );
337 return;
338 }
339
340 static id, iUser;
341 id = szData[ 0 ];
342 iUser = szData[ 1 ];
343
344 if( get_user_userid( id ) != iUser )
345 return;
346
347 new bFlare[33], bLighting[33], bFlashlight[33], bMadness[33]
348
349 bFlare[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "flare_aura" ) );
350 bLighting[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "lighting_map" ) );
351 bFlashlight[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "flashlight" ) );
352 bMadness[ id ] = SQL_ReadResult( hQuery, SQL_FieldNameToNum( hQuery, "madness_aura" ) );
353
354 g_iFlare[id] = bFlare[ id ]
355 g_iLighting[id] = bLighting[ id ]
356 g_iFlashlight[id] = bFlashlight[ id ]
357 g_iMadness[id] = bMadness[ id ]
358
359 zp_grenade_flare_set_aura( id, (g_iFlare[ id ] < 1) ? false : true );
360 zp_lighting_set( id, (g_iLighting[ id ] < 1) ? false : true );
361 zp_flashlight_set_aura( id, (g_iFlashlight[ id ] < 1) ? false : true );
362 zp_item_zombie_madness_set_aura( id, (g_iMadness[ id ] < 1) ? false : true );
363
364 // Set that the data has been loaded
365 g_bIsLoaded[id] = true
366
367 SQL_FreeHandle( hQuery );
368}
369
370SQL_CreateDatabase( )
371{
372 g_hSQLTuple = SQL_MakeDbTuple( SQL_HOSTNAME, SQL_USERNAME, SQL_PASSWORD, SQL_DATABASE );
373
374 if( !g_hSQLTuple )
375 {
376 set_fail_state( "Could not make database tuple" );
377 SQL_FreeHandle( g_hSQLTuple );
378 return;
379 }
380
381 static szQuery[ 512 ];
382 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` ) );" );
383 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Empty", szQuery );
384}
385
386SQL_InsertPlayer( id )
387{
388 static szAuth[ 32 ];
389 get_user_authid( id, szAuth, charsmax( szAuth ) );
390
391// if( !is_steam_valid( szAuth ) )
392// return;
393
394 static szName[ 64 ];
395 get_user_name( id, szName, charsmax( szName ) );
396
397 replace_all( szName, charsmax( szName ), "'", "''" );
398
399 static szData[ 2 ], szQuery[ 256 ];
400 szData[ 0 ] = id;
401 szData[ 1 ] = get_user_userid( id );
402
403 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 );
404 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Insert", szQuery, szData, sizeof( szData ) );
405}
406
407SQL_UpdatePlayer( id )
408{
409 static szAuth[ 32 ];
410 get_user_authid( id, szAuth, charsmax( szAuth ) );
411
412// if( !is_steam_valid( szAuth ) )
413// return;
414
415 static szName[ 64 ], szQuery[ 512 ];
416 get_user_name( id, szName, charsmax( szName ) );
417
418 replace_all( szName, charsmax( szName ), "'", "''" );
419
420 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 );
421 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Empty", szQuery );
422}
423
424public SQL_ThreadQuery_Empty( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
425{
426 if( iFailState != TQUERY_SUCCESS )
427 {
428 set_fail_state( szError );
429 return;
430 }
431
432 SQL_FreeHandle( hQuery );
433}
434
435public SQL_ThreadQuery_Insert( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iData )
436{
437 if( iFailState != TQUERY_SUCCESS )
438 {
439 set_fail_state( szError );
440 return;
441 }
442
443 static id, iUser;
444 id = szData[ 0 ];
445 iUser = szData[ 1 ];
446
447 if( get_user_userid( id ) != iUser )
448 return;
449
450 static szAuth[ 32 ], szQuery[ 256 ];
451 get_user_authid( id, szAuth, charsmax( szAuth ) );
452
453 formatex( szQuery, charsmax( szQuery ), "SELECT `flare_aura`, `lighting_map`, `flashlight`, `madness_aura` FROM `cs_zp_stats` WHERE `auth_id` = '%s';", szAuth );
454 SQL_ThreadQuery( g_hSQLTuple, "SQL_ThreadQuery_Select", szQuery, szData, iData );
455
456 SQL_FreeHandle( hQuery );
457}