Raised This Month: $ Target: $400
 0% 

want to use the wtj function from PTB in a small plugin


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
RCC|Dynamite
Senior Member
Join Date: May 2004
Location: Germany
Old 05-26-2005 , 12:39   want to use the wtj function from PTB in a small plugin
Reply With Quote #1

Code:
#include <amxmodx>
#include <amxmisc>

#define ACCESS_wtj ADMIN_RCON

// team ids
#define UNASSIGNED	 	0
#define TS 				1
#define CTS				2
#define AUTO_TEAM 		5

new const WTJ_VERSION[] = "0.1beta"

// Uncomment to activate log debug messages.
//#define WTJ_DEBUG
//#define WTJ_DEBUG2

// If you experiance some problems with team switching then uncomment line below
//#define MANUAL_SWITCH

// If you are running CS 1.5 then comment line below
#define CS16_SWITCH

// team selection control
new bool:WTJ_KICK = true // kick for wtj counts
new bool:WTJ_SAVEWTJ = false // save wtjs to wtj.log

// messages
new bool:WTJ_TELLWTJ = true // tell about wtj tries

// sorted player indices are 0-based

new wtConditions[3]
new winnerTeam
new loserTeam

new Float:ctKD
new Float:tKD
new Float:ctStrength
new Float:tStrength
new Float:ctRating
new Float:tRating

// player arrays are 1-based, there is no player 0
#if defined CS16_SWITCH
new clientVGUIMenu[33][2]
#endif
new wtjCount[33]

public plugin_init(){
	register_plugin("Team Balancer",WTJ_VERSION,"Ptahhotep")
	register_cvar("amx_WTJ_version",WTJ_VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
#if defined CS16_SWITCH
	register_menucmd(register_menuid("Team_Select",1),(1<<0)|(1<<1)|(1<<4),"teamselect")
	register_event("ShowMenu","menuclass","b","4&CT_Select","4&Terrorist_Select")
	register_clcmd("jointeam","jointeam")
#else
	register_menucmd(register_menuid("Team_Select",1),(1<<0)|(1<<1)|(1<<4),"teamselect")
	register_menucmd(-2,(1<<0)|(1<<1)|(1<<4),"teamselect")    // VGUI menu
#endif
	register_event("SendAudio","round_end","a","2=%!MRAD_terwin","2=%!MRAD_ctwin","2=%!MRAD_rounddraw") // Round End
	register_event("TeamScore","team_score","a") // Team Score
	register_event("RoundTime", "new_round", "bc") // Round Time
	register_event("DeathMsg","death_msg","a") // Kill
	register_event("TeamInfo","team_assign","a") // Team Assigment (also UNASSIGNED and SPECTATOR)
	register_event("TextMsg","team_join","a","1=1","2&Game_join_te","2&Game_join_ct") // Team Joining
	register_event("TextMsg","game_restart","a","1=4","2&#Game_C","2&#Game_w") // Game restart
	register_concmd("amx_WTJ","admin_WTJ",ACCESS_WTJ,"- displays WTJ options")

	new custompath[256]
	get_customdir(custompath, 255)
	format(custompath, 255, "exec %s/WTJ.cfg", custompath)
	server_cmd(custompath)

	#if defined WTJ_DEBUG2
	register_event("VGUIMenu","debugmenu","b")
	register_event("ShowMenu","debugmenu","b")
	register_clcmd("say /team","switchteam")
	register_clcmd("say /vgui","switchvgui")
	register_clcmd("menuselect","debugselect")
	#endif

#if defined CS16_SWITCH
	// Init clients VGUI-menu setting
	// Set terminating 0 to allow use of char processing instead of string
	// to improve performance.
	for (new i=0;i<33;i++){
		clientVGUIMenu[i][0] = '0'
		clientVGUIMenu[i][1] = 0
	}
#endif

	return PLUGIN_CONTINUE
}

checkTeamSwitch(id,iNewTeam) {
	// don't care where player joins
	if (!WTJ_LIMITJOIN) return PLUGIN_CONTINUE
	// Protection for admins
	if (get_user_flags(id) & ADMIN_IMMUNITY) return PLUGIN_CONTINUE
	// players is transfered so don't care with rest
	if (isBeingTransfered[id]) {
		//say("TRANSFER")
		isBeingTransfered[id] = false
		return PLUGIN_CONTINUE
	}
	//say("NO TRANSFER")
	// skip limiting for a few rounds into the map
	if (WTJ_LIMITAFTER && roundCounter <= WTJ_LIMITAFTER) return PLUGIN_CONTINUE
	// skip limiting for a small number of players
	if (get_playersnum() < WTJ_LIMITMIN) return PLUGIN_CONTINUE

	new iOldTeam = playerTeam[id]

	// disallow free team choices in the first rounds of a map
	if (WTJ_AUTOROUNDS&&(iOldTeam==UNASSIGNED)&&roundCounter<=WTJ_AUTOROUNDS)
		iNewTeam = AUTO_TEAM

	// prevent unwanted rejoining of the same team ...
	if (iNewTeam == iOldTeam) {
		//say("Preventing rejoining of the same team.")
		client_print(id,print_chat,"WTJ: Joining to the same team is not allowed...")
#if !defined MANUAL_SWITCH
		engclient_cmd(id,"chooseteam") // display menu again
#endif
		return PLUGIN_HANDLED
	}

	checkTeamBalance()
	//displayStatistics(0,true)

	// Player for sure was in CT or T team and now is joining to the opposite team
	if ((iNewTeam==CTS&&iOldTeam==TS)||(iNewTeam==TS&&iOldTeam==CTS)){
		// If someone is in new team and old team weren't full
		// and the winning team is a destination team or in
		// new team is more players than in old then treat it as wtj
		if ( teamCounts[iNewTeam]&&(teamCounts[iOldTeam]<WTJ_MAXSIZE)&&
			((iNewTeam==winnerTeam)||(teamCounts[iNewTeam]>=teamCounts[iOldTeam])) ) {
			// player is wtjing
			new text[256],name[32]
			get_user_name(id,name,31)
			// Kick wtj player if reached set limit
			if (++wtjCount[id] >= WTJ_WTJKICK && WTJ_KICK) {
				format(text, 255, "WTJ: Kicking %s for a WTJ count %d of %d.", name, wtjCount[id],WTJ_WTJKICK )
				doTypesay(text, 5, 0, 255, 0)
				say(text)
				server_cmd("kick #%d",get_user_userid(id))
				return PLUGIN_HANDLED
			}
			// Announce about WTJ
			if (WTJ_TELLWTJ) {
				if (iNewTeam == CTS) {
					format(text, 255, "WTJ: The CTs are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
					doTypesay(text, 5, 0, 50, 255)
				}
				else {
					format(text, 255, "WTJ: The Ts are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
					doTypesay(text, 5, 255, 50, 0)
				}
				say(text)
			}
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		// check for maximum team size
		if (teamCounts[iNewTeam] >= WTJ_MAXSIZE) {
			client_print(id,print_chat,"WTJ: Maximum team size prohibits team change.")
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		// check team size difference limits
		if ( teamCounts[iNewTeam]+1-teamCounts[iOldTeam] >= WTJ_MAXDIFF ) {
			client_print(id,print_chat,"WTJ: Maximum team size difference prohibits team change.")
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		return PLUGIN_CONTINUE // OK! He can join to the oppsoite team!!!
	}

	// Player is choosing his team for the first time!
	if (iNewTeam==CTS||iNewTeam==TS){
		// Get opposite team
		new opposingTeam = (iNewTeam==CTS)? TS : CTS
		// Players is joining to one team but the opposite is not full
		// and his team is bettter then opposite or has more players
		if (teamCounts[iNewTeam] && teamCounts[opposingTeam]<WTJ_MAXSIZE &&
		     (iNewTeam==winnerTeam||(!winnerTeam&&teamCounts[iNewTeam]>teamCounts[opposingTeam]))) {
			new text[256],name[32]
			get_user_name(id,name,31)
			if (++wtjCount[id] >= WTJ_WTJKICK && WTJ_KICK) {
				format(text, 255, "WTJ: Kicking %s for a WTJ count %d of %d.", name, wtjCount[id],WTJ_WTJKICK)
				doTypesay(text, 5, 0, 255, 0)
				say(text)
				server_cmd("kick #%d", get_user_userid(id))
				return PLUGIN_HANDLED
			}
			if (iNewTeam==CTS) {
				if (wtjCount[id]>=WTJ_WTJAUTO) {
					manageWtjFile(id)
					format(text, 255, "WTJ: Forcing %s to the Ts (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
#if defined CS16_SWITCH
					engclient_cmd(id,"jointeam","1")
#else
#if defined MANUAL_SWITCH
					client_cmd(id,"chooseteam;menuselect 1")
#else
					engclient_cmd(id,"menuselect","1")
#endif
#endif
					doTypesay(text, 5, 255, 50, 0)
					say(text)
				}
				else if (WTJ_TELLWTJ) {
					format(text, 255, "WTJ: The CTs are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
					doTypesay(text, 5, 0, 50, 255)
					say(text)
#if !defined MANUAL_SWITCH
					engclient_cmd(id,"chooseteam") // display menu again
#endif
				}
			}
			else {
				if (wtjCount[id]>=WTJ_WTJAUTO) {
					manageWtjFile(id)
					format(text, 255, "WTJ: Forcing %s to the CTs (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
#if defined CS16_SWITCH
					engclient_cmd(id,"jointeam","2")
#else
#if defined MANUAL_SWITCH
					client_cmd(id,"chooseteam;menuselect 2")
#else
					engclient_cmd(id,"menuselect","2")
#endif
#endif
					doTypesay(text, 5, 0, 50, 255)
					say(text)
				}
				else if (WTJ_TELLWTJ) {
					format(text, 255, "WTJ: The Ts are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],WTJ_WTJKICK)
					doTypesay(text, 5, 255, 50, 0)
					say(text)
#if !defined MANUAL_SWITCH
					engclient_cmd(id,"chooseteam") // display menu again
#endif
				}
			}
			return PLUGIN_HANDLED
		}
		// check for maximum team size
		if (teamCounts[iNewTeam] >= WTJ_MAXSIZE) {
			client_print(id,print_chat,"WTJ: Maximum team size prohibits team join.")
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		// check team size difference limits
		if ( teamCounts[iNewTeam]-teamCounts[opposingTeam] >= WTJ_MAXDIFF) {
			client_print(id,print_chat,"WTJ: Maximum team size difference prohibits team join.")
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		return PLUGIN_CONTINUE // OK! He can join to the oppsoite team!!!
	}

	// He is choosing the AUTO-SELECT but he was already in game (He wants to play fair!)
	if (iNewTeam==AUTO_TEAM&&(iOldTeam==CTS||iOldTeam==TS)) {
		//say("Changing team automatically.")
		new opposingTeam = (iOldTeam==CTS) ? TS : CTS
		if (teamCounts[opposingTeam] && ( (teamCounts[opposingTeam]>=WTJ_MAXSIZE)
				|| (iOldTeam==loserTeam) || (!loserTeam&&teamCounts[iOldTeam]<=teamCounts[opposingTeam])
				|| (teamCounts[opposingTeam]+1-teamCounts[iOldTeam]>=WTJ_MAXDIFF)) ) {
			client_print(id,print_chat,"WTJ: You have better stay in your current team...")
			return PLUGIN_HANDLED
		}
		client_print(id,print_chat,"WTJ: You have been auto-assigned...")
#if defined CS16_SWITCH
		engclient_cmd(id,"jointeam",(opposingTeam==CTS)?"2":"1")
#else
#if defined MANUAL_SWITCH
		client_cmd(id,"chooseteam;menuselect %d",(opposingTeam==CTS) ? 2 : 1 )
#else
		engclient_cmd(id,"menuselect",(opposingTeam==CTS) ? "2" : "1")
#endif
#endif
		return PLUGIN_HANDLED
	}
	// He is choosing the team for the first time with AUTO-SELECT (What a nice kid!)
	if (iNewTeam==AUTO_TEAM) {
		/* this is the "always smaller team" version
		if (teamCounts[CTS] < teamCounts[TS] || teamCounts[TS] >= WTJ_MAXSIZE) iNewTeam = CTS
		else if (teamCounts[TS] < teamCounts[CTS] || teamCounts[CTS] >= WTJ_MAXSIZE) iNewTeam = TS
		// both teams have same size ...
		else if (winnerTeam && teamCounts[loserTeam]<WTJ_MAXSIZE) iNewTeam = loserTeam
		else if (teamCounts[TS] >= WTJ_MAXSIZE) iNewTeam = CTS
		else if (teamCounts[CTS] >= WTJ_MAXSIZE) iNewTeam = TS
		else iNewTeam = (random_num(0,100) < 50) ? CTS : TS
		*/
		// this version prefers the losing team (but still honors WTJ_MAXDIFF)
		if (teamCounts[CTS] >= WTJ_MAXSIZE) iNewTeam = TS
		else if (teamCounts[TS] >= WTJ_MAXSIZE) iNewTeam = CTS
		else if (teamCounts[CTS]-teamCounts[TS] >= WTJ_MAXDIFF) iNewTeam = TS
		else if (teamCounts[TS]-teamCounts[CTS] >= WTJ_MAXDIFF) iNewTeam = CTS
		else if (winnerTeam) iNewTeam = loserTeam
		else if (teamCounts[CTS]<teamCounts[TS]) iNewTeam = CTS
		else if (teamCounts[TS]<teamCounts[CTS]) iNewTeam = TS
		// both teams have same size ...
		else iNewTeam = (random_num(0,100) < 50) ? CTS : TS
		// check for maximum team size
		if (teamCounts[iNewTeam]>=WTJ_MAXSIZE) {
			client_print(id,print_chat,"WTJ: Maximum team size prohibits team join.") // ??? - only a spectator???
#if !defined MANUAL_SWITCH
			engclient_cmd(id,"chooseteam") // display menu again
#endif
			return PLUGIN_HANDLED
		}
		client_print(id,print_chat,"WTJ: You have been auto-assigned...")
#if defined CS16_SWITCH
		engclient_cmd(id,"jointeam",(iNewTeam==CTS)?"2":"1")
#else
#if defined MANUAL_SWITCH
		client_cmd(id,"chooseteam;menuselect %d",(iNewTeam==CTS) ? 2 : 1 )
#else
		engclient_cmd(id,"menuselect",(iNewTeam == CTS) ? "2" : "1")
#endif
#endif
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
This ist only the code from PTB somebody know, how i can make it work that only the WTJ funktion use.

thx 4 help

Dynamite
__________________

|###########|
|###########|
|###########|
RCC|Dynamite is offline
Send a message via ICQ to RCC|Dynamite
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode