Страница 1 от 1

Заявка за настройка на плъгин

МнениеПубликувано:ср ное 09, 2016 1:53 pm
от PuBL!c
Може ли да се премахнат админ префиксите и да останат само ранковете?

.sma:
Код: Избери всички
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < engine >
#include < colorchat >
#include < hamsandwich >
#include < fun >
#include < nvault >

#define MAXRANKS 32

#define PLUGIN "BP Admin prefix with ranks"
#define VERSION "1.3"
#define AUTHOR "Dark-Gaming"

//ПРОМЕНЛИВИ
new PlayerRank[33], message[192]
new sayText, teamInfo, maxPlayers, g_AdminListen,  g_AdminListenFlag,g_MsgHud, gVault
new strName[191], strText[191], alive[11], temp_cvar[2], g_name[32]
new gPlayerPoints[33], give[33],iTarget[33]

new const g_szTag[][] = {
       "",
       "Server Owner",
       "Administrator",
       "Global Moderator",
       "Supervisor",
       "Team Bans",
       "Server Admin",
       "Test Admin",
       "VIP",
       "SMS Admin"
}

new const rankNames[MAXRANKS][] =
{
"[Jumper]", 
"[Jumper First Class]", 
"[Incredible]", 
"[Unstoppable]", 
"[Perfect]", 
"[Runner]", 
"[Great Bhop]", 
"[Bhopper]", 
"[Great Jumper]", 
"[Alien Jumper]", 
"[Super Bhopper]", 
"[LJ Master]", 
"[Technique]", 
"[Unreal]", 
"[Advanced]", 
"[Machine]",
"[Hunter]", 
"*PunisheR*", 
"[Quick]", 
"[Maniac]",
"[Jump Master]", 
"[Bhop Master]",
"[God Like]", 
"[Unique]", 
"*PRO*", 
"[Immortal]", 
"[Hero]", 
"[Jarring]", 
"*ProffesionaL*", 
"[Danger Bhopper]",
"[Bhop Legend]", 
"[HNS Master]"
};

new const rankXP[MAXRANKS] =
{
	0, 25, 50, 100, 150, 200, 350, 500, 700, 850, 1100, 1400, 1800, 2400, 3000, 3500, 4300, 5200, 5800, 6500, 7300, 8000, 9600, 10500, 12000, 13800, 15000, 17200, 20000, 21500, 24000, 26000
};
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	g_AdminListen = register_cvar("amx_listen", "1")
	g_AdminListenFlag = register_cvar("amx_listen_flag", "c")

	register_clcmd("say", "hook_say")
	register_clcmd("say_team", "hook_teamsay")
	register_clcmd("say /myrank", "cmdJumpRank")
	register_clcmd("say_team /myrank", "cmdJumpRank")
	register_clcmd("say /checkrank", "cmdCheckLevel")
	register_clcmd("say_team /checkrank", "cmdCheckLevel")
	register_clcmd("say /rankmenu", "cmdRankMenu", ADMIN_RCON)
	register_clcmd("say_team /rankmenu", "cmdRankMenu", ADMIN_RCON)

	register_concmd("Points_Amount", "cmdTyped", ADMIN_RCON);

	sayText = get_user_msgid("SayText")
	teamInfo = get_user_msgid("TeamInfo")
	maxPlayers = get_maxplayers()
	g_MsgHud = CreateHudSyncObj()
	
	register_message(sayText, "avoid_duplicated")
	register_event("DeathMsg", "Hook_Deathmessage", "a");
	RegisterHam(Ham_Spawn, "player", "player_spawn", 1);
	
	set_task(1.0, "taskHud", 0, _, _, "b")
	
	gVault = nvault_open( "PlayerRanks" );
}

public player_spawn(id)
{
	if( !is_user_alive( id ) ) return;

	if(MAXRANKS == PlayerRank[id]+1)
		ColorChat(id, RED, "[BetterPlay]^x01 Your level is ^x04#%d ^x01with rank ^x04%s ^x01. You have got ^x03 %d points", PlayerRank[id]+1, rankNames[PlayerRank[id]], gPlayerPoints[id])
	else
		ColorChat(id, RED, "[BetterPlay]^x01 Your level is ^x04#%d ^x01with rank ^x04%s^x01. You have got ^x03 %d^x01 /^x04 %d^x01 points to become^x04 %s^x01.", PlayerRank[id]+1, rankNames[PlayerRank[id]], gPlayerPoints[id], rankXP[PlayerRank[id]+1], rankNames[PlayerRank[id]+1])
	
	switch( PlayerRank[ id ] )
	{
		case 28: set_user_health( id, get_user_health( id ) + 5 );
		case 29: set_user_health( id, get_user_health( id ) + 10 );
		case 30: set_user_health( id, get_user_health( id ) + 15 );
		case 31: set_user_health( id, get_user_health( id ) + 20 );
		case 32: set_user_health( id, get_user_health( id ) + 30 );
	}
}

public cmdCheckLevel(id)
{
	new iMenu = menu_create("\yBetterPlay \d- \wChoose Player\r:", "checklevel_menu_handler")
	
	new iPlayers[32], iNum, iTarget;
	new UserName[34], szTempID[10];
	get_players(iPlayers, iNum);
	for(new i; i < iNum; i++)
	{
		iTarget = iPlayers[i];
		if(!is_user_connected(iTarget))
			continue;
		get_user_name(iTarget, UserName, sizeof UserName - 1);
		num_to_str(iTarget, szTempID, charsmax(szTempID));
		menu_additem(iMenu, UserName, szTempID);
	}
	menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, iMenu, 0);
}

public checklevel_menu_handler(id, iMenu, Item)
{
	if(Item == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return PLUGIN_HANDLED;
	}
	new iData[6], iName[64];
	new access, callback;
	menu_item_getinfo(iMenu, Item, access, iData, charsmax(iData), iName, charsmax(iName), callback);
	new target = str_to_num(iData);
	if(!is_user_connected(target))
	{
		ColorChat(id, GREEN, "[BetterPlay]^x01 The player you chose is not in the server.")
		menu_destroy(iMenu);
		cmdCheckLevel(id);
		return PLUGIN_HANDLED;
	}
	menu_destroy(iMenu);
	new szText[256], player_name[32];
	get_user_name(target, player_name, 31);
	if(MAXRANKS == PlayerRank[target]+1)
		formatex(szText, charsmax(szText), "<html><head></head><body><br/>Name: %s<br/>Points: %d<br/>Level: %d/%d<br/>Rank: %s<br/></body></html>", player_name, gPlayerPoints[target], PlayerRank[target]+1, MAXRANKS, rankNames[PlayerRank[target]]);
	else
		formatex(szText, charsmax(szText), "<html><head></head><body><br/>Name: %s<br/>Points: %d/%d<br/>Level: %d/%d<br/>Rank: %s<br/>Next Rank: %s</body></html>", player_name, gPlayerPoints[target], rankXP[PlayerRank[target]+1], PlayerRank[target]+1, MAXRANKS, rankNames[PlayerRank[target]], rankNames[PlayerRank[target]+1]);
	show_motd(id, szText, "BetterPlay Rank System");
	cmdCheckLevel(id);
	return PLUGIN_HANDLED;
}

public taskHud()
{
	new iPlayers[32], iNum, iTarget;
	get_players(iPlayers, iNum);
	for(new i; i < iNum; i++)
	{
		iTarget = iPlayers[i];
		if(!is_user_connected(iTarget))
			continue;
	
		set_hudmessage(0, 139, 139, 0.02, 0.17, 0, 6.0, 12.0)
		if(MAXRANKS == PlayerRank[iTarget]+1)
			ShowSyncHudMsg(iTarget, g_MsgHud, "Level: %d/%d^nRank : %s^nPoints : %d",PlayerRank[iTarget]+1, MAXRANKS, rankNames[PlayerRank[iTarget]], gPlayerPoints[iTarget])
		else
			ShowSyncHudMsg(iTarget, g_MsgHud, "Level: %d/%d^nRank : %s^nPoints : %d/%d",PlayerRank[iTarget]+1, MAXRANKS, rankNames[PlayerRank[iTarget]], gPlayerPoints[iTarget], rankXP[PlayerRank[iTarget]+1])
	}
}

public cmdJumpRank(id)
{
	if(MAXRANKS == PlayerRank[id]+1)
		ColorChat(id, RED, "[BetterPlay]^x01 Your level is ^x04#%d ^x01| Rank ^x04%s ^x01| Points:^x03 %d", PlayerRank[id]+1, rankNames[PlayerRank[id]], gPlayerPoints[id])
	else
		ColorChat(id, RED, "[BetterPlay]^x01 Your level is ^x04#%d ^x01| Rank ^x04%s ^x01| Points:^x03 %d^x01 /^x04 %d^x01 to become^x04 %s^x01.", PlayerRank[id]+1, rankNames[PlayerRank[id]], gPlayerPoints[id], rankXP[PlayerRank[id]+1], rankNames[PlayerRank[id]+1])
}

public cmdRankMenu(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED;
	new iMenu = menu_create("Rank Menu", "rankmenu_menu_handler")
	menu_additem(iMenu, "Give Points", "1");
	menu_additem(iMenu, "Take Points", "2");
	menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, iMenu, 0);
	return PLUGIN_CONTINUE;
}

public rankmenu_menu_handler(id, iMenu, Item)
{
	if(Item == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return PLUGIN_HANDLED;
	}
	new iData[6], iName[64];
	new access, callback;
	menu_item_getinfo(iMenu, Item, access, iData, charsmax(iData), iName, charsmax(iName), callback);
	give[id] = str_to_num(iData);
	GiveTakeMenu(id);
	return PLUGIN_HANDLED;
}

public GiveTakeMenu(id)
{
	static szText[64]
	formatex(szText, 63, "%s Points", give[id] == 1 ? "Give" : "Take")
	new iMenu = menu_create(szText, "givetake_menu_handler")

	new iPlayers[32], iNum, iTarget;
	new UserName[34], szTempID[10];
	get_players(iPlayers, iNum);
	for(new i; i < iNum; i++)
	{
		iTarget = iPlayers[i];
		if(!is_user_connected(iTarget))
			continue;
		get_user_name(iTarget, UserName, sizeof UserName - 1);
		num_to_str(iTarget, szTempID, charsmax(szTempID));
		menu_additem(iMenu, UserName, szTempID);
	}
	menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, iMenu, 0);
}

public givetake_menu_handler(id, iMenu, Item)
{
	if(Item == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return PLUGIN_HANDLED;
	}

	new iData[6], iName[64];
	new access, callback;
	menu_item_getinfo(iMenu, Item, access, iData, charsmax(iData), iName, charsmax(iName), callback);
	iTarget[id] = str_to_num(iData);
	if(!is_user_connected(iTarget[id]))
	{
		iTarget[id] = 0
		ColorChat(id, GREEN, "[BetterPlay]^x01 The player you chose is not in the server.")
		return PLUGIN_HANDLED;
	}
	menu_destroy(iMenu);
	client_cmd(id, "messagemode Points_Amount");
	return PLUGIN_HANDLED;
}

public cmdTyped(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1))
		return PLUGIN_HANDLED;

	if(!iTarget[id] || give[id] <= 0)
		return PLUGIN_HANDLED;
	if(!is_user_connected(iTarget[id]))
	{
		ColorChat(id, RED, "[BetterPlay]^x01 The player you chose is not in the server.")
		return PLUGIN_HANDLED;
	}

	new iTyped[12];
	read_argv(1, iTyped, sizeof iTyped - 1);
	new g_points = str_to_num(iTyped)
	new AdminName[32], PlayerName[32];
	get_user_name(id, AdminName, 31)
	get_user_name(iTarget[id], PlayerName, 31)
	if(give[id] == 1)
	{
		gPlayerPoints[iTarget[id]] += g_points
		ColorChat(0, GREEN,"[BetterPlay]^x03 %s^x01 gave^x04 %d^x01 rank points to^x03 %s^x01.", AdminName, g_points, PlayerName)
	}
	else
	{
		if(g_points > gPlayerPoints[iTarget[id]])
			gPlayerPoints[iTarget[id]] = 0
		else
			gPlayerPoints[iTarget[id]] -= g_points;
		ColorChat(0, GREEN,"[BetterPlay]^x03 %s^x01 took^x04 %d^x01 rank points from^x03 %s^x01.", AdminName, g_points, PlayerName)
	}
	new currentPlayerRank = 0;
	while(currentPlayerRank < (MAXRANKS - 1))
	{       
		if(gPlayerPoints[iTarget[id]] >= rankXP[currentPlayerRank + 1])
			++currentPlayerRank;     
		else         
			break;
	}
	PlayerRank[iTarget[id]] = currentPlayerRank;
	iTarget[id] = 0;
	GiveTakeMenu(id);
	Save( id );
	return PLUGIN_HANDLED;
}

public client_authorized( id )
{
	Load( id );
}

public client_disconnect( id )
{
	Save( id );
}

public client_putinserver(id)
{
	new currentPlayerRank = 0;
	while(currentPlayerRank < (MAXRANKS - 1))
	{       
		if(gPlayerPoints[id] >= rankXP[currentPlayerRank + 1])
			++currentPlayerRank;     
		else         
			break;
	}
	PlayerRank[id] = currentPlayerRank;
}

