Advertisement
Guest User

r

a guest
Feb 4th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.94 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <nvault>
  3. #include <amxmisc>
  4. #include <csx>
  5. #include <engine>
  6. #include <fakemeta>
  7.  
  8. new const PLUGIN [] = "Money"
  9. new const VERSION [] = "0.3"
  10. new const AUTHOR [] = "Aknamal"
  11.  
  12. new cvs[8];
  13.  
  14. new xmoney[33];
  15.  
  16. new Data[64];
  17.  
  18. new toplevels[33];
  19. new topnames[33][33];
  20.  
  21.  
  22. enum Color
  23. {
  24.     NORMAL = 1, // clients scr_concolor cvar color
  25.     YELLOW = 1, // NORMAL alias
  26.     GREEN, // Green Color
  27.     TEAM_COLOR, // Red, grey, blue
  28.     GREY, // grey
  29.     RED, // Red
  30.     BLUE, // Blue
  31. }
  32.  
  33. new TeamName[][] =
  34. {
  35.     "",
  36.     "TERRORIST",
  37.     "CT",  
  38.     "SPECTATOR"
  39. }
  40.  
  41. new p_vault;
  42.  
  43. public plugin_init()
  44. {
  45.     register_plugin(PLUGIN,VERSION,AUTHOR)
  46.  
  47.     register_event("TextMsg", "bomb_planted", "a", "2&%!MRAD_BOMBPL")
  48.     register_event("TextMsg", "bomb_defused", "a", "2&%!MRAD_BOMBDEF")
  49.     register_event("TextMsg", "bomb_explode", "a", "2&#Target_B")
  50.  
  51.     register_event("DeathMsg", "hk_die", "a");
  52.     p_vault = nvault_open("money_vault");
  53.  
  54.     cvs[0] = register_cvar("money_plant","3000");
  55.     cvs[1] = register_cvar("money_defuse","5000");
  56.     cvs[2] = register_cvar("money_explode","10000");
  57.     cvs[3] = register_cvar("money_lost","1");
  58.     cvs[4] = register_cvar("money_lost_value","800");
  59.     cvs[5] = register_cvar("money_hs","4500");
  60.     cvs[6] = register_cvar("money_kill","2000");
  61.     cvs[7] = register_cvar("money_knife","500");
  62.  
  63.     register_clcmd("say /bani","xBani");
  64.     register_clcmd("say_team /bani","xBani");
  65.  
  66.         register_clcmd("say /topbani","sayTopLevel");
  67.         register_clcmd("say_team /topbani","sayTopLevel");
  68.  
  69.     register_concmd("amx_bani", "b_cmd", ADMIN_LEVEL_H, "amx_bani <NICK> <NUMARUL DE LEVEL>")
  70.         register_concmd("amx_resetbani","concmdReset_Top");
  71.  
  72.         register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged")
  73.  
  74.         get_datadir(Data, 63);
  75.         read_top();
  76. }
  77.  
  78. public xBani(id)
  79. {
  80.     ColorChat(id, TEAM_COLOR, "^1[ ^4BANI^1 ] Ai ^3%i^1 $ !",xmoney[id]);
  81.     return 1
  82. }
  83.  
  84. public b_cmd(id,level,cid)
  85. {
  86.     if(!cmd_access(id,level,cid,3))
  87.         return PLUGIN_HANDLED;
  88.    
  89.     new arg[33], amount[220]
  90.     read_argv(1, arg, 32)
  91.     new target = cmd_target(id, arg, 7)
  92.     read_argv(2, amount, charsmax(amount) - 1)
  93.    
  94.     new exp = str_to_num(amount)
  95.    
  96.     if(!target)
  97.     {
  98.         return 1
  99.     }
  100.  
  101.     xmoney[target] = exp
  102.     checkandupdatetop(target,xmoney[target])
  103.     SaveData(target)
  104.     return 0
  105. }
  106.  
  107.  
  108. public plugin_natives()
  109. {
  110.     register_native("get_player_money","_get")
  111.     register_native("set_player_money","_set");
  112. }
  113.  
  114. public _get(param)
  115. {
  116.     return xmoney[get_param(1)];
  117. }
  118.  
  119. public _set(param, value)
  120. {
  121.     new id = get_param( 1 );
  122.     new value = get_param( 2 );
  123.  
  124.     if(is_user_connected(id))
  125.     {
  126.         xmoney[id] = value;
  127.         return 0
  128.     }
  129.     else
  130.     {
  131.         return 1
  132.     }
  133.     return 0
  134. }
  135.  
  136. public ClientUserInfoChanged(id)
  137. {
  138.         static const name[] = "name"
  139.         static szOldName[32], szNewName[32]
  140.         pev(id, pev_netname, szOldName, charsmax(szOldName))
  141.         if( szOldName[0] )
  142.         {
  143.                 get_user_info(id, name, szNewName, charsmax(szNewName))
  144.                 if( !equal(szOldName, szNewName) )
  145.                 {
  146.                         set_user_info(id, name, szOldName)
  147.                         return FMRES_HANDLED
  148.                 }
  149.         }
  150.         return FMRES_IGNORED
  151. }
  152.  
  153.  
  154. public save_top() {
  155.         new path[128];
  156.         formatex(path, 127, "%s/Bani.dat", Data);
  157.         if( file_exists(path) ) {
  158.                 delete_file(path);
  159.         }
  160.         new Buffer[256];
  161.         new f = fopen(path, "at");
  162.         for(new i = 0; i < 15; i++)
  163.         {
  164.                 formatex(Buffer, 255, "^"%s^" ^"%d^"^n",topnames[i],toplevels[i] );
  165.                 fputs(f, Buffer);
  166.         }
  167.         fclose(f);
  168. }
  169. public concmdReset_Top(id) {
  170.        
  171.         if( !(get_user_flags(id) & read_flags("abcdefghijklmnopqrstu"))) {
  172.                        return PLUGIN_HANDLED;
  173.         }
  174.         new path[128];
  175.         formatex(path, 127, "%s/Bani.dat", Data);
  176.         if( file_exists(path) ) {
  177.                 delete_file(path);
  178.         }        
  179.         static info_none[33];
  180.         info_none = "";
  181.         for( new i = 0; i < 15; i++ ) {
  182.                 formatex(topnames[i], 31, info_none);
  183.                 toplevels[i]= 0;
  184.         }
  185.         save_top();
  186.         new aname[32];
  187.         get_user_name(id, aname, 31);
  188.         ColorChat(0, TEAM_COLOR,"^1[^3 BANI^1 ] Adminul ^4%s^1 a resetat top bani!", aname);
  189.         return PLUGIN_CONTINUE;
  190. }
  191.  
  192. public plugin_precache() {
  193.     new Entity = create_entity("info_map_parameters");
  194.    
  195.     DispatchKeyValue(Entity, "buying", "3");
  196.     DispatchSpawn(Entity);
  197. }
  198.  
  199. public pfn_keyvalue(Entity) {
  200.     new ClassName[20], Dummy[2];
  201.     copy_keyvalue(ClassName, charsmax(ClassName), Dummy, charsmax(Dummy), Dummy, charsmax(Dummy));
  202.    
  203.     if(equal(ClassName, "info_map_parameters")) {
  204.         remove_entity(Entity);
  205.         return PLUGIN_HANDLED;
  206.     }
  207.    
  208.     return PLUGIN_CONTINUE;
  209. }
  210. public checkandupdatetop(id, levels) {        
  211.  
  212.         new name[32];
  213.         get_user_name(id, name, 31);
  214.         for (new i = 0; i < 15; i++)
  215.         {
  216.                 if( levels > toplevels[i] )
  217.                 {
  218.                         new pos = i;        
  219.                         while( !equal(topnames[pos],name) && pos < 15 )
  220.                         {
  221.                                 pos++;
  222.                         }
  223.                        
  224.                         for (new j = pos; j > i; j--)
  225.                         {
  226.                                 formatex(topnames[j], 31, topnames[j-1]);
  227.                                 toplevels[j] = toplevels[j-1];
  228.                                
  229.                         }
  230.                         formatex(topnames[i], 31, name);
  231.                        
  232.                         toplevels[i]= levels;
  233.                        
  234.                         ColorChat(0, TEAM_COLOR,"^1[^3 BANI^1 ] Jucatorul ^4%s^1 a intrat pe locul ^4%i^1 in top bani !", name,(i+1));
  235.                         if(i+1 == 1) {
  236.                                 client_cmd(0, "spk vox/doop");
  237.                         } else {
  238.                                 client_cmd(0, "spk buttons/bell1");
  239.                         }
  240.                         save_top();
  241.                         break;
  242.                 }
  243.                 else if( equal(topnames[i], name))
  244.                 break;        
  245.         }
  246. }
  247. public read_top() {
  248.         new Buffer[256],path[128];
  249.         formatex(path, 127, "%s/Bani.dat", Data);
  250.        
  251.         new f = fopen(path, "rt" );
  252.         new i = 0;
  253.         while( !feof(f) && i < 15+1)
  254.         {
  255.                 fgets(f, Buffer, 255);
  256.                 new lvls[25];
  257.                 parse(Buffer, topnames[i], 31, lvls, 24);
  258.                 toplevels[i]= str_to_num(lvls);
  259.                
  260.                 i++;
  261.         }
  262.         fclose(f);
  263. }
  264. public sayTopLevel(id) {   
  265.     static buffer[2368], name[131], len, i;
  266.     len = formatex(buffer, 2047, "<body bgcolor=#FFFFFF><table width=100%% cellpadding=2 cellspacing=0 border=0>");
  267.     len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#52697B><th width=10%% > # <th width=45%%> Nume <th width=45%%>Bani");
  268.     for( i = 0; i < 15; i++ ) {    
  269.         if( toplevels[i] == 0) {
  270.             len += formatex(buffer[len], 2047-len, "<tr align=center%s><td> %d <td> %s <td> %s",((i%2)==0) ? "" : " bgcolor=#A4BED6", (i+1), "-", "-");
  271.             //i = NTOP
  272.         }
  273.         else {
  274.             name = topnames[i];
  275.             while( containi(name, "<") != -1 )
  276.                 replace(name, 129, "<", "&lt;");
  277.             while( containi(name, ">") != -1 )
  278.                 replace(name, 129, ">", "&gt;");
  279.             len += formatex(buffer[len], 2047-len, "<tr align=center%s><td> %d <td> %s <td> %d",((i%2)==0) ? "" : " bgcolor=#A4BED6", (i+1), name,toplevels[i]);
  280.         }
  281.     }
  282.     len += format(buffer[len], 2367-len, "</table>");
  283.     len += formatex(buffer[len], 2367-len, "<tr align=bottom font-size:11px><Center><br><br><br><br>by BACON</body>");
  284.     static strin[20];
  285.     format(strin,33, "Top Level");
  286.     show_motd(id, buffer, strin);
  287. }
  288.  
  289.  
  290. public bomb_planted(id)
  291. {
  292.     xmoney[id] = xmoney[id] + get_pcvar_num(cvs[0]);
  293.     checkandupdatetop(id,xmoney[id])
  294.     SaveData(id)
  295. }
  296.  
  297. public bomb_defused(id)
  298. {
  299.     xmoney[id] = xmoney[id] + get_pcvar_num(cvs[1]);
  300.     checkandupdatetop(id,xmoney[id])
  301.     SaveData(id)   
  302. }
  303.  
  304. public bomb_explode(id)
  305. {
  306.     xmoney[id] = xmoney[id] + get_pcvar_num(cvs[2]);
  307.     checkandupdatetop(id,xmoney[id])
  308.     SaveData(id)   
  309. }
  310.  
  311. public hk_die()
  312. {
  313.     new vct = read_data( 2 );
  314.     new atk = read_data( 1 );
  315.     new hitplace,weapon = get_user_weapon(atk, weapon, hitplace);
  316.  
  317.     if(!atk || atk == vct || !is_user_alive(atk))
  318.     {
  319.         return 1;
  320.     }
  321.    
  322.     if(get_pcvar_num(cvs[3]))
  323.     {
  324.         xmoney[vct] = xmoney[vct] - get_pcvar_num(cvs[4]);
  325.         checkandupdatetop(vct,xmoney[vct])
  326.         SaveData(vct)
  327.         return 0
  328.     }
  329.  
  330.     if(weapon == CSW_KNIFE)
  331.     {
  332.         xmoney[atk] = xmoney[atk] + get_pcvar_num(cvs[7]);
  333.         checkandupdatetop(atk,xmoney[atk])
  334.         SaveData(atk)
  335.         return 0
  336.     }
  337.  
  338.     if(hitplace == HIT_HEAD)
  339.     {
  340.         xmoney[atk] = xmoney[atk] + get_pcvar_num(cvs[5]);
  341.         checkandupdatetop(atk,xmoney[atk])
  342.         SaveData(atk)
  343.         return 0
  344.     }else{
  345.         xmoney[atk] = xmoney[atk] + get_pcvar_num(cvs[6]);
  346.         checkandupdatetop(atk,xmoney[atk])
  347.         SaveData(atk)
  348.         return 0
  349.     }  
  350.     return 0
  351. }
  352.  
  353. public SaveData(id)
  354. {
  355.         new PlayerName[35];
  356.         get_user_name(id,PlayerName,34);
  357.        
  358.         new vaultkey[64],vaultdata[256];
  359.         format(vaultkey,63,"%s",PlayerName);
  360.         format(vaultdata,255,"%i",xmoney[id]);
  361.         nvault_set(p_vault,vaultkey,vaultdata);
  362.         return PLUGIN_CONTINUE;
  363. }
  364. public LoadData(id)
  365. {
  366.         new PlayerName[35];
  367.         get_user_name(id,PlayerName,34);
  368.        
  369.         new vaultkey[64],vaultdata[256];
  370.         format(vaultkey,63,"%s",PlayerName);
  371.         format(vaultdata,255,"%i",xmoney[id]);
  372.         nvault_get(p_vault,vaultkey,vaultdata,255);
  373.        
  374.         replace_all(vaultdata, 255, "`", " ");
  375.        
  376.         new playerlevel[32];
  377.        
  378.         parse(vaultdata, playerlevel, 31);
  379.        
  380.         xmoney[id] = str_to_num(playerlevel);
  381.        
  382.         return PLUGIN_CONTINUE;
  383. }
  384.  
  385. public client_disconnect(id)
  386. {
  387.     SaveData(id)
  388. }
  389.  
  390. public client_putinserver(id)
  391. {
  392.     LoadData(id)
  393. }
  394.  
  395. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
  396. {
  397.     new message[256];
  398.  
  399.     switch(type)
  400.     {
  401.         case NORMAL: // clients scr_concolor cvar color
  402.         {
  403.             message[0] = 0x01;
  404.         }
  405.         case GREEN: // Green
  406.         {
  407.             message[0] = 0x04;
  408.         }
  409.         default: // White, Red, Blue
  410.         {
  411.             message[0] = 0x03;
  412.         }
  413.     }
  414.      
  415.     vformat(message[1], 251, msg, 4);
  416.  
  417.     // Make sure message is not longer than 192 character. Will crash the server.
  418.     message[191] = '^0';
  419.  
  420.     new team, ColorChange, index, MSG_Type;
  421.     if(id)
  422.     {
  423.         MSG_Type = MSG_ONE;
  424.         index = id;
  425.     } else {
  426.         index = FindPlayer();
  427.         MSG_Type = MSG_ALL;
  428.     }
  429.  
  430.     team = get_user_team(index);
  431.     ColorChange = ColorSelection(index, MSG_Type, type);
  432.  
  433.  
  434.     ShowColorMessage(index, MSG_Type, message);
  435.     if(ColorChange)
  436.     {
  437.         Team_Info(index, MSG_Type, TeamName[team]);
  438.     }
  439. }
  440.  
  441. ShowColorMessage(id, type, message[])
  442. {
  443.     static get_user_msgid_saytext;
  444.     if(!get_user_msgid_saytext)
  445.     {
  446.         get_user_msgid_saytext = get_user_msgid("SayText");
  447.     }
  448.     message_begin(type, get_user_msgid_saytext, _, id);
  449.     write_byte(id) 
  450.     write_string(message);
  451.     message_end(); 
  452. }
  453.  
  454. Team_Info(id, type, team[])
  455. {
  456.     static bool:teaminfo_used;
  457.     static get_user_msgid_teaminfo;
  458.     if(!teaminfo_used)
  459.     {
  460.         get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
  461.         teaminfo_used = true;
  462.     }
  463.     message_begin(type, get_user_msgid_teaminfo, _, id);
  464.     write_byte(id);
  465.     write_string(team);
  466.     message_end();
  467.  
  468.     return 1;
  469. }
  470.  
  471. ColorSelection(index, type, Color:Type)
  472. {
  473.     switch(Type)
  474.     {
  475.         case RED:
  476.         {
  477.             return Team_Info(index, type, TeamName[1]);
  478.         }
  479.         case BLUE:
  480.         {
  481.             return Team_Info(index, type, TeamName[2]);
  482.         }
  483.         case GREY:
  484.         {
  485.             return Team_Info(index, type, TeamName[0]);
  486.         }
  487.     }
  488.  
  489.     return 0;
  490. }
  491.  
  492. FindPlayer()
  493. {
  494.     new i = -1;
  495.     static iMaxPlayers;
  496.     if( !iMaxPlayers )
  497.     {
  498.         iMaxPlayers = get_maxplayers( );
  499.     }
  500.     while(i <= iMaxPlayers)
  501.     {
  502.         if(is_user_connected(++i))
  503.             return i;
  504.     }
  505.  
  506.     return -1;
  507. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement