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