public Load( id )
{
	if( !is_user_bot( id ) && !is_user_hltv( id ) )
	{
		new vaultkey[ 64 ], vaultdata[ 256 ], points[ 33 ], UserName[ 33 ];
		get_user_name( id, UserName, charsmax( UserName ) );
		
		format( vaultkey, charsmax( vaultkey ), "%s", UserName );
		format( vaultdata, charsmax( vaultdata ), "%i#", gPlayerPoints[ id ] );
		
		nvault_get( gVault, vaultkey, vaultdata, 255 );
		replace_all( vaultdata, 255, "#", " " );
		
		parse( vaultdata, points, 32 );
		gPlayerPoints[ id ] = str_to_num( points );
	}
}

public Save( id )
{
	if( !is_user_bot( id ) && !is_user_hltv( id ) )
	{
		new vaultkey[ 64 ], vaultdata[ 256 ], UserName[ 33 ];
		get_user_name( id, UserName, charsmax( UserName ) );
		
		format( vaultkey, charsmax( vaultkey ), "%s", UserName );
		format( vaultdata, charsmax( vaultdata ), "%i#", gPlayerPoints[ id ] );
		
		nvault_set( gVault, vaultkey, vaultdata );
	}
}

public avoid_duplicated(msgId, msgDest, receiver)
	return PLUGIN_HANDLED;

public hook_say(id)
{
	read_args(message, 191)
	remove_quotes(message)

	if(message[0] == '@' || message[0] == '/' || message[0] == '!' || message[0] == '#' || message[0] == '$' || equal(message, ""))
		return PLUGIN_CONTINUE

	get_user_name(id, g_name, charsmax(g_name))

	new isAlive	
	new admin = 0, iFlags = get_user_flags(id)
	if(iFlags & ADMIN_LEVEL_B) admin = 1  //owner
	else if(iFlags & ADMIN_LEVEL_C) admin = 2   //administrator
 	else if(iFlags & ADMIN_LEVEL_D) admin = 3  //global
	else if(iFlags&  ADMIN_LEVEL_G) admin=4 //otgowornik
	else if(iFlags& ADMIN_LEVEL_H) admin=5  //ekip banove
	else if(iFlags & ADMIN_BAN) admin = 6  //admin
	else if(iFlags & ADMIN_LEVEL_F) admin = 7  //test
	else if(iFlags & ADMIN_LEVEL_E) admin = 8  //vip
	else if(iFlags & ADMIN_CHAT) admin = 9  //sms admin
	

	if(is_user_alive(id))
	{
		isAlive = 1
		alive = "^x01"
	}
	else
	{
		isAlive = 0
		alive = "^x01*DEAD* "
	}

	static  color[10]
	if(admin)
	{
		get_user_team(id, color, 9)
		format(strName, 191, "%s^x01[^x04%s^x01] ^x03%s ", alive, g_szTag[admin], g_name)
		format(strText, 191, "^x01%s", message)
	}
	else
	{
		get_user_name(id, g_name, 32)
		get_user_team(id, color, 9)
		format(strName, 191, "%s^x04%s ^x03%s", alive, rankNames[PlayerRank[id]], g_name)
		format(strText, 191, "%s", message)
	}

	format(message, 191, "%s ^x01: %s", strName, strText)

	sendMessage(color, isAlive)// Sends the colored message
	return PLUGIN_CONTINUE;
}

public hook_teamsay(id)
{
	read_args(message, 191)
	remove_quotes(message)

	if(message[0] == '@' || message[0] == '/' || message[0] == '!' || message[0] == '#' || message[0] == '$' || equal(message, "")) // Ignores Admin Hud Messages, Admin Slash commands
		return PLUGIN_CONTINUE

	new playerTeam = get_user_team(id)
	new playerTeamName[19]

	switch(playerTeam) // Team names which appear on team-only messages
	{
		case 1: copy(playerTeamName, 11, "Terrorists")
		case 2: copy(playerTeamName, 18, "Counter-Terrorists")
		default: copy(playerTeamName, 9, "Spectator")
	}

	get_user_name(id, g_name, charsmax(g_name))
	new isAlive	
	new admin = 0, iFlags = get_user_flags(id)
	if(iFlags & ADMIN_LEVEL_B) admin = 1  //owner
	else if(iFlags & ADMIN_LEVEL_C) admin = 2   //administrator
 	else if(iFlags & ADMIN_LEVEL_D) admin = 3  //global
	else if(iFlags&  ADMIN_LEVEL_G) admin=4 //otgowornik
	else if(iFlags& ADMIN_LEVEL_H) admin=5  //ekip banove
	else if(iFlags & ADMIN_BAN) admin = 6  //admin
	else if(iFlags & ADMIN_LEVEL_F) admin = 7  //test
	else if(iFlags & ADMIN_LEVEL_E) admin = 8  //vip
	else if(iFlags & ADMIN_CHAT) admin = 9  //sms admin

	if(is_user_alive(id))
	{
		isAlive = 1
		alive = "^x01"
	}
	else
	{
		isAlive = 0
		alive = "^x01*DEAD* "
	}

	static  color[10]
	if(admin)
	{
		get_user_team(id, color, 9)
		format(strName, 191, "%s(%s) ^x01[^x04%s^x01] ^x03%s ", alive, playerTeamName,  g_szTag[admin], g_name)
		format(strText, 191, "^x01%s", message)
	}
	else
	{
		get_user_name(id, g_name, 32)
		get_user_team(id, color, 9);
		format(strName, 191, "%s(%s) ^x04%s ^x03%s", alive, playerTeamName, rankNames[PlayerRank[id]], g_name)
		format(strText, 191, "%s", message)
	}

	format(message, 191, "%s ^x01: %s", strName, strText)
	sendTeamMessage(color, isAlive, playerTeam)
	return PLUGIN_CONTINUE
}

public sendMessage(color[], alive)
{
	new teamName[10]
   
	for(new player = 1; player < maxPlayers; player++)
	{
		if(!is_user_connected(player))
			continue

		get_pcvar_string(g_AdminListenFlag, temp_cvar, charsmax(temp_cvar))
		if(alive && is_user_alive(player) || !alive && !is_user_alive(player) || get_pcvar_num(g_AdminListen) && get_user_flags(player) & read_flags(temp_cvar))
		{
			get_user_team(player, teamName, 9)// Stores user's team name to change back after sending the message
			changeTeamInfo(player, color)// Changes user's team according to color choosen
			writeMessage(player, message)// Writes the message on player's chat
			changeTeamInfo(player, teamName)// Changes user's team back to original
		}
	}
}

public sendTeamMessage(color[], alive, playerTeam)
{
	new teamName[10]

	for(new player = 1; player < maxPlayers; player++)
	{
		if(!is_user_connected(player))
			continue

		get_pcvar_string(g_AdminListenFlag, temp_cvar, charsmax(temp_cvar))
		if(get_user_team(player) == playerTeam || get_pcvar_num(g_AdminListen) && get_user_flags(player) & read_flags(temp_cvar))
		{
			if(alive && is_user_alive(player) || !alive && !is_user_alive(player) || get_pcvar_num(g_AdminListen) && get_user_flags(player) & read_flags(temp_cvar))
			{
				get_user_team(player, teamName, 9)// Stores user's team name to change back after sending the message
				changeTeamInfo(player, color)// Changes user's team according to color choosen
				writeMessage(player, message)// Writes the message on player's chat
				changeTeamInfo(player, teamName)// Changes user's team back to original
			}
		}
	}
}


public changeTeamInfo(player, team[])
{
	message_begin(MSG_ONE, teamInfo, _, player)// Tells to to modify teamInfo(Which is responsable for which time player is)
	write_byte(player)// Write byte needed
	write_string(team)// Changes player's team
	message_end()// Also Needed
}


public writeMessage(player, message[])
{
	message_begin(MSG_ONE, sayText, {0, 0, 0}, player)// Tells to modify sayText(Which is responsable for writing colored messages)
	write_byte(player)// Write byte needed
	write_string(message)// Effectively write the message, finally, afterall
	message_end()// Needed as always
}

public Hook_Deathmessage()
{
	new killer = read_data(1);
	new victim = read_data(2);

	if(killer == victim)
		return PLUGIN_CONTINUE;
	if(!killer || killer > maxPlayers)
		return PLUGIN_CONTINUE;

	gPlayerPoints[killer]++
	new currentPlayerRank = 0;
	while(currentPlayerRank < (MAXRANKS - 1))
	{       
		if(gPlayerPoints[killer] >= rankXP[currentPlayerRank + 1])
			++currentPlayerRank;     
		else         
			break;
	}
	new OldRank = PlayerRank[killer]
	PlayerRank[killer] = currentPlayerRank
	Save( killer );
	if(OldRank < currentPlayerRank)
	{
		new g_name[32]
		get_user_name(killer, g_name, 31)
		ColorChat(0, GREEN, "[BetterPlay] ^1Congratulations! ^x03%s^x01 got a new rank ^x04%s", g_name, rankNames[PlayerRank[killer]])
	}
	return PLUGIN_CONTINUE;
}