raizo21

Buy Admin

Dec 8th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 16.50 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < amxmisc >
  3. #include < hamsandwich >
  4. #include < nvault >
  5.  
  6. #pragma tabsize 0
  7. #pragma compress 1
  8.  
  9. #define PLUGIN "Buy Admin"
  10. #define VERSION "1.0"
  11. #define AUTHOR "raizo"
  12.  
  13. #define MAX_WAYS 32
  14.  
  15. enum transfer
  16. {
  17.     points_10 = 1,
  18.     points_50,
  19.     points_100,
  20.     points_500,
  21.     points_1000
  22. }
  23.  
  24. enum transfer_config
  25. {
  26.     transfer:points_transfer
  27. }
  28.  
  29. new all_transfers[MAX_WAYS+1][transfer_config]
  30. new szTmp[192];
  31. new his_friend_points[33]
  32.  
  33. new his_points[33],his_user_kills[33],current_grade[33],MSG_TEXT;
  34.  
  35. new VaultPoints
  36.  
  37. new const Tag[] = "[BuyAdmin]";
  38. new const TrTag[] = "[Transfer Points]";
  39.  
  40. enum BUY_STUFF
  41. {
  42.     GradName[128],
  43.     GradFlags[128],
  44.     GradCost
  45. };
  46.  
  47. new const AdminBuy[][BUY_STUFF] =
  48. {
  49.     { "Vip","ab",3000 },
  50.     { "Admin","bcefij",5000 },
  51.     { "Moderator","bcdefimjru",7000 },
  52.     { "C-owner","bcdefijmnopqrstuv",10000 }
  53. };
  54.  
  55. public plugin_init()
  56. {
  57.     register_plugin(PLUGIN, VERSION, AUTHOR);
  58.  
  59.     register_clcmd("say /buy", "shop_buy");
  60.     register_clcmd( "say /transfer","transfer_points" );
  61.  
  62.     register_clcmd("amx_set_points","Set_Points",ADMIN_RCON,"<name> <points>")
  63.  
  64.     register_clcmd("Type_your_password","set_password");
  65.  
  66.     MSG_TEXT = get_user_msgid("SayText");
  67.  
  68.     RegisterHam(Ham_Killed, "player", "PlayerKilledPoints", 1)
  69.    
  70.     VaultPoints = nvault_open ("BuyAdminPoints")
  71.    
  72.     set_task(200.0,"Buy_Mesaje",0,"",0,"b",0)
  73.    
  74.     register_clcmd("say", "handle_say")
  75. }
  76.  
  77. public handle_say(id)
  78. {
  79.     new said[64], player[32]
  80.     read_args(said, 63)
  81.     remove_quotes(said)
  82.    
  83.     if (said[0] == ' ')
  84.         return PLUGIN_CONTINUE
  85.     else
  86.         strtok(said, said, 63, player, 31, ' ')
  87.        
  88.     if (!equal(said, "/points"))
  89.         return PLUGIN_CONTINUE
  90.    
  91.     new user = cmd_target(id, player, 2)
  92.    
  93.     if (!user)
  94.     {
  95.         ChatColor(id,"!team%s User Not Found!",Tag);
  96.         return PLUGIN_CONTINUE
  97.     }
  98.    
  99.     new szTargetName[32], szAdminName[32]
  100.     get_user_name(id, szAdminName, 31)
  101.     get_user_name(user, szTargetName, 31)
  102.    
  103.     ChatColor(0,"!team%s !ghave !team%d !gpoints! ",szTargetName, his_points[user]);
  104.    
  105.     return PLUGIN_HANDLED
  106.    
  107. }
  108.  
  109. public transfer_points(id)
  110. {
  111.     new menu = menu_create("\y[\r Transfer Points \y ]\w By raizo","transfer_points_handled")
  112.  
  113.     formatex(szTmp,charsmax(szTmp),"Choose Points \r%s",transfer_results(all_transfers[id][points_transfer]));
  114.     menu_additem(menu,szTmp,"1")
  115.    
  116.     formatex(szTmp,charsmax(szTmp),"Choose Player");
  117.     menu_additem(menu,szTmp,"2")
  118.    
  119.     menu_display(id,menu)
  120.  
  121.     return PLUGIN_HANDLED;
  122. }
  123.  
  124. public transfer_points_handled(id,menu,item)
  125. {
  126.     if(item == MENU_EXIT)
  127.     {
  128.         menu_destroy(menu);
  129.  
  130.         return PLUGIN_HANDLED;
  131.     }
  132.  
  133.     new data[3], iName[64]
  134.     new access, callback;
  135.     menu_item_getinfo(menu, item, access, data,2, iName, 63, callback);
  136.     new key = str_to_num(data)
  137.  
  138.     switch(key)
  139.     {
  140.         case 1:
  141.         {
  142.             all_transfers[id][points_transfer] = ( ++all_transfers[id][points_transfer] > (transfer:5) ) ? (transfer:1) :all_transfers[id][points_transfer]
  143.         }
  144.         case 2:
  145.         {
  146.             Search_Player(id)
  147.        return PLUGIN_HANDLED;
  148.         }
  149.     }
  150.     menu_destroy(menu);
  151.  
  152.     transfer_points(id)
  153.     bot(id)
  154.     return PLUGIN_HANDLED;
  155. }
  156.  
  157. public bot(id)
  158. {
  159.     if(is_user_connected(id))
  160.     {
  161.         transfer_results_handled(id)
  162.     }
  163. }
  164.  
  165.  
  166. transfer_results(transfer:part)
  167. {
  168.     new szResult[64]
  169.    
  170.     switch(part)
  171.     {
  172.         case points_10:    copy(szResult, charsmax(szResult), "10 Points");
  173.         case points_50:    copy(szResult, charsmax(szResult), "50 Points");
  174.         case points_100:   copy(szResult, charsmax(szResult), "100 Points");
  175.         case points_500:   copy(szResult, charsmax(szResult), "500 Points");
  176.         case points_1000:  copy(szResult, charsmax(szResult), "1000 Points");
  177.    
  178.         default:             copy(szResult, charsmax(szResult), "");
  179.     }
  180.     return szResult;
  181. }
  182.  
  183. transfer_results_handled(id)
  184. {
  185.     switch(all_transfers[id][points_transfer])
  186.     {
  187.         case points_10:
  188.         {
  189.             his_friend_points[id] = 1
  190.         }
  191.         case points_50:
  192.         {
  193.             his_friend_points[id] = 2
  194.         }
  195.         case points_100:
  196.         {
  197.             his_friend_points[id] = 3
  198.         }
  199.         case points_500:
  200.         {
  201.             his_friend_points[id] = 4
  202.         }
  203.         case points_1000:
  204.         {
  205.             his_friend_points[id] = 5
  206.         }
  207.     }
  208.     return 0;
  209. }
  210.  
  211.  public Search_Player( id )
  212.  {
  213.     new menu = menu_create( "\rChoose Your Player!:", "menu_handler" );
  214.  
  215.     new players[32], pnum, tempid;
  216.  
  217.     new szName[32], szUserId[32];
  218.  
  219.     get_players( players, pnum, "a" );
  220.  
  221.     for ( new i; i<pnum; i++ )
  222.     {
  223.         tempid = players[i];
  224.  
  225.         get_user_name( tempid, szName, charsmax( szName ) );
  226.  
  227.         formatex( szUserId, charsmax( szUserId ), "%d", get_user_userid( tempid ) );
  228.  
  229.         menu_additem( menu, szName, szUserId, 0 );
  230.     }
  231.  
  232.     menu_display( id, menu, 0 );
  233.  }
  234.  
  235.  public menu_handler( id, menu, item )
  236.  {
  237.  
  238.     if ( item == MENU_EXIT )
  239.     {
  240.         menu_destroy( menu );
  241.         return PLUGIN_HANDLED;
  242.     }
  243.  
  244.  
  245.     new szData[6], szName[64];
  246.     new _access, item_callback;
  247.  
  248.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  249.  
  250.     new userid = str_to_num( szData );
  251.  
  252.     new player = find_player( "k", userid );
  253.    
  254.     new idname[33], playername[33]
  255.    
  256.     get_user_name(id,idname,charsmax(idname))
  257.     get_user_name(player,playername,charsmax(playername))
  258.    
  259.     if ( player && is_user_alive( player ) )
  260.     {
  261.          
  262.         if(his_friend_points[id] == 1)
  263.     {
  264.         if((his_points[id] >= 10))
  265.              {
  266.             his_points[id] -= 10   
  267.             his_points[player] += 10
  268.             ChatColor(0,"!g%s !team%s !gsend to !team%s !g10 !teampoints using /transfer",TrTag,idname,playername);
  269.              }
  270.              else
  271.              {
  272.                  ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 10 points",TrTag);
  273.                  return PLUGIN_HANDLED;
  274.              }
  275.     }
  276.          else if(his_friend_points[id] == 2)
  277.     {
  278.         if((his_points[id] >= 50))
  279.              {
  280.             his_points[id] -= 50   
  281.             his_points[player] += 50
  282.             ChatColor(0,"!g%s !team%s !gsend to !team%s !g50 !teampoints using /transfer",TrTag,idname,playername);
  283.              }
  284.              else
  285.              {
  286.                  ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 50 points",TrTag);
  287.                  return PLUGIN_HANDLED;
  288.              }  
  289.     }
  290.         else if(his_friend_points[id] == 3)
  291.     {
  292.         if((his_points[id] >= 100))
  293.              {
  294.             his_points[id] -= 100  
  295.             his_points[player] += 100
  296.             ChatColor(0,"!g%s !team%s !gsend to !team%s !g100 !teampoints using /transfer",TrTag,idname,playername);
  297.              }
  298.              else
  299.              {
  300.                  ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 100 points",TrTag);
  301.                  return PLUGIN_HANDLED;
  302.              }
  303.     }
  304.         else if(his_friend_points[id] == 4)
  305.     {
  306.         if((his_points[id] >= 500))
  307.              {
  308.             his_points[id] -= 500  
  309.             his_points[player] += 500
  310.             ChatColor(0,"!g%s !team%s !gsend to !team%s !g500 !teampoints using /transfer",TrTag,idname,playername);
  311.              }
  312.              else
  313.              {
  314.                  ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 500 points",TrTag);
  315.                  return PLUGIN_HANDLED;
  316.              }
  317.          }
  318.         else if(his_friend_points[id] == 5)
  319.     {
  320.         if((his_points[id] >= 1000))
  321.              {
  322.             his_points[id] -= 1000 
  323.             his_points[player] += 1000
  324.             ChatColor(0,"!g%s !team%s !gsend to !team%s !g1000 !teampoints using /transfer",TrTag,idname,playername);
  325.              }
  326.              else
  327.              {
  328.                  ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 1000 points",TrTag);
  329.                  return PLUGIN_HANDLED;
  330.              }
  331.     }  
  332.     }
  333.     menu_destroy( menu );
  334.     return PLUGIN_HANDLED;
  335.  }
  336.  
  337. public Buy_Mesaje()
  338. {
  339.     ChatColor(0,"!team%s Type !y/buy !teamor !y/transfer !teamto choose any admin using points! ",Tag);
  340. }
  341.  
  342. public PlayerKilledPoints(Victim, Killer)
  343. {
  344.     if (Victim == Killer || !is_user_alive(Killer))
  345.         return
  346.    
  347.     his_points[Killer] += 1;
  348.     his_user_kills[Killer]++
  349.    
  350.     if(his_user_kills[Killer] == 10)
  351.     {
  352.         ChatColor(Killer,"!team%s You have won !y%d !teampoints! ",Tag,his_points[Killer]);
  353.     his_user_kills[Killer] = 0
  354.     }
  355. }
  356.  
  357.  
  358. public Set_Points( id, level, cid )
  359. {
  360.     if (!cmd_access(id,level,cid,2))
  361.         return PLUGIN_HANDLED ;
  362.        
  363.      new szName[32]
  364.      get_user_name(id, szName, charsmax(szName))
  365.        
  366.     new name[ 50 ];
  367.     read_argv( 1, name, 49 );
  368.     new valSz[ 50 ], val;
  369.     read_argv( 2, valSz, 49 );
  370.     val = str_to_num( valSz );
  371.    
  372.     new user = cmd_target( id, name, CMDTARGET_ALLOW_SELF );
  373.  
  374.     his_points[ user ] = val * 1;
  375.    
  376.     ChatColor(0,"!team%s !g%s !yset !team%d !ypoints to !g%s!!y",Tag,szName,val,name)
  377.    
  378.     return PLUGIN_HANDLED;
  379. }
  380.  
  381. public shop_buy( id )
  382. {
  383.     new Temp[128],szNumber[10],count = 0;
  384.    
  385.     formatex(Temp,charsmax(Temp),"Buy Admin \r| \yYour points : \r%d",his_points[id]);
  386.     new menu = menu_create(Temp, "handler_admin")
  387.    
  388.     if(check(id) != -1)
  389.     {
  390.         for(new i = check(id) ; i < sizeof(AdminBuy) ;i++)
  391.         {
  392.             count++;
  393.             num_to_str(i,szNumber, charsmax( szNumber ));
  394.             format(Temp,charsmax(Temp),"\r%s \yFlags:\w[\r%s\w] \yCost:\w[\r%d\w]",AdminBuy[i][GradName],AdminBuy[i][GradFlags],AdminBuy[i][GradCost]);
  395.             menu_additem(menu,Temp,szNumber);
  396.         }
  397.     }
  398.     if(count==0)
  399.     {
  400.         ChatColor(id,"!g%s !yNo grades registred.",Tag);
  401.        return PLUGIN_HANDLED;
  402.     }
  403.     menu_display(id, menu, 0);
  404.     return PLUGIN_HANDLED;
  405. }
  406.  
  407. public handler_admin(id, menu, item)
  408. {  
  409.     if( item == MENU_EXIT )
  410.     {
  411.         menu_destroy(menu);
  412.         return PLUGIN_HANDLED;
  413.     }
  414.     static data[6], name[64], acs, cllbck;
  415.    
  416.     menu_item_getinfo(menu, item, acs, data, 5, name, 63, cllbck);
  417.     current_grade[id] = str_to_num(data);
  418.     if((his_points[id] - AdminBuy[current_grade[id]][GradCost]) >= 0)
  419.     {
  420.         client_cmd( id, "messagemode Type_your_password" );
  421.         ChatColor(id,"!g%s !yYou just buyed !team%s !y,set your password now please.",Tag,AdminBuy[current_grade[id]][GradName]);
  422.     }
  423.     else
  424.     {
  425.         ChatColor(id,"!g%s !ySorry,you don't have enough points to buy !team%s !y,you need !g%d !ymore points,come back then.",Tag,AdminBuy[current_grade[id]][GradName],(AdminBuy[current_grade[id]][GradCost]-his_points[id]));
  426.         return PLUGIN_HANDLED;
  427.     }
  428.     menu_destroy(menu);
  429.     return PLUGIN_HANDLED;
  430. }
  431.  
  432. public set_password( id )
  433. {
  434.     if(current_grade[id] < 0)
  435.     {
  436.         ChatColor(id,"!g%s !ySorry you can't hook this command with messagemode.",Tag)
  437.         return PLUGIN_HANDLED;
  438.     }
  439.     new szArg[ 21 ];
  440.    
  441.     read_argv(1, szArg, sizeof ( szArg ) -1 );
  442.    
  443.     if ( !strlen( szArg ) || strlen( szArg ) < 5 )
  444.     {
  445.         ChatColor(id,"!g%s !yYour password can't be smaller than !team5 characters.",Tag)
  446.         client_cmd( id, "messagemode Type_your_password" );
  447.         return PLUGIN_HANDLED;
  448.     }
  449.     else if( strlen( szArg ) > 20 )
  450.     {
  451.         ChatColor(id,"!g%s !yYour password can't be bigger than !team20 characters.",Tag)
  452.         client_cmd( id, "messagemode Type_your_password" );
  453.         return PLUGIN_HANDLED;
  454.     }
  455.     if((his_points[id] - AdminBuy[current_grade[id]][GradCost]) >= 0)
  456.     {
  457.         his_points[id] -= AdminBuy[current_grade[id]][GradCost];
  458.         SetAdmin(id,szArg);
  459.     }
  460.     else
  461.     {
  462.         ChatColor(id,"!g%s !ySorry,you don't have enough points to buy !team%s !y,you need !g%d !ymore points,come back then.",Tag,AdminBuy[current_grade[id]][GradName],(AdminBuy[current_grade[id]][GradCost]-his_points[id]));
  463.         return PLUGIN_HANDLED;
  464.     }
  465.     return PLUGIN_HANDLED;
  466. }
  467.  
  468. public SetAdmin(id,pass[])
  469. {
  470.     new configsDir[64]
  471.     get_configsdir(configsDir, 63)
  472.     format(configsDir, 63, "%s/users.ini", configsDir)
  473.    
  474.     if (!file_exists(configsDir))
  475.     {
  476.         ChatColor(id,"!g%s !ySorry but our users.ini is missing contact an owner to report this.",Tag);
  477.         return PLUGIN_HANDLED;
  478.     }
  479.     remove_user_flags(id);
  480.  
  481.     new text[256];
  482.     new player_name[32],szTypeAdmin[256],i = 0;
  483.     new line_name[64],line_password[64],line_accessflags[64],line_flags[64],parsedParams;
  484.     new currentTime[9],currentDate[11],stock_i=-1;
  485.     get_user_name(id,player_name,charsmax(player_name));
  486.     get_time("%H:%M:%S",currentTime,charsmax(currentTime))
  487.     get_time("%Y/%m/%d",currentDate,charsmax(currentDate))
  488.     new file = fopen(configsDir,"rt");
  489.    
  490.     while(!feof(file))
  491.     {
  492.         fgets(file,text,50);
  493.         i++;
  494.  
  495.         if(text[0] == ';')
  496.             continue;
  497.  
  498.         parsedParams = parse(text,line_name,charsmax(line_name),line_password,charsmax(line_password),line_accessflags,charsmax(line_accessflags),line_flags,charsmax(line_flags)) 
  499.         if (parsedParams != 4)
  500.             continue;
  501.  
  502.         if(equal(player_name,line_name))
  503.         {
  504.             stock_i = i;
  505.             break;
  506.         }
  507.     }
  508.    
  509.     formatex(szTypeAdmin, sizeof( szTypeAdmin ) -1,"^"%s^" ^"%s^" ^"%s^" ^"a^";Admin Buyed | Date : %s | Time : %s | Points Left : %d", player_name,pass,AdminBuy[current_grade[id]][GradFlags],currentDate,currentTime,his_points[id]);
  510.     if(stock_i != -1)
  511.     write_file(configsDir,szTypeAdmin,stock_i-1);
  512.     else
  513.     write_file(configsDir,szTypeAdmin,i-1);
  514.     fclose(file);
  515.     new g_passprefix[32];get_cvar_string("amx_password_field",g_passprefix,31);
  516.     set_user_info( id, g_passprefix, pass );
  517.     ChatColor(id,"!g%s !yYou just buyed !team%s !yyour admin was automatically added,connect next time using setinfo %s %s.",Tag,AdminBuy[current_grade[id]][GradName],g_passprefix,pass);
  518.     current_grade[id] = -1;
  519.     server_cmd( "amx_reloadadmins" );
  520.     return PLUGIN_HANDLED;
  521. }
  522. public client_putinserver(id)
  523. {
  524.     LoadData(id)
  525.  
  526.     current_grade[id] = -1;
  527. }
  528.  
  529. public client_disconnect(id)
  530. {
  531.     SaveData(id)
  532.    
  533.     current_grade[id] = -1;
  534. }
  535.  
  536. public check(id)
  537. {
  538.     new stock_val = 0;
  539.     for(new i = 0 ; i < sizeof(AdminBuy);i++)
  540.     {
  541.         if(get_user_flags(id) == read_flags(AdminBuy[i][GradFlags]))
  542.         {
  543.             if( i == (sizeof(AdminBuy)-1) )
  544.             stock_val = -1;
  545.             else
  546.             stock_val = i+1;
  547.             break;
  548.         }
  549.     }
  550.     return stock_val;
  551. }
  552.  
  553. public plugin_end() nvault_close(VaultPoints)
  554.  
  555.  
  556. public LoadData(playerid)
  557. {
  558.     new vaultkey [ 64 ],vaultdata [ 256 ];
  559.    
  560.     format(vaultkey, 63,"%s-Mod", GetName(playerid))
  561.     format(vaultdata, 255,"%i#", his_points[playerid])
  562.     nvault_get(VaultPoints, vaultkey, vaultdata, 255);
  563.     replace_all(vaultdata, 255, "#", " ");
  564.    
  565.     new playerpoints[50];
  566.    
  567.     parse(vaultdata, playerpoints, 49);  
  568.  
  569.     his_points[playerid] = str_to_num(playerpoints);
  570. }
  571.  
  572.  
  573. public SaveData(playerid)
  574. {
  575.     new vaultkey[64], vaultdata[256]
  576.    
  577.     format(vaultkey, 63,"%s-Mod", GetName(playerid))
  578.     format(vaultdata, 255,"%i#", his_points[playerid])
  579.     nvault_set(VaultPoints, vaultkey, vaultdata)
  580. }
  581.  
  582. stock GetName(playerid)
  583. {
  584.     new name[32]
  585.     get_user_name(playerid, name, 31)
  586.  
  587.     return name
  588. }
  589.  
  590. stock ChatColor(const id, const input[], any:...)
  591. {
  592.     new count = 1, players[32]
  593.     static msg[191]
  594.     vformat(msg, 190, input, 3)
  595.  
  596.     replace_all(msg, 190, "!g", "^4")
  597.     replace_all(msg, 190, "!y", "^1")
  598.     replace_all(msg, 190, "!team", "^3")
  599.  
  600.     if (id) players[0] = id; else get_players(players, count, "ch")
  601.     {
  602.         for (new i = 0; i < count; i++)
  603.         {
  604.             if (is_user_connected(players[i]))
  605.             {
  606.                 message_begin(MSG_ONE_UNRELIABLE,MSG_TEXT, _, players[i]);
  607.                 write_byte(players[i]);
  608.                 write_string(msg);
  609.                 message_end();
  610.             }
  611.         }
  612.     }
  613. }
Add Comment
Please, Sign In to add comment