· 8 years ago · Dec 19, 2017, 02:56 PM
1/* SCXPM Version 17.0 by Silencer
2** Edited by Wrd, Version 17.31
3** Wrd thanks supergreg for his suggestions
4**
5** Edited by PythEch, Version 17.31.4
6**
7** Special Thanks to:
8**
9** VEN For heavily improving my Scripting-Skills. ;p
10** darkghost9999 For his great Ideas!
11**
12**
13** Thanks to:
14**
15** ThomasNguyen
16** `666
17** g3x
18** Hitman (Warchild)
19**
20*/
21
22// comment the #define USING_CS if you don't use cs
23// #define USING_CS
24
25#include <amxmodx>
26#include <amxmisc>
27#include <fakemeta>
28#include <fun>
29#include <sqlx>
30#include <bit>
31
32#if defined USING_CS
33#include <cstrike>
34#endif
35
36#define VERSION "17.31.4"
37#define LASTUPDATE "26 March 2012"
38
39/*
40* The table create code is too long to compile so table have to be created manually
41
42CREATE TABLE IF NOT EXISTS `scxpm_stats` (
43 `id` int(11) NOT NULL auto_increment,
44 `uniqueid` varchar(50) NOT NULL,
45 `authid` varchar(24) NOT NULL,
46 `ip` varchar(24) NOT NULL,
47 `nick` varchar(50) NOT NULL,
48 `xp` bigint(20) NOT NULL default '0',
49 `playerlevel` int(11) NOT NULL default '0',
50 `skillpoints` int(11) NOT NULL default '0',
51 `medals` tinyint(4) NOT NULL default '4',
52 `health` int(11) NOT NULL default '0',
53 `armor` int(11) NOT NULL default '0',
54 `rhealth` int(11) NOT NULL default '0',
55 `rarmor` int(11) NOT NULL default '0',
56 `rammo` int(11) NOT NULL default '0',
57 `gravity` int(11) NOT NULL default '0',
58 `speed` int(11) NOT NULL default '0',
59 `dist` int(11) NOT NULL default '0',
60 `dodge` int(11) NOT NULL default '0',
61 `lastUpdated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
62 PRIMARY KEY (`id`),
63 UNIQUE KEY `uniqueid` (`uniqueid`)
64) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
65
66*/
67
68
69
70/*
71* Future Features
72* if you want new features ask it on: http://forums.alliedmods.net/showthread.php?t=44168
73* ------------------
74* - pruning database with the `lastUpdated` field
75* - cuicide penalty
76*
77*/
78
79/*
80* Changelog
81*
82* Version: 17.31.4
83* Date: 26 March 2012
84* ------------------------
85* Added an optional ability to limit maximum level that players can gain per map. This will prevent players to use bugs to boost their XP (e.g of4a4.bsp)
86* Added cvars 'scxpm_maxlevelup_enabled', 'scxpm_maxlevelup' and 'scxpm_maxlevelup_limit'
87* ------------------------
88*
89* Version: 17.31.3
90* Date: 4 October 2011
91* ------------------------
92* Bug Teampower give no hp and ap to Teammates
93* Fixed Remove wrong code ({// Do nothing} else ) to fix teampower
94* Edited Teampower Speed from 2.0 to 1.0
95* Edited Teampower +60 hp and ap too +100 hp and ap
96* Edited Teampower luck from 4200 to 2000
97* Edited Teampower luck by 40 skill points from 0,1000 to 1000,1000
98* Edited Block Attack luck from 0,185 to 80,185 to fix it but dont know if it works
99* Edited Medikit Heal speed from slow to fast
100* Edited scxpm_hud_channel" from 3 to 0
101* ------------------------
102*
103* Version: 17.31.2
104* Date: 2 October 2011
105* ------------------------
106* Fixed Changed new starthealth; and new startarmor; in new starthealth=100; and new startarmor=100;to fix the bug by join the game hp still by 100 hp.
107* Fixed scxpm_regen and I fixed the backward hp problem when you have over 100 hp
108* Edited armor regeneration
109* Edited scxpm_randomammo
110* Edited give stuff (ammo regeneration ,ammo packs)
111* Edited scxpm_xpgain from 1.0 to 10.0
112* Edited scxpm_save_frequent from 0 to 1
113* ------------------------
114*
115* Version: 17.31.1
116* Date: 11 February 2011
117* ------------------------
118* - Changed boolean structures(loaddata, has_godmode, etc) - now it's
119* not 33 sized bool arrays, but single ints
120* - Hooking say event instead of concmd every say command
121* - Restructured rank data, ranks are now in a variable, only a rank's id is stored
122* - Changed cvars into pcvars
123* - Removed some stuff:
124* - #include <core> - this is already included in amxmodx
125* - load_error array - never gets a true value, so it is unused
126* ------------------------
127*
128* Version: 17.31
129* Date: 21 March 2010
130* ------------------------
131* - Fixed movement bug
132* - Fixed not receiving xp for kill
133* ------------------------
134*
135* Version: 17.30
136* Date: 08 Februari 2010
137* ------------------------
138* - Added Incremental skill upgrade
139* ------------------------
140*
141* Version: 17.29
142* Date: 07 Februari 2010
143* ------------------------
144* - Fixed: set loaddata to true when loading from file
145* ------------------------
146*
147* Version: 17.28
148* Date: 02 Februari 2010
149* ------------------------
150* - Fixed: don't set the xp back to 0
151* ------------------------
152*
153* Version: 17.27
154* Date: 20 December 2009
155* ------------------------
156* - Added: scxpm_maxlevel cvar for capping the max level
157* - Fixed: xp problem when #define USING_CS is commented
158* ------------------------
159*
160* Version: 17.26
161* Date: 15 November 2009
162* ------------------------
163* - Fixed: The inefficient way of calculating the xp does not work for sven coop
164* ------------------------
165*
166* Version: 17.25
167* Date: 9 November 2009
168* ------------------------
169* - Changed: amx_scxpm_gamename to scxpm_gamename
170* - Changed: amx_scxpm_save to scxpm_save
171* - Changed: amx_scxpm_savestyle to scxpm_savestyle
172* - Changed: amx_scxpm_debug to scxpm_debug
173* - Changed: scxpm_xpgain to scxpm_xpgain
174* ------------------------
175*
176* Version: 17.24
177* Date: 8 November 2009
178* ------------------------
179* - Removed: Inefficient way of calculating the xp
180* - Added: Event triggered way of calculating the xp
181* ------------------------
182*
183* Version: 17.23
184* Date: 7 November 2009
185* ------------------------
186* - Added: lastupdate field in the database for later use
187* - Added: cvar scxpm_minplaytime: setting in seconds the minimum playing time before stats are saved
188* - Fixed: empty uniqueid added to database
189* - Fixed: empty ip or nickname added to the database
190* ------------------------
191*
192* Version: 17.22
193* Date: 2 November 2009
194* ------------------------
195* - Changed database structure and queries for better query handling
196* - Added an check so that data is not loaded twice because of retreiving the steamid
197* ------------------------
198*
199* Update Note from version 17.21 to 17.22
200* execute the following query:
201* - ALTER TABLE `scxpm_stats` ADD `uniqueid` VARCHAR( 50 ) NOT NULL AFTER `id` ;
202* - UPDATE scxpm_stats SET uniqueid = <unique>;
203* replace <unique> with the following possibilities according to your situation
204* - authid
205* - ip
206* - nick
207* - ALTER TABLE `scxpm_stats` ADD UNIQUE (`uniqueid`)
208*
209* Version: 17.21
210* Date: 28 Oktober 2009
211* ------------------------
212* - Fixed: xp lower than 0 won't be saved
213* ------------------------
214*
215* Version: 17.20
216* Date: 11 Oktober 2009
217* ------------------------
218* - Fixed: Possible entries inserted in the database with no auth id when the savestyle is on authid
219* - Fixed: Players could only gain one level and the rest would not be saved
220* - Fixed: directly go to the correct level when alot of xp is given, instead of going through every level
221* - Added: More debug feedback
222* ------------------------
223*
224* Version: 17.19
225* Date: 8 Oktober 2009
226* ------------------------
227* - Fixed: Added the loaddata check on save, no stats will be saved if no data is loaded
228* ------------------------
229*
230* Version: 17.18
231* Date: 15 September 2009
232* ------------------------
233* - Fixed: Threaed SQL (There were incredible horrible bugs)
234* ------------------------
235*
236* Version: 17.17
237* Date: 13 September 2009
238* ------------------------
239* - Added: Threaded sql
240* ------------------------
241*
242* Version: 17.16
243* Date: 31 August 2009
244* ------------------------
245* - Fixed: Showing the players info and other players info
246* ------------------------
247*
248* Version: 17.15
249* Date: 28 August 2009
250* ------------------------
251* - Added create sql script info
252* - Fixed the savexp_all sql part
253* - Fixed health issue
254* ------------------------
255*
256*
257* Version: 17.14
258* Date: 2 August 2009
259* ------------------------
260* - Added changes made by supergreg
261* = Changed the database cvars
262* Now another database can be used instead of the default one
263* = Fixed: cs weapons offset
264* = Generally small but useful changes
265* = Added a define for cs, if you don't use this pluging for cs please comment the define
266* ------------------------
267*
268* Version: 17.13
269* Date: 30 Juli 2009
270* ------------------------
271* - Fixed repeated saving stats; scxpm_save_frequent fixed
272* ------------------------
273*
274* Version: 17.12
275* Date: 30 Juli 2009
276* -------------------------
277* - Try to fix the health bug when spawning
278* - Added this changelog
279* -------------------------
280*/
281
282
283/*
284** Queries
285*/
286#define QUERY_SELECT_SKILLS "SELECT `xp`, `playerlevel`, `skillpoints`, `medals`, `health`, `armor`, `rhealth`, `rarmor`, `rammo`, `gravity`, `speed`, `dist`, `dodge` FROM `%s` WHERE %s"
287#define QUERY_UPDATE_SKILLS "INSERT INTO %s (uniqueid) VALUES ('%s') ON DUPLICATE KEY UPDATE authid ='%s',nick='%s',ip='%s',xp='%d',playerlevel='%d',skillpoints='%d',medals='%d',health='%d',armor='%d',rhealth='%d',rarmor='%d',rammo='%d',gravity='%d',speed='%d',dist='%d',dodge='%d'"
288
289// added for mysql support
290new Handle:dbc;
291new g_Cache[1024];
292new sql_table[64];
293new loaddata; // check so data is only saved when data is loaded
294new bool:plugin_ended;
295
296#if defined USING_CS
297 // cs specific
298 new ammotype[7][15]; // types of ammo you can receive through random ammo (from regeneration)
299#endif
300
301new const ranks[23][] = {
302 "Frightened Civilian",
303 "Civilian",
304 "Fighter",
305 "Private Third Class",
306 "Private Second Class",
307 "Private First Class",
308 "Free Agent",
309 "Professional Free Agent",
310 "Professional Force Member",
311 "Professional Force Leader",
312 "Special Force Member",
313 "Special Force Leader",
314 "United Forces Member",
315 "United Forces Leader",
316 "Hidden Operations Member",
317 "Hidden Operations Scheduler",
318 "Hidden Operations Leader",
319 "General",
320 "Top 30 of most famous Leaders",
321 "Top 15 of most famous Leaders",
322 "Highest Force Member",
323 "Highest Force Leader",
324 "Loading..."
325}
326
327new xp[33];
328new neededxp[33];
329new playerlevel[33];
330new rank[33];
331new skillpoints[33];
332new medals[35];
333new health[33];
334new armor[33];
335new rhealth[33];
336new rarmor[33];
337new rammo[33];
338new gravity[33];
339new speed[33];
340new dist[33];
341new dodge[33];
342new rarmorwait[33];
343new rhealthwait[33];
344new ammowait[33];
345new starthealth=100;
346new startarmor=100;
347new lastfrags[33];
348new lastDeadflag[33];
349new skillIncrement[33];
350#if !defined USING_CS
351 new bool:onecount;
352#endif
353new has_godmode;
354
355new pcvar_gamename, pcvar_save, pcvar_debug, pcvar_savestyle, pcvar_minplaytime;
356new pcvar_sql_host, pcvar_sql_user, pcvar_sql_pass, pcvar_sql_db, pcvar_sql_table;
357new pcvar_hud_channel, pcvar_save_frequent, pcvar_xpgain, pcvar_maxlevel;
358
359new firstLvl[33],pcvar_maxlevelup_enabled,pcvar_maxlevelup,pcvar_maxlevelup_limit;
360
361public plugin_init()
362{
363 log_amx( "[SCXPM] Loading Sven Coop XP Mod version %s", VERSION );
364 register_plugin("SCXPM",VERSION,"Silencer");
365 register_menucmd(register_menuid("Select Skill"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),"SCXPMSkillChoice");
366 register_menucmd(register_menuid("Select Increment"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5),"SCXPMIncrementChoice");
367 register_forward(FM_GetGameDescription,"scxpm_gn");
368 register_forward(FM_PlayerPreThink,"scxpm_prethink");
369 register_concmd("setlvl","scxpm_setlvl",ADMIN_IMMUNITY,"Playername Value - Will set Players Level");
370 register_concmd("addmedal","scxpm_addmedal",ADMIN_IMMUNITY,"Playername - Will award Player with a Medal");
371 register_concmd("removemedal","scxpm_removemedal",ADMIN_IMMUNITY,"Playername - Will remove a Medal of a Player");
372 register_concmd("addxp","scxpm_addxp",ADMIN_IMMUNITY,"Playername Value - Will add xp to Players xp");
373 register_concmd("removexp","scxpm_removexp",ADMIN_IMMUNITY,"Playername Value - Will remove xp from Players xp");
374
375 // for debug reasons
376 // register_concmd("say savedata","scxpm_savexp_all_mysql",ADMIN_IMMUNITY,"- Will save your SCXPM data");
377
378 register_concmd("godmode","scxpm_godmode",ADMIN_IMMUNITY,"Playername - Toggle Players God Mode On or Off.");
379 register_concmd("noclipmode","scxpm_noclipmode",ADMIN_IMMUNITY,"Playername - Toggle Players noclip Mode On or Off.");
380
381 register_clcmd("say", "say_hook");
382 register_clcmd("say_team", "say_hook");
383
384 register_concmd("selectskills","SCXPMSkill",0,"- Opens the Skill Choice Menu, if you have Skillpoints available");
385 register_concmd("resetskills","scxpm_reset",1,"- Will reset your Skills so you can rechoose them");
386 register_concmd("playerskills","scxpm_others",0,"- Will print Other Players Stats");
387 register_concmd("skillsinfo","scxpm_info",0,"- Will print Information about all Skills");
388 register_concmd("scxpminfo","scxpm_version",0,"- Will print Information about SCXPM");
389
390 // there is no need to change the name
391 pcvar_gamename = register_cvar("scxpm_gamename","1");
392
393 // set a load protecting flag
394 for( new i = 0; i<33 ;i++ )
395 {
396 clear_player_flag(loaddata, i);
397 }
398 plugin_ended = false;
399
400 /* If enabled, it will try to prevent players using bugs to boost their XP in maps like of4a4
401 ** 0 = Disabled
402 ** 1 = Enabled
403 */
404 pcvar_maxlevelup_enabled = register_cvar("scxpm_maxlevelup_enabled", "1");
405
406 // Maximum level can be gained per map (Default:20)
407 pcvar_maxlevelup = register_cvar("scxpm_maxlevelup", "20");
408
409 // Players will be able to level up without limitations if they're under the specified level (Default:100)
410 pcvar_maxlevelup_limit = register_cvar("scxpm_maxlevelup_limit", "80");
411
412 /*
413 ** set the save style
414 ** 0 = not saved
415 ** 1 = save in a file
416 ** 2 = save in mysql
417 */
418 pcvar_save = register_cvar("scxpm_save","1");
419
420
421 // for debug information in the logfile set this to 1
422 pcvar_debug = register_cvar("scxpm_debug","0");
423
424 /*
425 ** what to save on
426 ** 0 = id
427 ** 1 = ip address
428 ** 2 = nickname
429 */
430 //register_cvar("scxpm_savestyle", "0")
431
432 // if sv_lan is on save stuff on the nickname
433 if (get_cvar_num("sv_lan") == 1)
434 {
435 pcvar_savestyle = register_cvar("scxpm_savestyle", "2");
436 }
437 else
438 {
439 pcvar_savestyle = register_cvar("scxpm_savestyle", "0");
440 }
441
442 // minimum play time before saving data in seconds, 0 = always save
443 pcvar_minplaytime = register_cvar("scxpm_minplaytime", "0");
444
445 /*
446 ** mysql
447 */
448 pcvar_sql_host = register_cvar("scxpm_sql_host", "127.0.0.1");
449 pcvar_sql_user = register_cvar("scxpm_sql_user", "NOTSET");
450 pcvar_sql_pass = register_cvar("scxpm_sql_pass", "NOTSET");
451 pcvar_sql_db = register_cvar("scxpm_sql_db", "NOTSET");
452 pcvar_sql_table = register_cvar("scxpm_sql_table", "scxpm_stats");
453
454 new configsDir[64];
455 get_configsdir(configsDir, 63);
456 server_cmd("exec %s/sql.cfg", configsDir);
457
458#if defined USING_CS
459 ammotype[0] = "ammo_9mm"; // glock18, elite, mp5navy, tmp
460 ammotype[1] = "ammo_50ae"; // deagle
461 ammotype[2] = "ammo_buckshot"; // m3, xm1014
462 ammotype[3] = "ammo_57mm"; // p90, fiveseven
463 ammotype[4] = "ammo_45acp"; // usp, mac10, ump45
464 ammotype[5] = "ammo_556nato"; // famas, sg552, m4a1, aug, sg550
465 ammotype[6] = "ammo_9mm"; // glock18, elite, mp5navy, tmp
466#endif
467
468 // hud message fix if it conflicts with other plugins
469 pcvar_hud_channel = register_cvar("scxpm_hud_channel", "0");
470
471 // to enable frequent savestyle
472 // if set to 1 players data will be saved as soon it gains xp
473 pcvar_save_frequent = register_cvar("scxpm_save_frequent", "1");
474
475 pcvar_xpgain = register_cvar( "scxpm_xpgain", "3.0" );
476
477 // possibility to cap the max level
478 pcvar_maxlevel = register_cvar( "scxpm_maxlevel", "1800" );
479
480 set_task( 0.5, "scxpm_sdac", 0, "", 0, "b" );
481 register_logevent("roundstart", 2, "0=World triggered", "1=Round_Start");
482 #if defined USING_CS
483 register_event("DeathMsg","death","a");
484 #endif
485 set_task( 0.1, "sql_init" );
486 register_message(get_user_msgid("Health"), "message_Health");
487}
488
489public plugin_end() {
490 if (get_pcvar_num( pcvar_debug ) == 1 )
491 {
492 log_amx( "[SCXPM DEBUG] plugin_end" );
493 }
494
495 if ( dbc ) {
496 SQL_FreeHandle( dbc );
497 }
498
499 plugin_ended = true;
500
501 return PLUGIN_HANDLED;
502}
503
504// init the sql, check if the sql table exist
505public sql_init() {
506 if ( get_pcvar_num( pcvar_save ) >= 2 && !dbc)
507 {
508 if (get_pcvar_num( pcvar_debug ) == 1 )
509 {
510 log_amx( "[SCXPM DEBUG] Begin Init the sql" );
511 }
512
513 new host[64], username[64], password[64], dbname[64];
514
515 //no pcvar, only called once at plugin start
516 get_pcvar_string( pcvar_sql_host, host, 64 );
517 get_pcvar_string( pcvar_sql_user, username, 64 );
518 get_pcvar_string( pcvar_sql_pass, password, 64 );
519 get_pcvar_string( pcvar_sql_db, dbname, 64 );
520
521 get_pcvar_string( pcvar_sql_table, sql_table, 64 );
522
523 SQL_SetAffinity( "mysql" );
524 dbc = SQL_MakeDbTuple( host, username, password, dbname );
525
526 // check if the table exist
527 formatex( g_Cache, 1023, "show tables like '%s'", sql_table );
528 SQL_ThreadQuery( dbc, "ShowTableHandle", g_Cache);
529
530 if (get_pcvar_num( pcvar_debug ) == 1 )
531 {
532 log_amx( "[SCXPM DEBUG] End Init the sql" );
533 }
534 }
535}
536
537public message_Health(msgid, dest, id) {
538 if(!is_user_alive(id)) {
539 return PLUGIN_CONTINUE;
540 }
541
542 new hp = get_msg_arg_int(1);
543
544 if(hp > 255 && (hp % 256) == 0) {
545 set_msg_arg_int(1, ARG_BYTE, ++hp);
546 }
547
548 return PLUGIN_CONTINUE;
549}
550
551// give xp to player
552public scxpm_addxp( id, level, cid ) {
553 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 3 ) )
554 {
555 return PLUGIN_HANDLED;
556 }
557
558 new targetarg[32];
559 read_argv(1, targetarg, 31);
560 new target = cmd_target( id, targetarg, 11 );
561 if ( !target )
562 {
563 return PLUGIN_HANDLED;
564 }
565 new xparg[32];
566 read_argv( 2, xparg, 31 );
567 new addxp = str_to_num( xparg );
568 new name[32];
569 get_user_name( target, name, 31 );
570
571
572
573 if ( addxp + xp[target] > scxpm_calc_xp ( get_pcvar_num( pcvar_maxlevel ) ) )
574 {
575 addxp = scxpm_calc_xp ( get_pcvar_num( pcvar_maxlevel ) ) - xp[target];
576 }
577
578 // should be impossible but why not
579 if ( addxp + xp[target] < 0 )
580 {
581 xp[target] = 0;
582 }
583
584 // now add the xp to the current xp
585 xp[target] += addxp;
586
587 // now save the stats
588 SavePlayerData( target );
589
590 // for logging purposes
591 new adminname[32];
592 new adminid[32];
593 get_user_name( id, adminname, 31 );
594 get_user_authid(id, adminid, 31 );
595 log_amx("[SCXPM] %s %s gave %s %i xp ", adminname, adminid, name, addxp );
596
597 console_print( id, "%s gained %i xp. New xp: %i", name, addxp, xp[target] );
598
599 return PLUGIN_HANDLED;
600}
601
602// remove xp from player
603public scxpm_removexp( id, level, cid ) {
604 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 3 ) )
605 {
606 return PLUGIN_HANDLED;
607 }
608
609 new targetarg[32];
610 read_argv(1, targetarg, 31);
611 new target = cmd_target( id, targetarg, 11 );
612 if( !target )
613 {
614 return PLUGIN_HANDLED;
615 }
616 new xparg[32];
617 read_argv( 2, xparg, 31 );
618 new removexp = str_to_num( xparg );
619 new name[32];
620 get_user_name( target, name, 31 );
621
622 // if players xp minus remove xp is higher than the max xp
623 if ( xp[target] - removexp > 11500000 )
624 {
625 removexp = xp[target] - 11500000;
626 }
627
628 // now remove the xp from the current xp
629 xp[target] -= removexp;
630
631 if ( xp[target] < 0 )
632 {
633 xp[target] = 0;
634 }
635
636 // level needs to be recalculated
637 playerlevel[target] = scxpm_calc_lvl ( xp[target] );
638
639 //if there are too many skills some should be removed
640 while ( playerlevel[target] < health[target] + armor[target] + rhealth[target] + rarmor[target] + rammo[target] + gravity[target] + speed[target] + dist[target] + dodge[target] + skillpoints[target] )
641 {
642 if ( health[target] > 0 )
643 {
644 health[target]--;
645 }
646 else if ( armor[target] > 0 )
647 {
648 armor[target]--;
649 }
650 else if ( rhealth[target] > 0 )
651 {
652 rhealth[target]--;
653 }
654 else if ( rarmor[target] > 0 )
655 {
656 rarmor[target]--;
657 }
658 else if ( rammo[target] > 0 )
659 {
660 rammo[target]--;
661 }
662 else if ( gravity[target] > 0 )
663 {
664 gravity[target]--;
665 }
666 else if ( speed[target] > 0 )
667 {
668 speed[target]--;
669 }
670 else if ( dist[target] > 0 )
671 {
672 dist[target]--;
673 }
674 else if ( dodge[target] > 0 )
675 {
676 dodge[target]--;
677 }
678 }
679
680 // recalculate needed xp
681 scxpm_calcneedxp ( target );
682
683 // now save the stats
684 SavePlayerData( target );
685
686 // for logging purposes
687 new adminname[32];
688 new adminid[32];
689 get_user_name( id, adminname, 31 );
690 get_user_authid(id, adminid, 31 );
691 log_amx("[SCXPM] %s %s removed %s %i xp ", adminname, adminid, name, removexp );
692
693 console_print( id, "%s lost %i xp. New xp: %i", name, removexp, xp[target] );
694 return PLUGIN_HANDLED
695}
696
697// set gamename
698public scxpm_gn() {
699 if( get_pcvar_num(pcvar_gamename) >= 1 )
700 {
701 new g[32];
702 format( g, 31, "SCXPM %s", VERSION );
703 forward_return( FMV_STRING, g);
704 return FMRES_SUPERCEDE;
705 }
706 return PLUGIN_HANDLED;
707}
708
709// set players level
710public scxpm_setlvl( id, level, cid ) {
711 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 3 ) )
712 {
713 return PLUGIN_HANDLED;
714 }
715 new targetarg[32];
716 read_argv(1, targetarg, 31);
717 new target = cmd_target( id, targetarg, 11 );
718 if( !target )
719 {
720 return PLUGIN_HANDLED;
721 }
722 new lvlarg[32];
723 read_argv( 2, lvlarg, 31 );
724 new nowlvl = str_to_num( lvlarg );
725 new name[32];
726 get_user_name( target, name, 31 );
727 if( nowlvl >= get_pcvar_num( pcvar_maxlevel ) )
728 {
729 nowlvl = get_pcvar_num( pcvar_maxlevel );
730 }
731 if ( nowlvl < 0 )
732 {
733 nowlvl = 0;
734 }
735 if ( nowlvl == playerlevel[target] )
736 {
737 if ( target == id )
738 {
739 console_print( id, "[SCXPM] Your Level is already %i.", nowlvl );
740 }
741 else
742 {
743 console_print(id, "[SCXPM] %s's Level is already %i.", name, nowlvl );
744 }
745 return PLUGIN_HANDLED
746 }
747 else
748 {
749 if ( nowlvl >= 1800 )
750 {
751 nowlvl = 1800;
752 xp[target] = 11500000;
753 }
754 else
755 {
756 if ( nowlvl <= 0 )
757 {
758 nowlvl = 0;
759 xp[target] = 0;
760 }
761 else
762 {
763 new helpvar = nowlvl - 1;
764 new Float:m70b = float( helpvar ) * 70.0;
765 new Float:mselfm3dot2b = float( helpvar ) * float(helpvar) * 3.5;
766 xp[target] = floatround( m70b + mselfm3dot2b + 30.0);
767 }
768 }
769 }
770 if ( playerlevel[target] > nowlvl )
771 {
772 playerlevel[target] = nowlvl;
773 if (target == id )
774 {
775 console_print( id, "[SCXPM] You lowered your Level to %i. Calling Skill Reset!", playerlevel[target] );
776 }
777 else
778 {
779 console_print( id, "[SCXPM] You lowered %s's Level to %i.", name, playerlevel[target] );
780 }
781 if ( nowlvl > 0 )
782 {
783 if ( target != id )
784 {
785 client_print( target, print_chat, "[SCXPM] An Admin has lowered your Level to %i! Calling Skill Reset!", playerlevel[target] );
786 }
787 scxpm_reset( target );
788 }
789 else
790 {
791 if ( target != id )
792 {
793 client_print( target, print_chat, "[SCXPM] An Admin has lowered your Level to 0! You lost all Skills!" );
794 }
795 health[target] = 0;
796 armor[target] = 0;
797 rhealth[target] = 0;
798 rarmor[target] = 0;
799 rammo[target] = 0;
800 gravity[target] = 0;
801 speed[target] = 0;
802 dist[target] = 0;
803 dodge[target] = 0;
804 skillpoints[target] = 0;
805 if ( get_user_health( target ) > starthealth )
806 {
807 set_user_health( target, starthealth );
808 }
809 if (get_user_armor( target ) > startarmor )
810 {
811 set_user_armor( target, startarmor );
812 }
813 set_user_gravity( target, 1.0 );
814 }
815 }
816 else
817 {
818 if ( nowlvl < 1800 )
819 {
820 skillpoints[target] = skillpoints[target] + nowlvl - playerlevel[target];
821 playerlevel[target] = nowlvl;
822 if ( target == id )
823 {
824 console_print( id, "[SCXPM] You raised your Level to %i.", playerlevel[target] );
825 }
826 else
827 {
828 console_print( id, "[SCXPM] You raised %s's Level to %i.", name, playerlevel[target] );
829 client_print( target, print_chat, "[SCXPM] An Admin has raised your Level to %i! Calling Skill Menu!", playerlevel[target] );
830 }
831 SCXPMSkill( target );
832 }
833 else
834 {
835 set_user_health( target, get_user_health( target ) + 450 - health[target] );
836 set_user_armor( target, get_user_armor( target ) + 450 - armor[target] );
837 health[target] = 450;
838 armor[target] = 450;
839 rhealth[target] = 300;
840 rarmor[target] = 300;
841 rammo[target] = 30;
842 gravity[target] = 40;
843 speed[target] = 80;
844 dist[target] = 60;
845 dodge[target] = 90;
846 skillpoints[target] = 0;
847 playerlevel[target] = 1800;
848 if ( target == id )
849 {
850 console_print( id, "[SCXPM] You raised your Level to 1800." );
851 }
852 else
853 {
854 console_print( id, "[SCXPM] You raised %s's Level to 1800.", name );
855 client_print( target, print_chat, "[SCXPM] An Admin has raised your Level to 1800! You got all Skills!" );
856 }
857 }
858 }
859 scxpm_calcneedxp( target );
860 SavePlayerData( target );
861
862 firstLvl[target] = nowlvl;
863
864 // for logging purposes
865 new adminname[32];
866 new adminid[32];
867 get_user_name( id, adminname, 31 );
868 get_user_authid(id, adminid, 31 );
869 log_amx( "[SCXPM] %s %s setlvl %s to level %i ", adminname, adminid, name, playerlevel[target] );
870
871 return PLUGIN_HANDLED;
872}
873
874// give player a medal
875public scxpm_addmedal( id, level, cid) {
876 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 2 ) )
877 {
878 return PLUGIN_HANDLED;
879 }
880 new targetarg[32];
881 read_argv(1, targetarg, 31);
882 new target = cmd_target( id, targetarg, 11 );
883 if ( !target )
884 {
885 return PLUGIN_HANDLED;
886 }
887 new name[32];
888 get_user_name( target, name, 31 );
889 if ( medals[target] < 16 )
890 {
891 medals[target]+=1;
892 console_print( id, "You awarded %s with a Medal.", name );
893 client_print( 0, print_chat, "[SCXPM] %s was awarded with a Medal! (He now has %i Medals)", name, medals[target] - 1 );
894 }
895 else
896 {
897 console_print( id, "%s already has 15 Medals.", name );
898 }
899
900 // for logging purposes
901 new adminname[32];
902 new adminid[32];
903 get_user_name( id, adminname, 31 );
904 get_user_authid(id, adminid, 31 );
905 log_amx( "[SCXPM] %s %s addmedal to %s", adminname, adminid, name );
906
907 return PLUGIN_HANDLED;
908}
909
910// remove players medal
911public scxpm_removemedal( id, level, cid ) {
912 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 2 ) )
913 {
914 return PLUGIN_HANDLED;
915 }
916 new targetarg[32];
917 read_argv( 1, targetarg, 31);
918 new target = cmd_target( id, targetarg, 11 );
919 if( !target )
920 {
921 return PLUGIN_HANDLED;
922 }
923 new name[32];
924 get_user_name( target, name, 31 );
925 if ( medals[target] > 1 )
926 {
927 medals[target]-=1;
928 console_print( id, "You took a Medal of %s.", name );
929 client_print( 0, print_chat, "[SCXPM] %s lost a Medal! (He now has %i Medals)", name,medals[target] - 1 );
930 }
931 else
932 {
933 console_print( id, "%s already has no Medals.", name );
934 }
935
936 // for logging purposes
937 new adminname[32];
938 new adminid[32];
939 get_user_name( id, adminname, 31 );
940 get_user_authid(id, adminid, 31 );
941 log_amx( "[SCXPM] %s %s removemedal from %s", adminname, adminid, name );
942
943 return PLUGIN_HANDLED;
944}
945
946// toggle godmode
947public scxpm_godmode(id,level,cid) {
948 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 2 ) )
949 {
950 return PLUGIN_HANDLED;
951 }
952 new godmode_arg[32];
953 read_argv( 1, godmode_arg, 31 );
954 new godmode_target = cmd_target( id, godmode_arg, 0 );
955 if ( godmode_target )
956 {
957 new godmode_name[32];
958 get_user_name( godmode_target, godmode_name, 31);
959 if ( !is_user_alive( godmode_target ) )
960 {
961 console_print( id, "[SCXPM] The User %s is currently dead!", godmode_name );
962 return PLUGIN_HANDLED;
963 }
964 if(is_player_flag_set(has_godmode, godmode_target))
965 {
966 set_user_godmode( godmode_target );
967 clear_player_flag(has_godmode, godmode_target);
968 if ( godmode_target == id )
969 {
970 console_print(id,"[SCXPM] You disabled God Mode on yourself!");
971 }
972 else
973 {
974 console_print( id, "[SCXPM] The User %s lost his God Mode!", godmode_name );
975 client_print( godmode_target, print_chat, "[SCXPM] An Admin has disabled God Mode on you!" );
976 }
977 }
978 else
979 {
980 set_player_flag(has_godmode, godmode_target);
981 set_user_godmode( godmode_target, 1 );
982 if ( godmode_target == id )
983 {
984 console_print( id, "[SCXPM] You enabled God Mode on yourself!" );
985 }
986 else
987 {
988 console_print( id, "[SCXPM] The User %s now has God Mode!", godmode_name );
989 client_print( godmode_target, print_chat, "[SCXPM] An Admin has enabled God Mode on you!" );
990 }
991 }
992 }
993 return PLUGIN_HANDLED;
994}
995
996// toggle noclip
997public scxpm_noclipmode( id, level, cid ) {
998 if ( !cmd_access( id, ADMIN_IMMUNITY, cid, 2 ) )
999 {
1000 return PLUGIN_HANDLED;
1001 }
1002 new noclipmode_arg[32];
1003 read_argv( 1, noclipmode_arg, 31 );
1004 new noclipmode_target = cmd_target( id, noclipmode_arg, 0 );
1005 if ( noclipmode_target )
1006 {
1007 new noclipmode_name[32];
1008 get_user_name( noclipmode_target, noclipmode_name, 31 );
1009 if ( !is_user_alive( noclipmode_target ) )
1010 {
1011 console_print( id, "[SCXPM] The User %s is currently dead!", noclipmode_name );
1012 return PLUGIN_HANDLED;
1013 }
1014 if ( get_user_noclip( noclipmode_target ) )
1015 {
1016 set_user_noclip( noclipmode_target );
1017 if ( noclipmode_target == id )
1018 {
1019 console_print( id, "[SCXPM] You disabled Noclip Mode on yourself" );
1020 }
1021 else
1022 {
1023 console_print( id, "[SCXPM] The User %s lost his Noclip Mode!", noclipmode_name );
1024 client_print( noclipmode_target, print_chat, "[SCXPM] An Admin has disabled Noclip Mode on you!" );
1025 }
1026 }
1027 else
1028 {
1029 set_user_noclip( noclipmode_target, 1 );
1030 if ( noclipmode_target == id )
1031 {
1032 console_print( id, "[SCXPM] You enabled Noclip Mode on yourself!" );
1033 }
1034 else
1035 {
1036
1037 console_print( id, "[SCXPM] The User %s now has Noclip Mode!", noclipmode_name );
1038 client_print( noclipmode_target, print_chat, "[SCXPM] An Admin has enabled Noclip Mode on you!" );
1039 }
1040 }
1041 }
1042 return PLUGIN_HANDLED;
1043}
1044
1045// reset players skills
1046public scxpm_reset(id) {
1047 health[id] = 0;
1048 armor[id] = 0;
1049 rhealth[id] = 0;
1050 rarmor[id] = 0;
1051 rammo[id] = 0;
1052 gravity[id] = 0;
1053 speed[id] = 0;
1054 dist[id] = 0;
1055 dodge[id] = 0;
1056 //xp[id] = 0;
1057 skillpoints[id] = playerlevel[id];
1058 if ( get_user_health( id ) > starthealth + medals[id] )
1059 {
1060 set_user_health( id, starthealth + medals[id] )
1061 }
1062 if ( get_user_armor(id) > startarmor + medals[id] )
1063 {
1064 set_user_armor( id, startarmor + medals[id] )
1065 }
1066 set_user_gravity( id, 1.0 )
1067 if ( skillpoints[id] > 0 )
1068 {
1069 client_print( id, print_chat, "[SCXPM] All your Skills have been set back. Please choose..." );
1070 SCXPMSkill( id );
1071 }
1072 else
1073 {
1074 client_print( id, print_chat, "[SCXPM] You have no Skills to reset." );
1075 }
1076}
1077
1078// show plugin info
1079public scxpm_version( id ) {
1080 new allinfo[1023];
1081 format( allinfo, 1022, "Plugin Name: SCXPM (Sven Cooperative Experience Mod)^nPlugin Type: Running under AMXModX (www.amxmodx.org)^nAuthor: Silencer^nVersion: %s^nLast Update: %s^nExperience Multiplier (Server Side): %f^nInformation: http://forums.alliedmods.net/showthread.php?t=44168", VERSION, LASTUPDATE, get_pcvar_float( pcvar_xpgain ) );
1082 show_motd( id, allinfo, "SCXPM Information" );
1083}
1084
1085// show players skill data
1086public scxpm_info( id ) {
1087 #if defined USING_CS
1088 new allskills[1023] = "1. Strength:<br /> Starthealth + 1 * Strengthlevel.<br />";
1089 format(allskills,1022,"%s<br />2. Superior Armor:<br /> Startarmor + 1 * Armorlevel.<br />",allskills);
1090 format(allskills,1022,"%s<br />3. Regeneration:<br /> One HP every (150.5-(Regenerationlevel/2)) Seconds<br /> + Bonus Chance every 0.5 Seconds.<br />",allskills);
1091 format(allskills,1022,"%s<br />4. Nano Armor:<br /> One AP every (150.5-(Nanoarmorlevel/2)) Seconds<br /> + Bonus Chance every 0.5 Seconds.<br />",allskills);
1092 format(allskills,1022,"%s<br />5. Ammunition Reincarnation:<br /> Ammunition for current Weapon every (90-(Ammolevel*2.5)) Seconds.<br />",allskills);
1093 format(allskills,1022,"%s<br />6. Anti Gravity Device:<br /> Lowers your Gravity by (1.5)%% per Level. Hold Jump-Key!<br />",allskills);
1094 format(allskills,1022,"%s<br />7. Awareness:<br /> Generic Skill which is enhancing many other Skills a bit.<br />",allskills);
1095 format(allskills,1022,"%s<br />8. Team Power:<br /> Supports nearby Teammates with HP and AP<br /> and also yourself on higher Level.<br />",allskills);
1096 format(allskills,1022,"%s<br />9. Block Attack:<br /> Chance on fully blocking any Attack of (Blocklevel/3)%%.<br />",allskills);
1097 format(allskills,1022,"%s<br />Special - Medals:<br /> Given by an Admin, Shows your Importance.<br /> (Minimal Ability Support)",allskills);
1098 #else
1099 new allskills[1023] = "1. Strength:^n Starthealth + 1 * Strengthlevel.^n";
1100 format(allskills,1022,"%s^n2. Superior Armor:^n Startarmor + 1 * Armorlevel.^n",allskills);
1101 format(allskills,1022,"%s^n3. Regeneration:^n One HP every (150.5-(Regenerationlevel/2)) Seconds^n + Bonus Chance every 0.5 Seconds.^n",allskills);
1102 format(allskills,1022,"%s^n4. Nano Armor:^n One AP every (150.5-(Nanoarmorlevel/2)) Seconds^n + Bonus Chance every 0.5 Seconds.^n",allskills);
1103 format(allskills,1022,"%s^n5. Ammunition Reincarnation:^n Ammunition for current Weapon every (90-(Ammolevel*2.5)) Seconds.^n",allskills);
1104 format(allskills,1022,"%s^n6. Anti Gravity Device:^n Lowers your Gravity by (1.5)%% per Level. Hold Jump-Key!^n",allskills);
1105 format(allskills,1022,"%s^n7. Awareness:^n Generic Skill which is enhancing many other Skills a bit.^n",allskills);
1106 format(allskills,1022,"%s^n8. Team Power:^n Supports nearby Teammates with HP and AP^n and also yourself on higher Level.^n",allskills);
1107 format(allskills,1022,"%s^n9. Block Attack:^n Chance on fully blocking any Attack of (Blocklevel/3)%%.^n",allskills);
1108 format(allskills,1022,"%s^nSpecial - Medals:^n Given by an Admin, Shows your Importance.^n (Minimal Ability Support)",allskills);
1109 #endif
1110 show_motd(id,allskills,"Skills Information")
1111}
1112
1113// show all connected players skills
1114public scxpm_others( id ) {
1115 new alldata[2048];
1116 #if defined USING_CS
1117 alldata="<html><head><title>Players levels</title></head><body><table border='1'><tr><th width='200' align='left' cellpadding='5'>Playername</th><th width='40'>Level</th><th width='40'>Medals</th></tr>"
1118 new iPlayers[32],iNum
1119 get_players(iPlayers,iNum)
1120 for(new g=0;g<iNum;g++)
1121 {
1122 new i=iPlayers[g]
1123 if(is_user_connected(i))
1124 {
1125 new name[20]
1126 get_user_name(i,name,19)
1127 format(alldata,2047,"%s<tr><td>%s</td><td align='center'>%i</td><td align='center'>%i</td>",alldata,name,playerlevel[i],medals[i]-1)
1128 }
1129 }
1130 format(alldata,2047,"%s</table></body></html>",alldata)
1131 #else
1132 alldata="Playername Level Medals^n"
1133 new iPlayers[32],iNum
1134 get_players(iPlayers,iNum)
1135 for(new g=0;g<iNum;g++)
1136 {
1137 new i=iPlayers[g]
1138 if(is_user_connected(i))
1139 {
1140 new name[20]
1141 get_user_name(i,name,19)
1142 new toadd=20-strlen(name)
1143 new spaces[20]=""
1144 add(spaces,19," ",toadd)
1145 format(alldata,2047,"%s^n%s %s %i %i",alldata,name,spaces,playerlevel[i],medals[i]-1)
1146 }
1147 }
1148 #endif
1149 show_motd( id, alldata, "Players Data" );
1150}
1151
1152// get the different ranks
1153public scxpm_getrank( id ) {
1154 new rid;
1155 new pl = playerlevel[id];
1156
1157 if(pl>=1800){
1158 rid = 21;
1159 }else if((pl>=1700)&&(pl<=1799)){
1160 rid = 20;
1161 }else if((pl>=1600)&&(pl<=1699)){
1162 rid = 19;
1163 }else if((pl>=1500)&&(pl<=1599)){
1164 rid = 18;
1165 }else if((pl>=1400)&&(pl<=1499)){
1166 rid = 17;
1167 }else if((pl>=1300)&&(pl<=1399)){
1168 rid = 16;
1169 }else if((pl>=1200)&&(pl<=1299)){
1170 rid = 15;
1171 }else if((pl>=1100)&&(pl<=1199)){
1172 rid = 14;
1173 }else if((pl>=1000)&&(pl<=1099)){
1174 rid = 13;
1175 }else if((pl>=900)&&(pl<=999)){
1176 rid = 12;
1177 }else if((pl>=800)&&(pl<=899)){
1178 rid = 11;
1179 }else if((pl>=700)&&(pl<=799)){
1180 rid = 10;
1181 }else if((pl>=600)&&(pl<=699)){
1182 rid = 9;
1183 }else if((pl>=500)&&(pl<=599)){
1184 rid = 8;
1185 }else if((pl>=400)&&(pl<=499)){
1186 rid = 7;
1187 }else if((pl>=300)&&(pl<=399)){
1188 rid = 6;
1189 }else if((pl>=200)&&(pl<=299)){
1190 rid = 5;
1191 }else if((pl>=100)&&(pl<=199)){
1192 rid = 4;
1193 }else if((pl>=50)&&(pl<=99)){
1194 rid = 3;
1195 }else if((pl>=20)&&(pl<=49)){
1196 rid = 2;
1197 }else if((pl>=5)&&(pl<=19)){
1198 rid = 1;
1199 }else{
1200 rid = 0;
1201 }
1202 rank[id] = rid;
1203}
1204
1205public say_hook(id){
1206 new command[15];
1207
1208 read_argv(1,command,sizeof command-1);
1209
1210 if(equali(command,"selectskills") || equali(command,"/selectskills")){
1211 SCXPMSkill(id);
1212 return PLUGIN_HANDLED;
1213 }else if(equali(command,"resetskills") || equali(command,"/resetskills")){
1214 scxpm_reset(id);
1215 return PLUGIN_HANDLED;
1216 }else if(equali(command,"playerskills") || equali(command,"/playerskills")){
1217 scxpm_others(id);
1218 return PLUGIN_HANDLED;
1219 }else if(equali(command,"skillsinfo") || equali(command,"/skillsinfo")){
1220 scxpm_info(id);
1221 return PLUGIN_HANDLED;
1222 }else if(equali(command,"scxpminfo") || equali(command,"/scxpminfo")){
1223 scxpm_version(id);
1224 return PLUGIN_HANDLED;
1225 }
1226 return PLUGIN_CONTINUE;
1227}
1228
1229// give extra info for beginners
1230public scxpm_newbiehelp( id ) {
1231 if ( is_user_connected( id ) )
1232 {
1233 new name[32];
1234 get_user_name( id, name, 31);
1235 client_print( id, print_chat, "[SCXPM] Commands: ^"'say skillsinfo', 'say selectskills', 'say resetskills', 'say playerskills', 'say scxpminfo'^"" );
1236 }
1237}
1238
1239// if player got the steam id load again
1240public client_authorized( id ) {
1241 LoadPlayerData( id );
1242}
1243
1244// load empty skills for new player or faulty load
1245public LoadEmptySkills( id ) {
1246 xp[id] = 0;
1247 playerlevel[id] = 0;
1248 scxpm_calcneedxp( id );
1249 scxpm_getrank( id );
1250 skillpoints[id] = 0;
1251 medals[id] = 4;
1252 health[id] = 0;
1253 armor[id] = 0;
1254 rhealth[id] = 0;
1255 rarmor[id] = 0;
1256 rammo[id] = 0;
1257 gravity[id] = 0;
1258 speed[id] = 0;
1259 dist[id] = 0;
1260 dodge[id] = 0;
1261 lastDeadflag[id] = 1;
1262 lastfrags[id] = 0;
1263 firstLvl[id]=0;
1264 set_task( 35.0, "scxpm_newbiehelp", id, "", 0, "a", 3 );
1265}
1266
1267// prepare data on client connect
1268public client_connect( id ) {
1269 if (get_pcvar_num( pcvar_debug ) == 1 )
1270 {
1271 log_amx( "[SCXPM DEBUG] Begin client_connect" );
1272 new name[64];
1273 get_user_name( id, name, 63);
1274 log_amx( "[SCXPM DEBUG] %s connected", name );
1275 }
1276 lastfrags[ id ] = 0;
1277 clear_player_flag(loaddata, id);
1278 // if savemode is on steamid don't load till the id is retreived
1279 if ( get_pcvar_num( pcvar_save ) < 2 )
1280 {
1281 LoadPlayerData( id );
1282 }
1283 if (get_pcvar_num( pcvar_debug ) == 1 )
1284 {
1285 log_amx( "[SCXPM DEBUG] End client_connect" );
1286 }
1287}
1288
1289// clear data on client disconnect
1290public client_disconnect( id ) {
1291 if (get_pcvar_num( pcvar_debug ) == 1 )
1292 {
1293 log_amx( "[SCXPM DEBUG] Begin client_disconnect" );
1294 new name[64];
1295 get_user_name( id, name, 63);
1296 log_amx( "[SCXPM DEBUG] %s disconnected", name );
1297 }
1298
1299 if ( get_pcvar_num( pcvar_minplaytime ) == 0 || get_pcvar_num( pcvar_minplaytime ) <= get_user_time( id ) ) {
1300 SavePlayerData( id );
1301 }
1302 else {
1303 if (get_pcvar_num( pcvar_debug ) == 1 ) {
1304 log_amx( "[SCXPM DEBUG] Player is too short in the server, don't save stats" );
1305 }
1306 }
1307
1308 xp[id] = 0;
1309 neededxp[id] = 0;
1310 playerlevel[id] = 0;
1311 skillpoints[id] = 0;
1312 medals[id] = 0;
1313 health[id] = 0;
1314 armor[id] = 0;
1315 rhealth[id] = 0;
1316 rarmor[id] = 0;
1317 rammo[id] = 0;
1318 gravity[id] = 0;
1319 speed[id] = 0;
1320 dist[id] = 0;
1321 dodge[id] = 0;
1322 rarmorwait[id] = 0;
1323 rhealthwait[id] = 0;
1324 ammowait[id] = 0;
1325 rank[id] = sizeof ranks-1;
1326 clear_player_flag(loaddata, id);
1327 if (get_pcvar_num( pcvar_debug ) == 1 )
1328 {
1329 log_amx( "[SCXPM DEBUG] End client_disconnect" );
1330 }
1331}
1332
1333// check respawn and gravity
1334public scxpm_prethink( id ) {
1335 new deadflag = pev( id, pev_deadflag );
1336 if ( !deadflag && lastDeadflag[id] )
1337 {
1338 scxpm_client_spawn( id );
1339 }
1340
1341 lastDeadflag[id] = deadflag;
1342 if ( pev( id, pev_button ) &IN_JUMP )
1343 {
1344 gravityon( id );
1345 }
1346 else
1347 {
1348 if ( pev( id, pev_oldbuttons ) &IN_JUMP )
1349 {
1350 gravityoff( id );
1351 }
1352 }
1353}
1354
1355// set players health and armor on spawn
1356public scxpm_client_spawn( id )
1357{
1358 starthealth = get_user_health( id );
1359 startarmor = get_user_armor( id );
1360 set_user_health( id, health[id] + starthealth + medals[id] );
1361 set_user_armor( id, armor[id] + startarmor + medals[id] );
1362}
1363
1364// set players health and armor on spawn
1365public client_spawn ( id )
1366{
1367 starthealth = get_user_health( id );
1368 startarmor = get_user_armor( id );
1369 set_user_health( id, health[id] + starthealth + medals[id] );
1370 set_user_armor( id, armor[id] + startarmor + medals[id] );
1371}
1372
1373// set players health and armor on round start
1374public roundstart ( ) {
1375 if ( get_pcvar_num( pcvar_debug ) == 1 )
1376 {
1377 log_amx( "[SCXPM DEBUG] round_start" );
1378 }
1379
1380 for ( new i = 0; i < 33; i++ )
1381 {
1382 lastDeadflag[i] = 1;
1383 }
1384
1385 // loop through the players and set their stats
1386 new iPlayers[32], iNum;
1387 get_players( iPlayers, iNum );
1388
1389 for( new g = 0; g<iNum ;g++ )
1390 {
1391 new id = iPlayers[g];
1392
1393 new name[32];
1394 get_user_name( id, name, 31 );
1395
1396 starthealth = get_user_health( id );
1397 startarmor = get_user_armor( id );
1398
1399 if ( get_pcvar_num( pcvar_debug ) == 1 )
1400 {
1401 log_amx( "[SCXPM DEBUG] %s starthealth: %i", name, starthealth);
1402 log_amx( "[SCXPM DEBUG] setting %s health to: %i", name, health[id] + starthealth + medals[id]);
1403 }
1404 set_user_health( id, health[id] + starthealth + medals[id] );
1405 set_user_armor( id, armor[id] + startarmor + medals[id] );
1406 }
1407}
1408
1409// set gravity on for player
1410public gravityon( id ) {
1411 if ( is_user_connected( id ) )
1412 {
1413 if ( is_user_alive( id ) )
1414 {
1415 set_user_gravity( id, 1.0 - ( 0.015 * gravity[id] ) - ( 0.001 * medals[id] ) );
1416 }
1417 }
1418}
1419
1420// set gravity off for player
1421public gravityoff( id ) {
1422 if ( is_user_connected( id ) )
1423 {
1424 if ( is_user_alive( id ) )
1425 {
1426 set_user_gravity( id, 1.0 );
1427 }
1428 }
1429}
1430
1431// calculate needed xp for next level
1432public scxpm_calcneedxp ( id ) {
1433 new Float:m70 = float( playerlevel[id] ) * 70.0;
1434 new Float:mselfm3dot2 = float( playerlevel[id] ) * float( playerlevel[id] ) * 3.5;
1435 neededxp[id] = floatround( m70 + mselfm3dot2 + 30.0 );
1436}
1437
1438// calculate level from xp
1439public scxpm_calc_lvl ( xp ) {
1440 return floatround( -10 + floatsqroot( 100 - ( 60 / 7 - ( ( xp - 1 ) / 3.5 ) ) ), floatround_ceil );
1441}
1442
1443public scxpm_calc_xp ( level) {
1444 level--;
1445 return floatround( (float( level ) * 70.0) + (float( level ) * float(level) * 3.5) + 30);
1446}
1447
1448// give ammo
1449public scxpm_randomammo( i ) {
1450 new number = random_num(0,6)
1451#if defined USING_CS
1452 give_item(i, ammotype[number]);
1453#else
1454 new clip,ammo
1455 if(number==0)
1456 {
1457 get_user_ammo(i,2,clip,ammo)
1458 if(ammo<250)
1459 {
1460 give_item(i,"ammo_9mmAR")
1461 give_item(i,"ammo_9mmAR")
1462 }
1463 else
1464 {
1465 number=1
1466 }
1467 }
1468 if(number==1)
1469 {
1470 get_user_ammo(i,3,clip,ammo)
1471 if(ammo<36)
1472 {
1473 give_item(i,"ammo_357")
1474 give_item(i,"ammo_357")
1475 give_item(i,"ammo_357")
1476 }
1477 else
1478 {
1479 number=2
1480 }
1481 }
1482 if(number==2)
1483 {
1484
1485 get_user_ammo(i,7,clip,ammo)
1486 if(ammo<125)
1487 {
1488 give_item(i,"ammo_buckshot")
1489 give_item(i,"ammo_buckshot")
1490 give_item(i,"ammo_buckshot")
1491 }
1492 else
1493 {
1494 number=3
1495 }
1496 }
1497 if(number==3)
1498 {
1499 get_user_ammo(i,9,clip,ammo)
1500 if(ammo<100)
1501 {
1502 give_item(i,"ammo_gaussclip")
1503 give_item(i,"ammo_gaussclip")
1504 }
1505 else
1506 {
1507 number=4
1508 }
1509 }
1510 if(number==4)
1511 {
1512 get_user_ammo(i,6,clip,ammo)
1513 if(ammo<50)
1514 {
1515 give_item(i,"ammo_crossbow")
1516 give_item(i,"ammo_crossbow")
1517 give_item(i,"ammo_ARgrenades")
1518 give_item(i,"ammo_ARgrenades")
1519 }
1520 else
1521 {
1522 number=5
1523 }
1524 }
1525 if(number==5)
1526 {
1527 get_user_ammo(i,8,clip,ammo)
1528 if(ammo<5)
1529 {
1530 give_item(i,"ammo_rpgclip")
1531 }
1532 else
1533 {
1534 number=6
1535 }
1536 }
1537 if(number==6)
1538 {
1539 get_user_ammo(i,23,clip,ammo)
1540 if(ammo<15)
1541 {
1542 give_item(i,"ammo_762")
1543 give_item(i,"ammo_762")
1544 give_item(i,"ammo_556")
1545 give_item(i,"ammo_556")
1546 give_item(i,"ammo_sporeclip")
1547 give_item(i,"ammo_sporeclip")
1548 give_item(i,"ammo_sporeclip")
1549 give_item(i,"ammo_sporeclip")
1550 give_item(i,"ammo_sporeclip")
1551 }
1552 }
1553#endif
1554}
1555
1556// give stuff
1557public scxpm_regen() {
1558 new iPlayers[32],iNum
1559 get_players(iPlayers,iNum)
1560 for(new g=0;g<iNum;g++)
1561 {
1562 new i=iPlayers[g]
1563 if(is_user_connected(i))
1564 {
1565 if(is_user_alive(i))
1566 {
1567 new halfspeed=floatround(float(speed[i])/1.0)
1568 if(rhealth[i]>0)
1569 {
1570 if(rhealthwait[i]==0)
1571 {
1572 if(get_user_health(i)<health[i]+starthealth+medals[i]+halfspeed)
1573 {
1574 set_user_health(i,get_user_health(i)+1)
1575 rhealthwait[i]=300-rhealth[i]
1576 }
1577 }
1578 else
1579 {
1580 rhealthwait[i]-=1
1581 if(get_user_health(i)<health[i]+starthealth+medals[i]+halfspeed&&random_num(0,200+rhealth[i]+medals[i]+halfspeed)>1)
1582 {
1583 set_user_health(i,get_user_health(i)+1)
1584 }
1585 }
1586 }
1587 if(rarmor[i]>0)
1588 {
1589 if(rarmorwait[i]==0)
1590 {
1591 if(get_user_armor(i)<armor[i]+startarmor+medals[i]+halfspeed)
1592 {
1593 set_user_armor(i,get_user_armor(i)+1)
1594 rarmorwait[i]=300-rarmor[i]
1595 }
1596 }
1597 else
1598 {
1599 rarmorwait[i]-=1
1600 if(get_user_armor(i)<armor[i]+startarmor+medals[i]+halfspeed&&random_num(0,200+rarmor[i]+medals[i]+halfspeed)>1)
1601 {
1602 set_user_armor(i,get_user_armor(i)+1)
1603 }
1604 }
1605 }
1606 if(rammo[i]>0)
1607 {
1608 if(ammowait[i]==0)
1609 {
1610#if defined USING_CS
1611 scxpm_randomammo(i)
1612#else
1613 new clip,ammo
1614 switch(get_user_weapon(i,clip,ammo))
1615 {
1616 case 1: /* Crowbar */
1617 {
1618 scxpm_randomammo(i)
1619 }
1620 case 2: /* 9mm Handgun */
1621 {
1622 get_user_ammo(i,2,clip,ammo)
1623 if(ammo<250)
1624 {
1625 give_item(i,"ammo_9mmAR")
1626 }
1627 else
1628 {
1629 scxpm_randomammo(i)
1630 }
1631 }
1632 case 3: /* 357 (Revolver) */
1633 {
1634 get_user_ammo(i,3,clip,ammo)
1635 if(ammo<36)
1636 {
1637 give_item(i,"ammo_357")
1638 give_item(i,"ammo_357")
1639 }
1640 else
1641 {
1642 scxpm_randomammo(i)
1643 }
1644 }
1645 case 4: /* 9mm AR = MP5 */
1646 {
1647 get_user_ammo(i,4,clip,ammo)
1648 if(ammo<250)
1649 {
1650 give_item(i,"ammo_9mmAR")
1651 give_item(i,"ammo_9mmAR")
1652 }
1653 else
1654 {
1655 scxpm_randomammo(i)
1656 }
1657 }
1658 case 6: /* Crossbow */
1659 {
1660 get_user_ammo(i,6,clip,ammo)
1661 if(ammo<50)
1662 {
1663 give_item(i,"ammo_crossbow")
1664 give_item(i,"ammo_crossbow")
1665 }
1666 else
1667 {
1668 scxpm_randomammo(i)
1669 }
1670 }
1671 case 7: /* Shotgun */
1672 {
1673 get_user_ammo(i,7,clip,ammo)
1674 if(ammo<125)
1675 {
1676 give_item(i,"ammo_buckshot")
1677 give_item(i,"ammo_buckshot")
1678 }
1679 else
1680 {
1681 scxpm_randomammo(i)
1682 }
1683 }
1684 case 8: /* RPG Launcher */
1685 {
1686 get_user_ammo(i,8,clip,ammo)
1687 if(ammo<5)
1688 {
1689 give_item(i,"ammo_rpgclip")
1690 }
1691 else
1692 {
1693 scxpm_randomammo(i)
1694 }
1695 }
1696 case 9: /* Gauss Cannon */
1697 {
1698 get_user_ammo(i,9,clip,ammo)
1699 if(ammo<100)
1700 {
1701 give_item(i,"ammo_gaussclip")
1702 give_item(i,"ammo_gaussclip")
1703 }
1704 else
1705 {
1706 scxpm_randomammo(i)
1707 }
1708 }
1709 case 10: /* Egon */
1710 {
1711 get_user_ammo(i,10,clip,ammo)
1712 if(ammo<100)
1713 {
1714 give_item(i,"ammo_gaussclip")
1715 give_item(i,"ammo_gaussclip")
1716 }
1717 else
1718 {
1719 scxpm_randomammo(i)
1720 }
1721 }
1722 case 11: /* Hornetgun */
1723 {
1724 scxpm_randomammo(i)
1725 }
1726 case 12: /* Handgrenade */
1727 {
1728 scxpm_randomammo(i)
1729 }
1730 case 13: /* Tripmine */
1731 {
1732 scxpm_randomammo(i)
1733 }
1734 case 14: /* Satchels */
1735 {
1736 scxpm_randomammo(i)
1737 }
1738 case 15: /* Snarks */
1739 {
1740 scxpm_randomammo(i)
1741 }
1742 case 16: /* Uzi Akimbo */
1743 {
1744 get_user_ammo(i,16,clip,ammo)
1745 if(ammo<250)
1746 {
1747 give_item(i,"ammo_9mmAR")
1748 give_item(i,"ammo_9mmAR")
1749 }
1750 else
1751 {
1752 scxpm_randomammo(i)
1753 }
1754 }
1755 case 17: /* Uzi */
1756 {
1757 get_user_ammo(i,17,clip,ammo)
1758 if(ammo<100)
1759 {
1760 give_item(i,"ammo_9mmAR")
1761 give_item(i,"ammo_9mmAR")
1762 }
1763 else
1764 {
1765 scxpm_randomammo(i)
1766 }
1767 }
1768 case 18: /* Medkit */
1769 {
1770 scxpm_randomammo(i)
1771 if(get_user_health(i)<health[i]+starthealth+medals[i]+halfspeed)
1772 {
1773 set_user_health(i,get_user_health(i)+1)
1774 rhealthwait[i]=200-rhealth[i]
1775 }
1776 }
1777 case 20: /* Pipewrench */
1778 {
1779 scxpm_randomammo(i)
1780 }
1781 case 21: /* Minigun */
1782 {
1783 get_user_ammo(i,21,clip,ammo)
1784 if(ammo<600)
1785 {
1786 give_item(i,"ammo_556")
1787 give_item(i,"ammo_556")
1788 }
1789 else
1790 {
1791 scxpm_randomammo(i)
1792 }
1793 }
1794 case 22: /* Grapple */
1795 {
1796 scxpm_randomammo(i)
1797 }
1798 case 23: /* Sniper Rifle */
1799 {
1800 get_user_ammo(i,23,clip,ammo)
1801 if(ammo<15)
1802 {
1803 give_item(i,"ammo_762")
1804 give_item(i,"ammo_762")
1805 }
1806 else
1807 {
1808 scxpm_randomammo(i)
1809 }
1810 }
1811 case 24: /* M249 Saw */
1812 {
1813 get_user_ammo(i,24,clip,ammo)
1814 if(ammo<600)
1815 {
1816 give_item(i,"ammo_556")
1817 give_item(i,"ammo_556")
1818 }
1819 else
1820 {
1821 scxpm_randomammo(i)
1822 }
1823 }
1824 case 25: /* M16 */
1825 {
1826 get_user_ammo(i,25,clip,ammo)
1827 if(ammo<600)
1828 {
1829 give_item(i,"ammo_556")
1830 give_item(i,"ammo_ARgrenades")
1831 }
1832 else
1833 {
1834 scxpm_randomammo(i)
1835 }
1836 }
1837 case 26: /* Spore Launcher */
1838 {
1839 get_user_ammo(i,26,clip,ammo)
1840 if(ammo<30)
1841 {
1842 give_item(i,"ammo_sporeclip")
1843 give_item(i,"ammo_sporeclip")
1844 give_item(i,"ammo_sporeclip")
1845 give_item(i,"ammo_sporeclip")
1846 give_item(i,"ammo_sporeclip")
1847 give_item(i,"ammo_sporeclip")
1848 give_item(i,"ammo_sporeclip")
1849 give_item(i,"ammo_sporeclip")
1850 give_item(i,"ammo_sporeclip")
1851 give_item(i,"ammo_sporeclip")
1852 }
1853 else
1854 {
1855 scxpm_randomammo(i)
1856 }
1857 }
1858 case 27: /* Desert Eagle */
1859 {
1860 get_user_ammo(i,27,clip,ammo)
1861 if(ammo<36)
1862 {
1863 give_item(i,"ammo_357")
1864 give_item(i,"ammo_357")
1865 give_item(i,"ammo_357")
1866 }
1867 else
1868 {
1869 scxpm_randomammo(i)
1870 }
1871 }
1872 case 28: /* Shock Roach */
1873 {
1874 scxpm_randomammo(i)
1875 give_item(i,"item_battery")
1876 }
1877 }
1878#endif
1879 new speed_dt=floatround(float(speed[i])/15.0)
1880 ammowait[i]=179-(5*rammo[i])-speed_dt
1881 }
1882 else
1883 {
1884 ammowait[i]-=1
1885 }
1886 }
1887#if !defined USING_CS
1888 new clip,ammo
1889 switch(get_user_weapon(i,clip,ammo))
1890 {
1891 case 18: /* Medkit */
1892 {
1893 if(get_user_health(i)<100)
1894 {
1895 if(random_num(rhealth[i],800-get_user_health(i)>1))
1896 {
1897 set_user_health(i,get_user_health(i)+1)
1898 }
1899 }
1900 else
1901 {
1902 if(get_user_health(i)<health[i]+starthealth+medals[i]+halfspeed&&random_num(0,200+rhealth[i])>1)
1903 {
1904 set_user_health(i,get_user_health(i)+1)
1905 }
1906 }
1907 }
1908 }
1909#endif
1910 if(dist[i]>0)
1911 {
1912 for(new h=0;h<iNum;h++)
1913 {
1914 new id=iPlayers[h]
1915 for(new j=0;j<iNum;j++)
1916 {
1917 new i=iPlayers[j]
1918 if(id==i)
1919 {
1920 if(is_user_alive(i)&&is_user_alive(id))
1921 {
1922 new Float:origin_i[3]
1923 pev(i,pev_origin,origin_i)
1924 new Float:origin_id[3]
1925 pev(id,pev_origin,origin_id)
1926 if(get_distance_f(origin_i,origin_id)<=650.0)
1927 {
1928 new halfspeed=floatround(float(speed[i])/1.0)
1929 new iPlayers[32],iNum
1930 get_players(iPlayers,iNum)
1931 iNum=iNum*50
1932 new luck=random_num(1651-iNum,2000+dist[id]+dist[i]+halfspeed)
1933 if(luck>2000)
1934 {
1935 set_user_health(i,get_user_health(i)+1)
1936 if(get_user_health(i)>health[i]+starthealth+100+dist[id]+medals[i]+halfspeed)
1937 {
1938 set_user_health(i,health[i]+starthealth+100+dist[id]+medals[i]+halfspeed)
1939 }
1940 }
1941 luck=random_num(1651-iNum,2000+dist[id]+dist[i]+halfspeed)
1942 if(luck>2000)
1943 {
1944 set_user_armor(i,get_user_armor(i)+1)
1945 if(get_user_armor(i)>armor[i]+startarmor+100+dist[id]+medals[i]+halfspeed)
1946 {
1947 set_user_armor(i,armor[i]+startarmor+100+dist[id]+medals[i]+halfspeed)
1948 }
1949 }
1950 if(dist[id]>=40)
1951 {
1952 luck=random_num(1000,1000+dist[id])
1953 if(luck>1000)
1954 {
1955 set_user_health(i,get_user_health(i)+1)
1956 if(get_user_health(i)>health[i]+starthealth+100+dist[id]+medals[i]+halfspeed)
1957 {
1958 set_user_health(i,health[i]+starthealth+100+dist[id]+medals[i]+halfspeed)
1959 }
1960 set_user_armor(i,get_user_armor(i)+1)
1961 if(get_user_armor(i)>armor[i]+startarmor+100+dist[id]+medals[i]+halfspeed)
1962 {
1963 set_user_armor(i,armor[i]+startarmor+100+dist[id]+medals[i]+halfspeed)
1964 }
1965 }
1966 }
1967 }
1968 }
1969 }
1970 }
1971 }
1972 }
1973 if(!is_player_flag_set(has_godmode, i))
1974 {
1975 if(dodge[i]>0)
1976 {
1977 new piecespeed=floatround(float(speed[i])/7.0)
1978 new luck=random_num(80,185+dodge[i]+medals[i]+piecespeed)
1979 if(luck>185)
1980 {
1981 set_user_godmode(i,1)
1982 }
1983 else
1984 {
1985 set_user_godmode(i)
1986 }
1987 }
1988 else
1989 {
1990 set_user_godmode(i)
1991 }
1992 }
1993 }
1994 }
1995 }
1996}
1997
1998// periodic calculations
1999public scxpm_sdac() {
2000 #if defined USING_CS
2001 scxpm_showdata();
2002 scxpm_regen();
2003 #else
2004 switch(onecount)
2005 {
2006 case false:
2007 {
2008 onecount = true;
2009 }
2010 case true:
2011 {
2012 scxpm_reexp();
2013 scxpm_showdata();
2014 onecount = false;
2015 }
2016 }
2017 scxpm_regen();
2018 #endif
2019
2020 // added health fix
2021 /*
2022 new iPlayers[32], iNum, hp;
2023 get_players( iPlayers, iNum );
2024 for ( new i = 0; i < iNum; i++ ) {
2025 if(is_user_alive(i)) {
2026 hp = get_user_health(i);
2027 if (hp > 255 && (hp % 256) == 0) {
2028 set_user_health(i, hp++);
2029 }
2030 }
2031 }
2032 */
2033}
2034
2035#if !defined USING_CS
2036 public scxpm_reexp() {
2037 new iPlayers[32], iNum;
2038 get_players( iPlayers, iNum );
2039 for( new g = 0; g < iNum; g++ )
2040 {
2041 new i=iPlayers[g];
2042 if ( is_user_connected(i) )
2043 {
2044 if ( playerlevel[i] >= 1800 ) {
2045 xp[i] = 11500000;
2046 }
2047 else if ( playerlevel[i] >= get_pcvar_num( pcvar_maxlevel ) ) {
2048 xp[i] = scxpm_calc_xp( playerlevel[i] );
2049 }
2050 else {
2051 if(firstLvl[i] == 0){
2052 firstLvl[i] = playerlevel[i];}
2053
2054 if (get_pcvar_num(pcvar_maxlevelup_enabled) == 0 || playerlevel[i] <= get_pcvar_num(pcvar_maxlevelup_limit) || (playerlevel[i] - firstLvl[i]) < get_pcvar_num(pcvar_maxlevelup))
2055 {
2056 new Float:helpvar = float(xp[i])/5.0/get_pcvar_float(pcvar_xpgain)+float(get_user_frags(i))-float(lastfrags[i]);
2057 xp[i]=floatround(helpvar*5.0*get_pcvar_float(pcvar_xpgain));
2058 }
2059
2060 if ( get_pcvar_num( pcvar_save_frequent ) == 1 ) {
2061 SavePlayerData( i );
2062 }
2063 lastfrags[i] = get_user_frags(i);
2064 if( neededxp[i] > 0 ) {
2065 if(xp[i] >= neededxp[i]) {
2066 new playerlevelOld = playerlevel[i];
2067 playerlevel[i] = scxpm_calc_lvl(xp[i]);
2068 skillpoints[i] += playerlevel[i] - playerlevelOld;
2069 scxpm_calcneedxp(i);
2070
2071 new name[32];
2072 get_user_name( i, name, 31 );
2073 if ( playerlevel[i] == 1800 )
2074 {
2075 client_print(0,print_chat,"[SCXPM] Everyone say ^"Congratulations!!!^" to %s, who has reached Level 1800!",name)
2076 log_amx("[SCXPM] Player %s reached level 1800!", name );
2077 }
2078 else
2079 {
2080 client_print(i,print_chat,"[SCXPM] Congratulations, %s, you are now Level %i - Next Level: %i XP - Needed: %i XP",name,playerlevel[i],neededxp[i],neededxp[i]-xp[i])
2081 log_amx("[SCXPM] Player %s reached level %i!", name, playerlevel[i] );
2082 }
2083 scxpm_getrank(i)
2084 SCXPMSkill(i)
2085 // just in case save the data
2086 SavePlayerData( i );
2087 }
2088 }
2089 }
2090 }
2091 }
2092 }
2093#else
2094
2095public death() {
2096 new killerId, victimId;
2097 killerId = read_data(1);
2098 victimId = read_data(2);
2099 /*
2100 if ( get_pcvar_num( pcvar_debug ) == 1 )
2101 {
2102 new nickname[35];
2103 server_print( "[SCXPM DEBUG] death is triggered." );
2104 server_print( "[SCXPM DEBUG] killerId: %d",killerId );
2105
2106 get_user_name( killerId, nickname, 34 );
2107 server_print( "[SCXPM DEBUG] killer name: %s", nickname );
2108
2109 server_print( "[SCXPM DEBUG] victimId: %d",victimId );
2110 get_user_name( victimId, nickname, 34 );
2111 server_print( "[SCXPM DEBUG] victim name: %s", nickname );
2112 }
2113 */
2114
2115 if (killerId < 1 || victimId < 1 || !is_user_connected(killerId) || killerId == victimId) {
2116 if ( get_pcvar_num( pcvar_debug ) == 1 )
2117 {
2118 log_amx("[SCXPM DEBUG] Suicide or invalid killer/victim, dont award xp for kill");
2119 }
2120 return PLUGIN_HANDLED;
2121 }
2122
2123 if ( playerlevel[killerId] < get_pcvar_num( pcvar_maxlevel ) ) {
2124 scxpm_kill( killerId );
2125 }
2126
2127 return PLUGIN_HANDLED;
2128}
2129
2130public scxpm_kill( id ) {
2131 xp[id] += floatround( 5.0 * get_pcvar_float( pcvar_xpgain ) );
2132 if ( get_pcvar_num( pcvar_save_frequent ) == 1 )
2133 {
2134 SavePlayerData( id );
2135 }
2136 scxpm_calcneedxp(id);
2137 if( neededxp[id] > 0 )
2138 {
2139 if( xp[id] >= neededxp[id] )
2140 {
2141 new playerlevelOld = playerlevel[id];
2142 playerlevel[id] = scxpm_calc_lvl( xp[id] );
2143 skillpoints[id] += playerlevel[id] - playerlevelOld;
2144 scxpm_calcneedxp( id );
2145
2146 new name[64];
2147 get_user_name( id, name, 63 );
2148 if ( playerlevel[id] == 1800 )
2149 {
2150 client_print(0,print_chat,"[SCXPM] Everyone say ^"Congratulations!!!^" to %s, who has reached Level 1800!",name)
2151 log_amx("[SCXPM] Player %s reached level 1800!", name );
2152 }
2153 else
2154 {
2155 client_print(id,print_chat,"[SCXPM] Congratulations, %s, you are now Level %i - Next Level: %i XP - Needed: %i XP",name,playerlevel[id],neededxp[id],neededxp[id]-xp[id])
2156 log_amx("[SCXPM] Player %s reached level %i!", name, playerlevel[id] );
2157 }
2158 scxpm_getrank( id );
2159 SCXPMSkill( id );
2160 // just in case save the data
2161 SavePlayerData( id );
2162 }
2163 }
2164}
2165#endif
2166// show players data
2167public scxpm_showdata() {
2168 new iPlayers[32],iNum
2169 get_players(iPlayers,iNum)
2170 for(new g=0;g<iNum;g++)
2171 {
2172 new i=iPlayers[g]
2173 if(is_user_connected(i))
2174 {
2175 set_hudmessage(50,135,180,0.5,0.04,0,1.0,255.0,0.0,0.0,get_pcvar_num(pcvar_hud_channel))
2176 //set_hudmessage(50,135,180,-1.0,0.04,0,1.0,255.0,0.0,0.0,get_pcvar_num(pcvar_hud_channel))
2177 switch(playerlevel[i])
2178 {
2179 case 1800:
2180 {
2181 show_hudmessage(i,"Level: 1800 / 1800^nRank: Highest Force Leader^nMedals: %i / 15^nHealth: %i^nArmor: %i", medals[i]-1, get_user_health( i ), get_user_armor( i ) )
2182 }
2183 default:
2184 {
2185 if ( get_user_health( i ) > 250 || get_user_armor( i ) > 250)
2186 {
2187 show_hudmessage(i,"Exp.: %i / %i (+%i)^nLevel: %i / 1800^nRank: %s^nMedals: %i / 15^nHealth: %i^nArmor: %i", xp[i],neededxp[i],neededxp[i]-xp[i],playerlevel[i], ranks[rank[i]] ,medals[i]-1, get_user_health( i ), get_user_armor( i ) )
2188 }
2189 else
2190 {
2191 show_hudmessage(i,"Exp.: %i / %i (+%i)^nLevel: %i / 1800^nRank: %s^nMedals: %i / 15", xp[i],neededxp[i],neededxp[i]-xp[i],playerlevel[i], ranks[rank[i]],medals[i]-1 )
2192 }
2193 }
2194 }
2195
2196 if (playerlevel[i] >= 1800) {
2197 show_hudmessage(i,"Level: 1800 / 1800^nRank: Highest Force Leader^nMedals: %i / 15^nHealth: %i^nArmor: %i", medals[i]-1, get_user_health( i ), get_user_armor( i ) )
2198 }
2199 else if ( playerlevel[i] >= get_pcvar_num( pcvar_maxlevel ) ) {
2200 if ( get_user_health( i ) > 250 || get_user_armor( i ) > 250)
2201 {
2202 show_hudmessage(i,"Exp.: %i^nLevel: %i / %i^nRank: %s^nMedals: %i / 15^nHealth: %i^nArmor: %i", xp[i],playerlevel[i],get_pcvar_num( pcvar_maxlevel ),ranks[rank[i]],medals[i]-1, get_user_health( i ), get_user_armor( i ) )
2203 }
2204 else
2205 {
2206 show_hudmessage(i,"Exp.: %i^nLevel: %i / %i^nRank: %s^nMedals: %i / 15", xp[i],playerlevel[i],get_pcvar_num( pcvar_maxlevel ),ranks[rank[i]],medals[i]-1 )
2207 }
2208 }
2209 else {
2210 if ( get_user_health( i ) > 250 || get_user_armor( i ) > 250)
2211 {
2212 show_hudmessage(i,"Exp.: %i / %i (+%i)^nLevel: %i / %i^nRank: %s^nMedals: %i / 15^nHealth: %i^nArmor: %i", xp[i],neededxp[i],neededxp[i]-xp[i],playerlevel[i],get_pcvar_num( pcvar_maxlevel ),ranks[rank[i]],medals[i]-1, get_user_health( i ), get_user_armor( i ) )
2213 }
2214 else
2215 {
2216 show_hudmessage(i,"Exp.: %i / %i (+%i)^nLevel: %i / %i^nRank: %s^nMedals: %i / 15", xp[i],neededxp[i],neededxp[i]-xp[i],playerlevel[i],get_pcvar_num( pcvar_maxlevel ),ranks[rank[i]],medals[i]-1 )
2217 }
2218 }
2219 }
2220 }
2221}
2222
2223// show skill calculation
2224public SCXPMSkill( id ) {
2225 // the default value for the increment is 1
2226 skillIncrement[id] = 1;
2227
2228 if (skillpoints[id] > 20) {
2229 SCXPMIncrementMenu( id );
2230 }
2231 else {
2232 SCXPMSkillMenu( id );
2233 }
2234}
2235
2236// show the skills menu
2237public SCXPMSkillMenu( id ) {
2238 new menuBody[1024];
2239 format(menuBody,1023,"Select Skills - Skillpoints available: %i^n^n^n^n 1. Strength [ %i / 450 ]^n^n 2. Superior Armor [ %i / 450 ]^n^n 3. Health Regeneration [ %i / 300 ]^n^n 4. Nano Armor [ %i / 300 ]^n^n 5. Ammo Reincarnation [ %i / 30 ]^n^n 6. Anti Gravity Device [ %i / 40 ]^n^n 7. Awareness [ %i / 80 ]^n^n 8. Team Power [ %i / 60 ]^n^n 9. Block Attack [ %i / 90 ]^n^n^n 0. Done"
2240 ,skillpoints[id],health[id],armor[id],rhealth[id],rarmor[id],rammo[id],gravity[id],speed[id],dist[id],dodge[id]);
2241 show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),menuBody,13,"Select Skill");
2242}
2243
2244// show the increment menu
2245public SCXPMIncrementMenu( id ) {
2246 new menuBody[1024];
2247 if (skillpoints[id] >= 20 && skillpoints[id] < 50) {
2248 format(menuBody,1023,"Increment your skill with^n^n^n^n1. 1 point^n^n2. 5 points^n^n3. 10 points^n^n4. 25 points");
2249 }
2250 else if (skillpoints[id] >= 50 && skillpoints[id] < 100) {
2251 format(menuBody,1023,"Increment your skill with^n^n^n^n1. 1 point^n^n2. 5 points^n^n3. 10 points^n^n4. 25 points^n^n5. 50 points");
2252 }
2253 else if (skillpoints[id] >= 100) {
2254 format(menuBody,1023,"Increment your skill with^n^n^n^n1. 1 point^n^n2. 5 points^n^n3. 10 points^n^n4. 25 points^n^n5. 50 points^n^n6. 100 points");
2255 }
2256 show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5),menuBody,13,"Select Increment");
2257}
2258
2259public SCXPMIncrementChoice( id, key ) {
2260 switch(key){
2261 case 0: {
2262 skillIncrement[id] = 1;
2263 }
2264 case 1: {
2265 skillIncrement[id] = 5;
2266 }
2267 case 2: {
2268 skillIncrement[id] = 10;
2269 }
2270 case 3: {
2271 skillIncrement[id] = 25;
2272 }
2273 case 4: {
2274 skillIncrement[id] = 50;
2275 }
2276 case 5: {
2277 skillIncrement[id] = 100;
2278 }
2279 }
2280 SCXPMSkillMenu( id );
2281}
2282// choose a skill
2283public SCXPMSkillChoice( id, key ) {
2284 switch(key)
2285 {
2286 case 0:
2287 {
2288 if(skillpoints[id]>0)
2289 {
2290 if(health[id]<450)
2291 {
2292 if (skillIncrement[id] + health[id] >= 450) {
2293 skillIncrement[id] = 450 - health[id];
2294 }
2295 skillpoints[id] -= skillIncrement[id];
2296 health[id] += skillIncrement[id];
2297 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Strength to Level %i!",skillIncrement[id],health[id]);
2298 if(is_user_alive(id))
2299 {
2300 set_user_health(id, get_user_health(id) + skillIncrement[id]);
2301 }
2302 }
2303 else
2304 {
2305 client_print(id,print_chat,"[SCXPM] You have mastered your Strength already.")
2306 }
2307 if(skillpoints[id]>0)
2308 {
2309 SCXPMSkill(id);
2310 }
2311 }
2312 else
2313 {
2314 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Strength.")
2315 }
2316 }
2317 case 1:
2318 {
2319 if(skillpoints[id]>0)
2320 {
2321 if(armor[id]<450)
2322 {
2323 if (skillIncrement[id] + armor[id] >= 450) {
2324 skillIncrement[id] = 450 - armor[id];
2325 }
2326
2327 skillpoints[id]-= skillIncrement[id];
2328 armor[id] += skillIncrement[id];
2329 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Armor to Level %i!",skillIncrement[id],armor[id]);
2330 if(is_user_alive(id))
2331 {
2332 set_user_armor(id,get_user_armor(id)+skillIncrement[id]);
2333 }
2334 }
2335 else
2336 {
2337 client_print(id,print_chat,"[SCXPM] You have mastered your Armor already.")
2338 }
2339 if(skillpoints[id]>0)
2340 {
2341 SCXPMSkill(id)
2342 }
2343 }
2344 else
2345 {
2346 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Armor.")
2347 }
2348 }
2349 case 2:
2350 {
2351 if(skillpoints[id]>0)
2352 {
2353 if(rhealth[id]<300)
2354 {
2355 if (skillIncrement[id] + rhealth[id] >= 300) {
2356 skillIncrement[id] = 300 - rhealth[id];
2357 }
2358
2359 skillpoints[id] -= skillIncrement[id];
2360 rhealth[id] += skillIncrement[id];
2361 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Regeneration to Level %i!",skillIncrement[id],rhealth[id])
2362 }
2363 else
2364 {
2365 client_print(id,print_chat,"[SCXPM] You have mastered your Regeneration already.")
2366 }
2367 if(skillpoints[id]>0)
2368 {
2369 SCXPMSkill(id)
2370 }
2371 }
2372 else
2373 {
2374 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Regeneration.")
2375 }
2376 }
2377 case 3:
2378 {
2379 if(skillpoints[id]>0)
2380 {
2381 if(rarmor[id]<300)
2382 {
2383 if (skillIncrement[id] + rarmor[id] >= 300) {
2384 skillIncrement[id] = 300 - rarmor[id];
2385 }
2386
2387 skillpoints[id] -= skillIncrement[id];
2388 rarmor[id] += skillIncrement[id];
2389 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoint to enhance your Nano Armor to Level %i!",skillIncrement[id],rarmor[id]);
2390 }
2391 else
2392 {
2393 client_print(id,print_chat,"[SCXPM] You have mastered your Nano Armor already.")
2394 }
2395 if(skillpoints[id]>0)
2396 {
2397 SCXPMSkill(id)
2398 }
2399 }
2400 else
2401 {
2402 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Nano Armor.")
2403 }
2404 }
2405 case 4:
2406 {
2407 if(skillpoints[id]>0)
2408 {
2409 if(rammo[id]<30)
2410 {
2411 if (skillIncrement[id] + rammo[id] >= 30) {
2412 skillIncrement[id] = 30 - rammo[id];
2413 }
2414
2415 skillpoints[id] -= skillIncrement[id];
2416 rammo[id] += skillIncrement[id];
2417 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Ammo Reincarnation to Level %i!",skillIncrement[id],rammo[id]);
2418 }
2419 else
2420 {
2421 client_print(id,print_chat,"[SCXPM] You have mastered your Ammo Reincarnation already.")
2422 }
2423 if(skillpoints[id]>0)
2424 {
2425 SCXPMSkill(id)
2426 }
2427 }
2428 else
2429 {
2430 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Ammo Reincarnation.")
2431 }
2432 }
2433 case 5:
2434 {
2435 if(skillpoints[id]>0)
2436 {
2437 if(gravity[id]<40)
2438 {
2439 if (skillIncrement[id] + gravity[id] >= 40) {
2440 skillIncrement[id] = 40 - gravity[id];
2441 }
2442
2443 skillpoints[id] -= skillIncrement[id];
2444 gravity[id] += skillIncrement[id];
2445 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Anti Gravity Device to Level %i!",skillIncrement[id],gravity[id]);
2446 }
2447 else
2448 {
2449 client_print(id,print_chat,"[SCXPM] You have mastered your Anti Gravity Device already.")
2450 }
2451 if(skillpoints[id]>0)
2452 {
2453 SCXPMSkill(id)
2454 }
2455 }
2456 else
2457 {
2458 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Anti Gravity Device.")
2459 }
2460 }
2461 case 6:
2462 {
2463 if(skillpoints[id]>0)
2464 {
2465 if(speed[id]<80)
2466 {
2467 if (skillIncrement[id] + speed[id] >= 80) {
2468 skillIncrement[id] = 80 - speed[id];
2469 }
2470
2471 skillpoints[id] -= skillIncrement[id];
2472 speed[id] += skillIncrement[id];
2473 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Awareness to Level %i!",skillIncrement[id],speed[id])
2474 }
2475 else
2476 {
2477 client_print(id,print_chat,"[SCXPM] You have mastered your Awareness already.")
2478 }
2479 if(skillpoints[id]>0)
2480 {
2481 SCXPMSkill(id)
2482 }
2483 }
2484 else
2485 {
2486 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Awareness.")
2487 }
2488 }
2489 case 7:
2490 {
2491 if(skillpoints[id]>0)
2492 {
2493 if(dist[id]<60)
2494 {
2495 if (skillIncrement[id] + dist[id] >= 60) {
2496 skillIncrement[id] = 60 - dist[id];
2497 }
2498
2499 skillpoints[id] -= skillIncrement[id];
2500 dist[id] += skillIncrement[id];
2501 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoints to enhance your Team Power to Level %i!",skillIncrement[id],dist[id])
2502 }
2503 else
2504 {
2505 client_print(id,print_chat,"[SCXPM] You have mastered your Team Power already.")
2506 }
2507 if(skillpoints[id]>0)
2508 {
2509 SCXPMSkill(id)
2510 }
2511 }
2512 else
2513 {
2514 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Team Power.")
2515 }
2516 }
2517 case 8:
2518 {
2519 if(skillpoints[id]>0)
2520 {
2521 if(dodge[id]<90)
2522 {
2523 if (skillIncrement[id] + dodge[id] >= 90) {
2524 skillIncrement[id] = 90 - dodge[id];
2525 }
2526
2527 skillpoints[id] -= skillIncrement[id];
2528 dodge[id] += skillIncrement[id];
2529 client_print(id,print_chat,"[SCXPM] You spent %i Skillpoint to enhance your Dodging and Blocking Skills to Level %i!",skillIncrement[id],dodge[id]);
2530 }
2531 else
2532 {
2533 client_print(id,print_chat,"[SCXPM] You have mastered your Dodging and Blocking Skills already.")
2534 }
2535 if(skillpoints[id]>0)
2536 {
2537 SCXPMSkill(id)
2538 }
2539 }
2540 else
2541 {
2542 client_print(id,print_chat,"[SCXPM] You need one Skillpoint for enhancing your Dodgin and Blocking Skills.")
2543 }
2544 }
2545 case 9:
2546 {
2547
2548 }
2549 }
2550 return PLUGIN_HANDLED;
2551}
2552
2553//
2554// save and load
2555//
2556
2557// load player data
2558public LoadPlayerData( id )
2559{
2560 new save = get_pcvar_num( pcvar_save );
2561 new debug_on = get_pcvar_num( pcvar_debug );
2562
2563 if (plugin_ended == false) {
2564 if ( debug_on ){
2565 new nickname[35];
2566 get_user_name( id, nickname, 34 );
2567 log_amx( "[SCXPM DEBUG] Loading data for: %s", nickname );
2568 }
2569 // 0 = no saved data
2570 if ( save <= 0 ){
2571 LoadEmptySkills( id );
2572 }else if ( save == 1 ){
2573 scxpm_loadxp_file( id );
2574 }else if ( save >= 2 ){
2575 if ( !dbc ) sql_init();
2576 scxpm_loadxp_mysql( id );
2577 }else{
2578 if ( debug_on ){
2579 new nickname[35];
2580 get_user_name( id, nickname, 34 );
2581 log_amx( "[SCXPM DEBUG] Data already loaded, don't load data for: %s", nickname );
2582 }
2583 }
2584 }
2585 else {
2586 if ( debug_on ){
2587 log_amx( "[SCXPM DEBUG] Plugin already ended, don't load data" );
2588 }
2589 }
2590}
2591
2592// save player data
2593public SavePlayerData( id ) {
2594 new save = get_pcvar_num( pcvar_save );
2595 new debug_on = get_pcvar_num( pcvar_debug );
2596
2597 if ( save == 0 ) return PLUGIN_CONTINUE;
2598
2599 if (plugin_ended == false) {
2600 if (is_player_flag_set(loaddata,id)) {
2601 if (xp[id] >= 0) {
2602 //loaddata[id] = false;
2603 if ( debug_on ){
2604 new nickname[35];
2605 get_user_name( id, nickname, 34 );
2606 log_amx( "[SCXPM DEBUG] Saving data for: %s", nickname );
2607 }
2608 // 0 = will not be saved
2609 // 1 = save to file
2610 // 2 = save to mysql
2611 if ( save == 1 ){
2612 scxpm_savexp_file( id );
2613 }else{
2614 if ( !dbc ) sql_init();
2615 scxpm_savexp_mysql( id );
2616 }
2617 }
2618 else {
2619 if ( debug_on ){
2620 new nickname[35];
2621 get_user_name( id, nickname, 34 );
2622 log_amx( "[SCXPM DEBUG] xp lower than 0, don't save data for: %s", nickname );
2623 }
2624 }
2625 }
2626 else {
2627 if ( debug_on ){
2628 new nickname[35];
2629 get_user_name( id, nickname, 34 );
2630 log_amx( "[SCXPM DEBUG] Data not loaded, don't save data for: %s", nickname );
2631 }
2632 }
2633 }
2634 else {
2635 if ( debug_on){
2636 log_amx( "[SCXPM DEBUG] Plugin already ended, don't save data" );
2637 }
2638 }
2639
2640 return PLUGIN_CONTINUE;
2641}
2642
2643// load player data from file
2644public scxpm_loadxp_file( id ) {
2645 new savestyle = get_pcvar_num(pcvar_savestyle);
2646
2647 new authid[35];
2648 switch(savestyle){
2649 case 0 : {
2650 get_user_authid(id, authid, 34)
2651 if ( containi(authid,"STEAM_ID_PENDING") !=-1 ){
2652 LoadEmptySkills( id )
2653 return PLUGIN_CONTINUE;
2654 }
2655 }
2656 case 1 : {
2657 get_user_ip(id, authid, 34, 1)
2658 }
2659 case 2 : {
2660 get_user_name(id, authid, 34)
2661 }
2662 }
2663
2664 new vaultkey[64], vaultdata[96];
2665 format(vaultkey,63,"%s-scxpm",authid);
2666 if ( vaultdata_exists(vaultkey) )
2667 {
2668 get_vaultdata(vaultkey,vaultdata,95);
2669 replace_all(vaultdata,95,"#"," ");
2670 new pre_xp[16],pre_playerlevel[8],pre_skillpoints[8],pre_medals[8],pre_health[8],pre_armor[8],pre_rhealth[8],pre_rarmor[8],pre_rammo[8],pre_gravity[8],pre_speed[8],pre_dist[8],pre_dodge[8];
2671 parse(vaultdata,pre_xp,15,pre_playerlevel,7,pre_skillpoints,7,pre_medals,7,pre_health,7,pre_armor,7,pre_rhealth,7,pre_rarmor,7,pre_rammo,7,pre_gravity,7,pre_speed,7,pre_dist,7,pre_dodge,7);
2672 xp[id] = str_to_num(pre_xp);
2673 playerlevel[id] = str_to_num(pre_playerlevel);
2674 scxpm_calcneedxp(id);
2675 scxpm_getrank(id);
2676 skillpoints[id] = str_to_num(pre_skillpoints);
2677 medals[id] = str_to_num(pre_medals);
2678 health[id] = str_to_num(pre_health);
2679 armor[id] = str_to_num(pre_armor);
2680 rhealth[id] = str_to_num(pre_rhealth);
2681 rarmor[id] = str_to_num(pre_rarmor);
2682 rammo[id] = str_to_num(pre_rammo);
2683 gravity[id] = str_to_num(pre_gravity);
2684 speed[id] = str_to_num(pre_speed);
2685 dist[id] = str_to_num(pre_dist);
2686 dodge[id] = str_to_num(pre_dodge);
2687 }
2688 else
2689 {
2690 log_amx("[SCXPM] Start from level 0");
2691 LoadEmptySkills( id );
2692 }
2693 set_player_flag(loaddata, id);
2694 return PLUGIN_CONTINUE;
2695}
2696
2697// save player data to file
2698public scxpm_savexp_file( id ) {
2699 new savestyle = get_pcvar_num(pcvar_savestyle);
2700
2701 new authid[35];
2702 switch(savestyle){
2703 case 0 : {
2704 get_user_authid( id, authid, 34 );
2705 if ( containi(authid,"STEAM_ID_PENDING") !=-1 ){
2706 return PLUGIN_CONTINUE;
2707 }
2708 }
2709 case 1 : {
2710 get_user_ip( id, authid, 34, 1 );
2711 }
2712 case 2 : {
2713 get_user_name( id, authid, 34 );
2714 }
2715 }
2716 new vaultkey[64], vaultdata[96];
2717 format( vaultkey, 63, "%s-scxpm", authid );
2718 format( vaultdata, 95, "%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i",xp[id],playerlevel[id],skillpoints[id],medals[id],health[id],armor[id],rhealth[id],rarmor[id],rammo[id],gravity[id],speed[id],dist[id],dodge[id]);
2719 set_vaultdata( vaultkey, vaultdata );
2720 return PLUGIN_CONTINUE;
2721}
2722
2723// save player data to a database
2724public scxpm_savexp_mysql( id ) {
2725 new savestyle = get_pcvar_num(pcvar_savestyle);
2726
2727 new authid[35];
2728 new ip[35];
2729 new nickname[128];
2730 new where_statement[1024];
2731
2732 get_user_authid(id, authid, 34);
2733 get_user_ip(id, ip, 34, 1);
2734 get_user_name(id, nickname, 63);
2735
2736 if ( equali(ip, "") || equali(nickname, "") ) {
2737 if ( get_pcvar_num( pcvar_debug ) == 1 )
2738 {
2739 log_amx( "[SCXPM DEBUG] Empty ip or nickname, don't save data." );
2740 }
2741 return PLUGIN_CONTINUE;
2742 }
2743
2744 replace_all(nickname,127,"'","\'"); //avoiding sql errors with ' in name
2745
2746 switch(savestyle){
2747 case 0 : {
2748 if ( containi(authid,"STEAM_ID_PENDING") !=-1 || equali(authid, "") ){
2749 if ( get_pcvar_num( pcvar_debug ) == 1 ){
2750 log_amx( "[SCXPM DEBUG] Empty or invalid steamid, don't save data." );
2751 }
2752 return PLUGIN_CONTINUE;
2753 }
2754 formatex( g_Cache, 1023, QUERY_UPDATE_SKILLS, sql_table, authid, authid, nickname, ip, xp[id], playerlevel[id], skillpoints[id], medals[id], health[id], armor[id], rhealth[id], rarmor[id], rammo[id], gravity[id], speed[id], dist[id], dodge[id], where_statement );
2755 }
2756 case 1 : {
2757 formatex( g_Cache, 1023, QUERY_UPDATE_SKILLS, sql_table, ip, authid, nickname, ip, xp[id], playerlevel[id], skillpoints[id], medals[id], health[id], armor[id], rhealth[id], rarmor[id], rammo[id], gravity[id], speed[id], dist[id], dodge[id], where_statement );
2758 }
2759 case 2 : {
2760 formatex( g_Cache, 1023, QUERY_UPDATE_SKILLS, sql_table, nickname, authid, nickname, ip, xp[id], playerlevel[id], skillpoints[id], medals[id], health[id], armor[id], rhealth[id], rarmor[id], rammo[id], gravity[id], speed[id], dist[id], dodge[id], where_statement );
2761 }
2762 }
2763 SQL_ThreadQuery( dbc, "QueryHandle", g_Cache );
2764 return PLUGIN_CONTINUE;
2765}
2766
2767// load player data from a database
2768public scxpm_loadxp_mysql( id ) {
2769 new savestyle = get_pcvar_num(pcvar_savestyle);
2770
2771 if (get_pcvar_num(pcvar_debug) == 1)
2772 {
2773 log_amx( "[SCXPM DEBUG] Entered public scxpm_loadxp_mysql( id )" );
2774 }
2775
2776 new where_statement[1024];
2777 new authid[35];
2778 new ip[35];
2779 new nickname[128];
2780
2781 get_user_authid( id, authid, 34 );
2782 get_user_ip( id, ip, 34, 1 );
2783 get_user_name( id, nickname, 63 );
2784
2785 replace_all(nickname,127,"'","\'"); //avoiding sql errors with ' in name
2786
2787 switch(savestyle){
2788 case 0 : {
2789 if ( containi(authid,"STEAM_ID_PENDING") !=-1 || equali(authid, "") ){
2790 LoadEmptySkills( id );
2791 return PLUGIN_CONTINUE;
2792 }
2793 format(where_statement, 199, "`uniqueid` = '%s'", authid);
2794 }
2795 case 1 : {
2796 format(where_statement, 49, "`uniqueid` = '%s'", ip);
2797 }
2798 case 2 : {
2799 format(where_statement, 199, "`uniqueid` = '%s'", nickname);
2800 }
2801 }
2802
2803 formatex( g_Cache, 1023, QUERY_SELECT_SKILLS, sql_table, where_statement);
2804
2805 new send_id[1];
2806 send_id[0] = id;
2807
2808 SQL_ThreadQuery( dbc, "LoadDataHandle", g_Cache, send_id, 1 );
2809 return PLUGIN_CONTINUE;
2810}
2811
2812//
2813// sql handles
2814//
2815
2816// handle default queries
2817public QueryHandle( FailState, Handle:Query, Error[], Errcode, Data[], DataSize ) {
2818 new debug_on = get_pcvar_num( pcvar_debug );
2819
2820 if (debug_on) {
2821 log_amx( "[SCXPM DEBUG] Begin QueryHandle" );
2822 new sql[1024];
2823 SQL_GetQueryString ( Query, sql, 1024 );
2824 log_amx( "[SCXPM DEBUG] executed query: %s", sql );
2825 }
2826
2827 // lots of error checking
2828 if ( FailState == TQUERY_CONNECT_FAILED ) {
2829 log_amx( "[SCXPM SQL] Could not connect to SQL database." );
2830 return set_fail_state("[SCXPM SQL] Could not connect to SQL database.");
2831 }
2832 else if ( FailState == TQUERY_QUERY_FAILED ) {
2833 new sql[1024];
2834 SQL_GetQueryString ( Query, sql, 1024 );
2835 log_amx( "[SCXPM SQL] SQL Query failed: %s", sql );
2836 return set_fail_state("[SCXPM SQL] SQL Query failed.");
2837 }
2838
2839 if ( Errcode ) {
2840 return log_amx( "[SCXPM SQL] SQL Error on query: %s", Error );
2841 }
2842
2843 if ( debug_on ) {
2844 log_amx( "[SCXPM DEBUG] End QueryHandle" );
2845 }
2846 return PLUGIN_CONTINUE;
2847}
2848
2849// check if table exist
2850public ShowTableHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
2851 new debug_on = get_pcvar_num( pcvar_debug );
2852
2853 if (debug_on) {
2854 log_amx("[SCXPM DEBUG] Begin ShowTableHandle");
2855 new sql[1024];
2856 SQL_GetQueryString ( Query, sql, 1024 );
2857 log_amx( "[SCXPM DEBUG] executed query: %s", sql );
2858 }
2859
2860 if(FailState==TQUERY_CONNECT_FAILED){
2861 log_amx( "[SCXPM SQL] Could not connect to SQL database." );
2862 log_amx( "[SCXPM SQL] Switching to: scxpm_save 0" );
2863 log_amx( "[SCXPM SQL] Stats won't be saved" );
2864 set_pcvar_num ( pcvar_save, 0 );
2865 return PLUGIN_CONTINUE;
2866 }
2867 else if (FailState == TQUERY_QUERY_FAILED) {
2868 log_amx( "[SCXPM SQL] Query failed." );
2869 log_amx( "[SCXPM SQL] Switching to: scxpm_save 0" );
2870 log_amx( "[SCXPM SQL] Stats won't be saved" );
2871 set_pcvar_num ( pcvar_save, 0 );
2872 return PLUGIN_CONTINUE;
2873 }
2874
2875 if (Errcode) {
2876 log_amx( "[SCXPM SQL] Error on query: %s", Error );
2877 log_amx( "[SCXPM SQL] Switching to: scxpm_save 0" );
2878 log_amx( "[SCXPM SQL] Stats won't be saved" );
2879 set_pcvar_num ( pcvar_save, 0 );
2880 return PLUGIN_CONTINUE;
2881 }
2882
2883 if (SQL_NumResults(Query) > 0) {
2884 if (get_pcvar_num( pcvar_debug ) == 1 )
2885 {
2886 log_amx( "[SCXPM DEBUG] Database table found: %s", sql_table );
2887 }
2888 }
2889 else {
2890 log_amx( "[SCXPM SQL] Could not find the table: %s", sql_table );
2891 log_amx( "[SCXPM SQL] Switching to: scxpm_save 0" );
2892 log_amx( "[SCXPM SQL] Stats won't be saved" );
2893 set_pcvar_num ( pcvar_save, 0 );
2894 }
2895
2896 if (debug_on){
2897 log_amx( "[SCXPM DEBUG] End ShowTableHandle" );
2898 }
2899 return PLUGIN_CONTINUE;
2900}
2901
2902// load player data
2903public LoadDataHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
2904 new debug_on = get_pcvar_num( pcvar_debug );
2905
2906 if (debug_on){
2907 log_amx( "[SCXPM DEBUG] Begin LoadDataHandle" );
2908 new sql[1024];
2909 SQL_GetQueryString ( Query, sql, 1024 );
2910 log_amx( "[SCXPM DEBUG] executed query: %s", sql );
2911 }
2912 if (FailState == TQUERY_CONNECT_FAILED) {
2913 return set_fail_state("Could not connect to SQL database.")
2914 }else if (FailState == TQUERY_QUERY_FAILED){
2915 return set_fail_state("Query failed.")
2916 }
2917
2918 if (Errcode){
2919 return log_amx("Error on query: %s",Error)
2920 }
2921
2922 new id = Data[0];
2923
2924 set_player_flag(loaddata, id);
2925
2926 if (SQL_NumResults(Query) >= 1) {
2927 if (SQL_NumResults(Query) > 1) {
2928 if (get_pcvar_num( pcvar_debug ) == 1 ) {
2929 log_amx( "[SCXPM DEBUG] more than one entry found. just take the first one" );
2930 }
2931 }
2932 xp[id] = SQL_ReadResult(Query, 0) ;
2933 playerlevel[id] = SQL_ReadResult(Query, 1);
2934 scxpm_calcneedxp( id );
2935 scxpm_getrank( id );
2936 skillpoints[id] = SQL_ReadResult( Query, 2 );
2937 medals[id] = SQL_ReadResult(Query, 3);
2938 health[id] = SQL_ReadResult(Query, 4);
2939 armor[id] = SQL_ReadResult(Query, 5);
2940 rhealth[id] = SQL_ReadResult(Query, 6);
2941 rarmor[id] = SQL_ReadResult(Query, 7);
2942 rammo[id] = SQL_ReadResult(Query, 8);
2943 gravity[id] = SQL_ReadResult(Query, 9);
2944 speed[id] = SQL_ReadResult(Query, 10);
2945 dist[id] = SQL_ReadResult(Query, 11);
2946 dodge[id] = SQL_ReadResult(Query, 12);
2947 }
2948 else if (SQL_NumResults(Query) < 1){
2949 // load empty skills, the skills will be saved later on
2950 LoadEmptySkills( id );
2951 }
2952
2953 if (debug_on){
2954 log_amx( "[SCXPM DEBUG] End LoadDataHandle" );
2955 }
2956 return PLUGIN_CONTINUE;
2957}
2958/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
2959*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1031\\ f0\\ fs16 \n\\ par }
2960*/