Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < amxmisc >
- #include < hamsandwich >
- #include < nvault >
- #pragma tabsize 0
- #pragma compress 1
- #define PLUGIN "Buy Admin"
- #define VERSION "1.0"
- #define AUTHOR "raizo"
- #define MAX_WAYS 32
- enum transfer
- {
- points_10 = 1,
- points_50,
- points_100,
- points_500,
- points_1000
- }
- enum transfer_config
- {
- transfer:points_transfer
- }
- new all_transfers[MAX_WAYS+1][transfer_config]
- new szTmp[192];
- new his_friend_points[33]
- new his_points[33],his_user_kills[33],current_grade[33],MSG_TEXT;
- new VaultPoints
- new const Tag[] = "[BuyAdmin]";
- new const TrTag[] = "[Transfer Points]";
- enum BUY_STUFF
- {
- GradName[128],
- GradFlags[128],
- GradCost
- };
- new const AdminBuy[][BUY_STUFF] =
- {
- { "Vip","ab",3000 },
- { "Admin","bcefij",5000 },
- { "Moderator","bcdefimjru",7000 },
- { "C-owner","bcdefijmnopqrstuv",10000 }
- };
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- register_clcmd("say /buy", "shop_buy");
- register_clcmd( "say /transfer","transfer_points" );
- register_clcmd("amx_set_points","Set_Points",ADMIN_RCON,"<name> <points>")
- register_clcmd("Type_your_password","set_password");
- MSG_TEXT = get_user_msgid("SayText");
- RegisterHam(Ham_Killed, "player", "PlayerKilledPoints", 1)
- VaultPoints = nvault_open ("BuyAdminPoints")
- set_task(200.0,"Buy_Mesaje",0,"",0,"b",0)
- register_clcmd("say", "handle_say")
- }
- public handle_say(id)
- {
- new said[64], player[32]
- read_args(said, 63)
- remove_quotes(said)
- if (said[0] == ' ')
- return PLUGIN_CONTINUE
- else
- strtok(said, said, 63, player, 31, ' ')
- if (!equal(said, "/points"))
- return PLUGIN_CONTINUE
- new user = cmd_target(id, player, 2)
- if (!user)
- {
- ChatColor(id,"!team%s User Not Found!",Tag);
- return PLUGIN_CONTINUE
- }
- new szTargetName[32], szAdminName[32]
- get_user_name(id, szAdminName, 31)
- get_user_name(user, szTargetName, 31)
- ChatColor(0,"!team%s !ghave !team%d !gpoints! ",szTargetName, his_points[user]);
- return PLUGIN_HANDLED
- }
- public transfer_points(id)
- {
- new menu = menu_create("\y[\r Transfer Points \y ]\w By raizo","transfer_points_handled")
- formatex(szTmp,charsmax(szTmp),"Choose Points \r%s",transfer_results(all_transfers[id][points_transfer]));
- menu_additem(menu,szTmp,"1")
- formatex(szTmp,charsmax(szTmp),"Choose Player");
- menu_additem(menu,szTmp,"2")
- menu_display(id,menu)
- return PLUGIN_HANDLED;
- }
- public transfer_points_handled(id,menu,item)
- {
- if(item == MENU_EXIT)
- {
- menu_destroy(menu);
- return PLUGIN_HANDLED;
- }
- new data[3], iName[64]
- new access, callback;
- menu_item_getinfo(menu, item, access, data,2, iName, 63, callback);
- new key = str_to_num(data)
- switch(key)
- {
- case 1:
- {
- all_transfers[id][points_transfer] = ( ++all_transfers[id][points_transfer] > (transfer:5) ) ? (transfer:1) :all_transfers[id][points_transfer]
- }
- case 2:
- {
- Search_Player(id)
- return PLUGIN_HANDLED;
- }
- }
- menu_destroy(menu);
- transfer_points(id)
- bot(id)
- return PLUGIN_HANDLED;
- }
- public bot(id)
- {
- if(is_user_connected(id))
- {
- transfer_results_handled(id)
- }
- }
- transfer_results(transfer:part)
- {
- new szResult[64]
- switch(part)
- {
- case points_10: copy(szResult, charsmax(szResult), "10 Points");
- case points_50: copy(szResult, charsmax(szResult), "50 Points");
- case points_100: copy(szResult, charsmax(szResult), "100 Points");
- case points_500: copy(szResult, charsmax(szResult), "500 Points");
- case points_1000: copy(szResult, charsmax(szResult), "1000 Points");
- default: copy(szResult, charsmax(szResult), "");
- }
- return szResult;
- }
- transfer_results_handled(id)
- {
- switch(all_transfers[id][points_transfer])
- {
- case points_10:
- {
- his_friend_points[id] = 1
- }
- case points_50:
- {
- his_friend_points[id] = 2
- }
- case points_100:
- {
- his_friend_points[id] = 3
- }
- case points_500:
- {
- his_friend_points[id] = 4
- }
- case points_1000:
- {
- his_friend_points[id] = 5
- }
- }
- return 0;
- }
- public Search_Player( id )
- {
- new menu = menu_create( "\rChoose Your Player!:", "menu_handler" );
- new players[32], pnum, tempid;
- new szName[32], szUserId[32];
- get_players( players, pnum, "a" );
- for ( new i; i<pnum; i++ )
- {
- tempid = players[i];
- get_user_name( tempid, szName, charsmax( szName ) );
- formatex( szUserId, charsmax( szUserId ), "%d", get_user_userid( tempid ) );
- menu_additem( menu, szName, szUserId, 0 );
- }
- menu_display( id, menu, 0 );
- }
- public menu_handler( id, menu, item )
- {
- if ( item == MENU_EXIT )
- {
- menu_destroy( menu );
- return PLUGIN_HANDLED;
- }
- new szData[6], szName[64];
- new _access, item_callback;
- menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
- new userid = str_to_num( szData );
- new player = find_player( "k", userid );
- new idname[33], playername[33]
- get_user_name(id,idname,charsmax(idname))
- get_user_name(player,playername,charsmax(playername))
- if ( player && is_user_alive( player ) )
- {
- if(his_friend_points[id] == 1)
- {
- if((his_points[id] >= 10))
- {
- his_points[id] -= 10
- his_points[player] += 10
- ChatColor(0,"!g%s !team%s !gsend to !team%s !g10 !teampoints using /transfer",TrTag,idname,playername);
- }
- else
- {
- ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 10 points",TrTag);
- return PLUGIN_HANDLED;
- }
- }
- else if(his_friend_points[id] == 2)
- {
- if((his_points[id] >= 50))
- {
- his_points[id] -= 50
- his_points[player] += 50
- ChatColor(0,"!g%s !team%s !gsend to !team%s !g50 !teampoints using /transfer",TrTag,idname,playername);
- }
- else
- {
- ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 50 points",TrTag);
- return PLUGIN_HANDLED;
- }
- }
- else if(his_friend_points[id] == 3)
- {
- if((his_points[id] >= 100))
- {
- his_points[id] -= 100
- his_points[player] += 100
- ChatColor(0,"!g%s !team%s !gsend to !team%s !g100 !teampoints using /transfer",TrTag,idname,playername);
- }
- else
- {
- ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 100 points",TrTag);
- return PLUGIN_HANDLED;
- }
- }
- else if(his_friend_points[id] == 4)
- {
- if((his_points[id] >= 500))
- {
- his_points[id] -= 500
- his_points[player] += 500
- ChatColor(0,"!g%s !team%s !gsend to !team%s !g500 !teampoints using /transfer",TrTag,idname,playername);
- }
- else
- {
- ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 500 points",TrTag);
- return PLUGIN_HANDLED;
- }
- }
- else if(his_friend_points[id] == 5)
- {
- if((his_points[id] >= 1000))
- {
- his_points[id] -= 1000
- his_points[player] += 1000
- ChatColor(0,"!g%s !team%s !gsend to !team%s !g1000 !teampoints using /transfer",TrTag,idname,playername);
- }
- else
- {
- ChatColor(id,"!g%s !ySorry,you don't have enough points to send ,you need 1000 points",TrTag);
- return PLUGIN_HANDLED;
- }
- }
- }
- menu_destroy( menu );
- return PLUGIN_HANDLED;
- }
- public Buy_Mesaje()
- {
- ChatColor(0,"!team%s Type !y/buy !teamor !y/transfer !teamto choose any admin using points! ",Tag);
- }
- public PlayerKilledPoints(Victim, Killer)
- {
- if (Victim == Killer || !is_user_alive(Killer))
- return
- his_points[Killer] += 1;
- his_user_kills[Killer]++
- if(his_user_kills[Killer] == 10)
- {
- ChatColor(Killer,"!team%s You have won !y%d !teampoints! ",Tag,his_points[Killer]);
- his_user_kills[Killer] = 0
- }
- }
- public Set_Points( id, level, cid )
- {
- if (!cmd_access(id,level,cid,2))
- return PLUGIN_HANDLED ;
- new szName[32]
- get_user_name(id, szName, charsmax(szName))
- new name[ 50 ];
- read_argv( 1, name, 49 );
- new valSz[ 50 ], val;
- read_argv( 2, valSz, 49 );
- val = str_to_num( valSz );
- new user = cmd_target( id, name, CMDTARGET_ALLOW_SELF );
- his_points[ user ] = val * 1;
- ChatColor(0,"!team%s !g%s !yset !team%d !ypoints to !g%s!!y",Tag,szName,val,name)
- return PLUGIN_HANDLED;
- }
- public shop_buy( id )
- {
- new Temp[128],szNumber[10],count = 0;
- formatex(Temp,charsmax(Temp),"Buy Admin \r| \yYour points : \r%d",his_points[id]);
- new menu = menu_create(Temp, "handler_admin")
- if(check(id) != -1)
- {
- for(new i = check(id) ; i < sizeof(AdminBuy) ;i++)
- {
- count++;
- num_to_str(i,szNumber, charsmax( szNumber ));
- 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]);
- menu_additem(menu,Temp,szNumber);
- }
- }
- if(count==0)
- {
- ChatColor(id,"!g%s !yNo grades registred.",Tag);
- return PLUGIN_HANDLED;
- }
- menu_display(id, menu, 0);
- return PLUGIN_HANDLED;
- }
- public handler_admin(id, menu, item)
- {
- if( item == MENU_EXIT )
- {
- menu_destroy(menu);
- return PLUGIN_HANDLED;
- }
- static data[6], name[64], acs, cllbck;
- menu_item_getinfo(menu, item, acs, data, 5, name, 63, cllbck);
- current_grade[id] = str_to_num(data);
- if((his_points[id] - AdminBuy[current_grade[id]][GradCost]) >= 0)
- {
- client_cmd( id, "messagemode Type_your_password" );
- ChatColor(id,"!g%s !yYou just buyed !team%s !y,set your password now please.",Tag,AdminBuy[current_grade[id]][GradName]);
- }
- else
- {
- 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]));
- return PLUGIN_HANDLED;
- }
- menu_destroy(menu);
- return PLUGIN_HANDLED;
- }
- public set_password( id )
- {
- if(current_grade[id] < 0)
- {
- ChatColor(id,"!g%s !ySorry you can't hook this command with messagemode.",Tag)
- return PLUGIN_HANDLED;
- }
- new szArg[ 21 ];
- read_argv(1, szArg, sizeof ( szArg ) -1 );
- if ( !strlen( szArg ) || strlen( szArg ) < 5 )
- {
- ChatColor(id,"!g%s !yYour password can't be smaller than !team5 characters.",Tag)
- client_cmd( id, "messagemode Type_your_password" );
- return PLUGIN_HANDLED;
- }
- else if( strlen( szArg ) > 20 )
- {
- ChatColor(id,"!g%s !yYour password can't be bigger than !team20 characters.",Tag)
- client_cmd( id, "messagemode Type_your_password" );
- return PLUGIN_HANDLED;
- }
- if((his_points[id] - AdminBuy[current_grade[id]][GradCost]) >= 0)
- {
- his_points[id] -= AdminBuy[current_grade[id]][GradCost];
- SetAdmin(id,szArg);
- }
- else
- {
- 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]));
- return PLUGIN_HANDLED;
- }
- return PLUGIN_HANDLED;
- }
- public SetAdmin(id,pass[])
- {
- new configsDir[64]
- get_configsdir(configsDir, 63)
- format(configsDir, 63, "%s/users.ini", configsDir)
- if (!file_exists(configsDir))
- {
- ChatColor(id,"!g%s !ySorry but our users.ini is missing contact an owner to report this.",Tag);
- return PLUGIN_HANDLED;
- }
- remove_user_flags(id);
- new text[256];
- new player_name[32],szTypeAdmin[256],i = 0;
- new line_name[64],line_password[64],line_accessflags[64],line_flags[64],parsedParams;
- new currentTime[9],currentDate[11],stock_i=-1;
- get_user_name(id,player_name,charsmax(player_name));
- get_time("%H:%M:%S",currentTime,charsmax(currentTime))
- get_time("%Y/%m/%d",currentDate,charsmax(currentDate))
- new file = fopen(configsDir,"rt");
- while(!feof(file))
- {
- fgets(file,text,50);
- i++;
- if(text[0] == ';')
- continue;
- parsedParams = parse(text,line_name,charsmax(line_name),line_password,charsmax(line_password),line_accessflags,charsmax(line_accessflags),line_flags,charsmax(line_flags))
- if (parsedParams != 4)
- continue;
- if(equal(player_name,line_name))
- {
- stock_i = i;
- break;
- }
- }
- 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]);
- if(stock_i != -1)
- write_file(configsDir,szTypeAdmin,stock_i-1);
- else
- write_file(configsDir,szTypeAdmin,i-1);
- fclose(file);
- new g_passprefix[32];get_cvar_string("amx_password_field",g_passprefix,31);
- set_user_info( id, g_passprefix, pass );
- 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);
- current_grade[id] = -1;
- server_cmd( "amx_reloadadmins" );
- return PLUGIN_HANDLED;
- }
- public client_putinserver(id)
- {
- LoadData(id)
- current_grade[id] = -1;
- }
- public client_disconnect(id)
- {
- SaveData(id)
- current_grade[id] = -1;
- }
- public check(id)
- {
- new stock_val = 0;
- for(new i = 0 ; i < sizeof(AdminBuy);i++)
- {
- if(get_user_flags(id) == read_flags(AdminBuy[i][GradFlags]))
- {
- if( i == (sizeof(AdminBuy)-1) )
- stock_val = -1;
- else
- stock_val = i+1;
- break;
- }
- }
- return stock_val;
- }
- public plugin_end() nvault_close(VaultPoints)
- public LoadData(playerid)
- {
- new vaultkey [ 64 ],vaultdata [ 256 ];
- format(vaultkey, 63,"%s-Mod", GetName(playerid))
- format(vaultdata, 255,"%i#", his_points[playerid])
- nvault_get(VaultPoints, vaultkey, vaultdata, 255);
- replace_all(vaultdata, 255, "#", " ");
- new playerpoints[50];
- parse(vaultdata, playerpoints, 49);
- his_points[playerid] = str_to_num(playerpoints);
- }
- public SaveData(playerid)
- {
- new vaultkey[64], vaultdata[256]
- format(vaultkey, 63,"%s-Mod", GetName(playerid))
- format(vaultdata, 255,"%i#", his_points[playerid])
- nvault_set(VaultPoints, vaultkey, vaultdata)
- }
- stock GetName(playerid)
- {
- new name[32]
- get_user_name(playerid, name, 31)
- return name
- }
- stock ChatColor(const id, const input[], any:...)
- {
- new count = 1, players[32]
- static msg[191]
- vformat(msg, 190, input, 3)
- replace_all(msg, 190, "!g", "^4")
- replace_all(msg, 190, "!y", "^1")
- replace_all(msg, 190, "!team", "^3")
- if (id) players[0] = id; else get_players(players, count, "ch")
- {
- for (new i = 0; i < count; i++)
- {
- if (is_user_connected(players[i]))
- {
- message_begin(MSG_ONE_UNRELIABLE,MSG_TEXT, _, players[i]);
- write_byte(players[i]);
- write_string(msg);
- message_end();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment