hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.06.04. 10:41



Jelenlévő felhasználók

Jelenleg 197 felhasználó van jelen :: 0 regisztrált, 0 rejtett és 197 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: nincs regisztrált felhasználó az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 1 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: Amx PTB 1.8.b3
HozzászólásElküldve: 2014.01.26. 02:46 
Offline
Minden6ó
Avatar

Csatlakozott: 2011.01.19. 12:14
Hozzászólások: 4292
Megköszönt másnak: 219 alkalommal
Megköszönték neki: 287 alkalommal
Hali! Valaki lefordítaná?
SMA Forráskód: [ Mindet kijelol ]
  1. /*
  2.  * Ptahhotep's Team Balancer (PTB)
  3.  * Version 1.8b1
  4.  * AUTHOR: Ptahhotep (ptahhotep@planethalflife.com)
  5.  *
  6.  * 1.7b3 PTB converted for AMX Mod by OLO
  7.  * 1.7b5 Modified for CS 1.6 by XAD.
  8.  * Thanks Redmist ("slot1" to close old-style-menus).
  9.  * Added fix by 'Panzermensh' for lost kill when moved
  10.  * (thanks r0otd0wn).
  11.  * 1.7b6 Ported to AMX Mod X 0.16 by XAD.
  12.  * Changed config file path to configs/ptb.cfg
  13.  * 1.7b7 Added admin immunity by Ingerfara. (Thanks to EpsychE and rootdown)
  14.  * 1.7b8 JGHG: changed the path of ptb.cfg to use AMXx's default custom path.
  15.  
  16.  * 1.7b9.2 lantz69: 2005-10-03
  17.   - changed how players are transfered and cleaned up the code.
  18. - Players are now transfered without being killed and they also keep their weapons
  19. - lastRoundSwitched[id] is also updated at transfers. Before the amx_ptb playerfreq was broken
  20.  
  21.  * 1.7b9.3 lantz69: 2006-01-12
  22. - small fix for client_prints.
  23.  
  24.  * 1.8b1 lantz69: 2006-04-05
  25. - ptb.cfg is now back in addons/amxmodx/configs/
  26. - wtj.log is now in addons/amxmodx/logs/
  27. - using amxmodx function floatabs
  28. - added amxmodx 1.70 autochanneling for hud messages
  29. - admins with kick flag is able to join spec even if autojoin is enabled
  30. - new cvars ptb_switch_immunity and ptb_limitjoin_immunity. (in ptb.cfg)
  31. Now it's easy to disable admins immunity.
  32.  
  33. * 1.8b2 lantz69: 2006-08-03
  34. - If player has defuse kit before a transfer it will be removed (thx teame06)
  35. - Added compile option #define SHOW_IN_HLSW To be able to remove transfers being showed in HLSW chat (Sug. Brad)
  36.  
  37. * 1.8b3 lantz69: 2007-03-03
  38. - Fixed so you can have mp_roundtime to almost whatever you want and PTB will still work.
  39. Before PTB did not work if you had mp_roundtime set to 2.10 or 1.75 etc It had to be 1.5, 2.0, 2.5 etc
  40. - Added log_message to hlds logs when a player is transfered (player X joined team ..) for PsychoStats 3.X
  41. - Changed the time player is transfered from 4.0 to 4.5 seconds
  42. - Added cvar ptb_immunity_level so you dont need to recompile to change the admin flag for immunity
  43. - Added cvar ptb_access_level so you dont need to recompile to change the admin flag for access to ptb
  44. - Added cvar ptb_show_in_hlsw If you want to see Transfers made in the HLSW chat have this set to 1
  45. - Added the above cvars into ptb.cfg ptb_immunity_level, ptb_show_in_hlsw and ptb_access_level
  46. - Made all cvars use the new pcvars system.
  47. - Added protection for VIP to be transfered (Uncomment #define PTB_VIP_IMMUNITY in the source for this to work)
  48.  
  49. *** TODO ******
  50. Make it MultiLingual
  51.  */
  52.  
  53. #include <amxmodx>
  54. #include <amxmisc>
  55. #include <cstrike>
  56.  
  57. // Uncomment for support immunity on VIP
  58. //#define PTB_VIP_IMMUNITY
  59.  
  60. // Uncomment to activate log debug messages.
  61. //#define PTB_DEBUG
  62.  
  63. // team ids
  64. #define UNASSIGNED 0
  65. #define TS 1
  66. #define CTS 2
  67. #define AUTO_TEAM 5
  68.  
  69. new const PTB_VERSION[] = "1.8b3"
  70.  
  71. // team selection control
  72. new bool:PTB_LIMITJOIN = true // set limits on team joining
  73. new PTB_LIMITAFTER = 0 // number of rounds after which teams limiting begins
  74. new PTB_LIMITMIN = 0 // number of minimum players on map for team limiting
  75. new PTB_MAXSIZE = 10 // maximum team size per team
  76. new PTB_MAXDIFF = 2 // maximum team size difference
  77. new PTB_AUTOROUNDS = 3 // number of first rounds into match, which allow autojoin only
  78. new PTB_WTJAUTO = 3 // wtj tries needed to become autojoined
  79. new PTB_WTJKICK = 5 // wtj tries needed to become kicked
  80. new bool:PTB_KICK = true // kick for wtj counts
  81. new bool:PTB_SAVEWTJ = false // save wtjs to wtj.log
  82.  
  83. // team balancing actions
  84. new bool:PTB_SWITCH = true // switch/transfer players
  85. new PTB_SWITCHAFTER = 0 // number of rounds after which switching begins
  86. new PTB_SWITCHMIN = 3 // number of minimum players on map for switching
  87. new PTB_SWITCHFREQ = 1 // relative next possible switch round
  88. new PTB_PLAYERFREQ = 3 // relative next possible switch round for player
  89. new PTB_FORCESWITCH = 3 // number of tries after which PTB switches alive, if neccessary
  90. new bool:PTB_DEADONLY = false // switch dead only
  91.  
  92. // messages
  93. new bool:PTB_TELLWTJ = true // tell about wtj tries
  94. new bool:PTB_ANNOUNCE = true // announce team status at beginning of round
  95. new bool:PTB_SAYOK = true // announce team status, if teams are alright
  96. new bool:PTB_TYPESAY = true // use typesay
  97.  
  98. // team strength limits
  99. new PTB_MAXSTREAK = 2 // max. allowed team win streak
  100. new PTB_MAXSCORE = 2 // max. allowed team score difference
  101. new Float:PTB_MINRATING = 1.5 // minimum critical team rating
  102. new Float:PTB_MAXRATING = 2.0 // maximum critical team rating
  103. new Float:PTB_SUPERRATING = 3.0 // super critical team rating
  104. new PTB_MAXINCIDENTS = 50 // maximum kills + deaths before the score is divided by PTB_SCALEDOWN
  105. new PTB_SCALEDOWN = 2 // divisor for kills and deaths, when PTB_MAXINCIDENTS is reached
  106.  
  107. // sorted player indices are 0-based
  108. new sortedTeams[3][32]
  109. new sortedValidTargets[3][32]
  110. new validTargetCounts[3]
  111.  
  112. new teamKills[3]
  113. new teamDeaths[3]
  114. new teamScores[3]
  115. new winStreaks[3]
  116.  
  117. new wtConditions[3]
  118. new winnerTeam
  119. new loserTeam
  120.  
  121. new Float:ctKD
  122. new Float:tKD
  123. new Float:ctStrength
  124. new Float:tStrength
  125. new Float:ctRating
  126. new Float:tRating
  127.  
  128. // player arrays are 1-based, there is no player 0
  129. new clientVGUIMenu[33][2]
  130. new bool:isBeingTransfered[33]
  131. new playerTeam[33]
  132. new lastRoundSwitched[33]
  133. new wtjCount[33]
  134. new teamCounts[3]
  135. new kills[33]
  136. new deaths[33]
  137.  
  138. new roundCounter
  139. new lastSwitchRound
  140. new couldNotSwitchCounter
  141.  
  142. new lastTeamBalanceCheck[32]
  143.  
  144. //New auto-channeling system in amxmodx 1.70
  145. new g_MyMsgSync
  146.  
  147. // pcvars
  148. new saychat
  149. new transfer_type
  150. new switch_immunity
  151. new limitjoin_immunity
  152. new immunity_level
  153. new access_level
  154. new show_in_hlsw
  155.  
  156. public plugin_init(){
  157. register_plugin("Team Balancer",PTB_VERSION,"Ptahhotep")
  158. register_cvar("amx_ptb_version",PTB_VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
  159.  
  160. saychat = register_cvar("ptb_saychat", "1")
  161. transfer_type = register_cvar("ptb_transfer_type", "1")
  162. switch_immunity = register_cvar("ptb_switch_immunity", "1")
  163. limitjoin_immunity = register_cvar("ptb_limitjoin_immunity", "1")
  164. immunity_level = register_cvar("ptb_immunity_level", "o")
  165. access_level = register_cvar("ptb_access_level", "l")
  166. show_in_hlsw = register_cvar("ptb_show_in_hlsw", "1")
  167.  
  168. register_menucmd(register_menuid("Team_Select",1),(1<<0)|(1<<1)|(1<<4),"teamselect")
  169. register_event("ShowMenu","menuclass","b","4&CT_Select","4&Terrorist_Select")
  170. register_clcmd("jointeam","jointeam")
  171. register_clcmd("team_join","team_join")
  172. #if defined PTB_DEBUG
  173. register_clcmd("say /last","check_lasttransfer")
  174. #endif
  175. register_event("SendAudio","round_end","a","2=%!MRAD_terwin","2=%!MRAD_ctwin","2=%!MRAD_rounddraw") // Round End
  176. register_event("TeamScore","team_score","a") // Team Score
  177. register_event("RoundTime", "new_round", "bc") // Round Time
  178. register_event("DeathMsg","death_msg","a") // Kill
  179. register_event("TeamInfo","team_assign","a") // Team Assigment (also UNASSIGNED and SPECTATOR)
  180. register_event("TextMsg","team_join","a","1=1","2&Game_join_te","2&Game_join_ct") // Team Joining
  181. register_event("TextMsg","game_restart","a","1=4","2&#Game_C","2&#Game_w") // Game restart
  182. register_concmd("amx_ptb","admin_ptb",get_access_level_flag(),"- displays PTB options")
  183.  
  184. new configsDir[64]
  185. get_configsdir(configsDir, 63)
  186. server_cmd("exec %s/ptb.cfg", configsDir) // Execute main configuration file
  187.  
  188. //New auto-channeling system in amxmodx 1.70
  189. g_MyMsgSync = CreateHudSyncObj()
  190.  
  191.  
  192. // Init clients VGUI-menu setting
  193. // Set terminating 0 to allow use of char processing instead of string
  194. // to improve performance.
  195. for (new i=0;i<33;i++){
  196. clientVGUIMenu[i][0] = '0'
  197. clientVGUIMenu[i][1] = 0
  198. }
  199.  
  200. return PLUGIN_CONTINUE
  201. }
  202.  
  203. public get_immunity_level_flag()
  204. {
  205. new flags[24]
  206. get_pcvar_string(immunity_level, flags, 23)
  207.  
  208. return(read_flags(flags))
  209. }
  210.  
  211. public get_access_level_flag()
  212. {
  213. new flags[24]
  214. get_pcvar_string(access_level, flags, 23)
  215.  
  216. return(read_flags(flags))
  217. }
  218.  
  219.  
  220. Float:fdivWorkaround(Float:nom, Float:denom){
  221. if ( denom == 0.0) return nom
  222. return floatabs(nom / denom)
  223. }
  224.  
  225. doTypesay(string[], duration, r, g, b) {
  226. if (!PTB_TYPESAY) return
  227. //last parameter is not needed
  228. set_hudmessage(r, g, b, 0.05, 0.25, 0, 6.0, float(duration) , 0.5, 0.15, -1)
  229. //use this instead of show_hudmessage
  230. ShowSyncHudMsg(0, g_MyMsgSync, "%s", string)
  231. }
  232.  
  233. say(string[]){
  234. if(get_pcvar_num(saychat) == 1 || get_pcvar_num(saychat) == 3){
  235. client_print(0,print_chat,string)
  236. server_print(string)
  237. }
  238. }
  239.  
  240. bool:check_param_bool(param[])
  241. return (equali(param, "on") || equal(param, "1")) ? true : false
  242.  
  243. Float:check_param_float(param[],Float:n){
  244. new Float:a = floatstr(param)
  245. if (a < n) a = n
  246. return a
  247. }
  248.  
  249. check_param_num(param[],n){
  250. new a = str_to_num(param)
  251. if (a < n) a = n
  252. return a
  253. }
  254.  
  255. transferPlayer(id){
  256.  
  257. if (!is_user_connected(id)) return
  258. if (isBeingTransfered[id]) return
  259. isBeingTransfered[id] = false
  260.  
  261. new name[32], player_steamid[50], team_pre_transfer[12]
  262. get_user_name(id,name,31)
  263. get_user_authid(id, player_steamid, 49)
  264. get_user_team(id, team_pre_transfer, 11)
  265.  
  266. if(cs_get_user_defuse(id))
  267. cs_set_user_defuse(id, 0);
  268.  
  269. cs_set_user_team(id, (playerTeam[id]==TS) ? 2 : 1)
  270. cs_reset_user_model(id)
  271.  
  272. // This must be done here or lastroundswithed will not be registered
  273. lastRoundSwitched[id] = roundCounter
  274.  
  275. // This logs to hlds logs so Psychostats knows that the player has changed team (PS 3.X)
  276. //"LAntz69<9><STEAM_0:1:1895474><TERRORIST>" joined team "CT" //This is how it will be outputted in hlds logs
  277. log_message("^"%s<%d><%s><%s>^" joined team ^"%s^"",
  278. name, get_user_userid(id), player_steamid, team_pre_transfer, (playerTeam[id]==TS) ? "CT" : "TERRORIST" )
  279.  
  280. if(get_pcvar_num(show_in_hlsw) == 1)
  281. {
  282. // This makes you able to see transfers with HLSW in the chat
  283. log_message("^"<><><>^" triggered ^"amx_chat^" (text ^"[PTB] Transfered %s to %s^")",
  284. name, (playerTeam[id]==TS) ? "CT" : "TERRORIST" )
  285. }
  286.  
  287. #if defined PTB_DEBUG
  288. log_amx("Transfer player: %s lastRoundSwitched[id]: %i roundCounter:%i", name, lastRoundSwitched[id], roundCounter)
  289. client_print(0,print_chat,"Transfer player: %s lastRoundSwitched[id]: %i roundCounter:%i", name, lastRoundSwitched[id], roundCounter)
  290. #endif
  291. }
  292.  
  293. #if defined PTB_DEBUG
  294. public check_lasttransfer(id) {
  295. new lasttransfer, text[255]
  296. lasttransfer = lastRoundSwitched[id]
  297.  
  298. format(text,255,"LastRound transfered: %i", lasttransfer)
  299. say(text)
  300. }
  301. #endif
  302.  
  303. actAtEndOfRound(){
  304. if (!PTB_SWITCH) return
  305. // skip switching for the first few rounds
  306. if (roundCounter <= PTB_SWITCHAFTER) return
  307. // honor switch frequency setting
  308. if (roundCounter - lastSwitchRound < PTB_SWITCHFREQ) return
  309. // skip switching for a small number of players
  310. if (get_playersnum() < PTB_SWITCHMIN) return
  311.  
  312. say("PTB: Round ended, checking teams.")
  313. checkTeamBalance()
  314. if (winnerTeam) {
  315. sortTeam(CTS)
  316. sortTeam(TS)
  317.  
  318. // If they set the cvar(ptb_transfer_type) 1 or less than 2 or bigger than 3
  319. // then standard transfers will be selected
  320. if(get_pcvar_num(transfer_type) < 2 || get_pcvar_num(transfer_type) > 3){
  321.  
  322. // This is the standard if it should be a swith of to players or just one transfer
  323. if (teamCounts[winnerTeam] <= teamCounts[loserTeam]) // Original formula
  324. doSwitch()
  325. else if (teamCounts[loserTeam] < teamCounts[winnerTeam]) // Original formula
  326. doTransfer()
  327.  
  328. }
  329.  
  330. if(get_pcvar_num(transfer_type) == 2){
  331.  
  332. // This is more agressive but not so much as the one below
  333. if (teamCounts[winnerTeam] < teamCounts[loserTeam])
  334. doSwitch()
  335.  
  336. else if (teamCounts[loserTeam] <= teamCounts[winnerTeam])
  337. doTransfer()
  338. }
  339.  
  340. if(get_pcvar_num(transfer_type) == 3){
  341.  
  342. // This is the most agressive transfertype
  343. if ((teamCounts[winnerTeam]+(PTB_MAXDIFF/2)) < teamCounts[loserTeam])
  344. doSwitch()
  345.  
  346. else if (teamCounts[loserTeam] <= (teamCounts[winnerTeam]+(PTB_MAXDIFF/2)))
  347. doTransfer()
  348. }
  349.  
  350. }
  351. }
  352.  
  353. createValidTargets(theTeam, bool:deadonly) {
  354. new n = 0
  355. for (new i = 0; i < teamCounts[theTeam]; ++i) {
  356.  
  357.  
  358. #if defined PTB_VIP_IMMUNITY
  359. // If player is in the VIP team dont touch
  360. if (cs_get_user_vip(sortedTeams[theTeam][i])) continue
  361. #endif
  362.  
  363. // Protection for admins if ptb_switch_immunity 1
  364. if (get_user_flags(sortedTeams[theTeam][i])&get_immunity_level_flag() && (get_pcvar_num(switch_immunity) == 1)) continue
  365. // Dead only condition
  366. if ( deadonly && is_user_alive(sortedTeams[theTeam][i]) ) continue
  367. // Already switched or in PTB_PLAYERFREQ time condition
  368. if ((lastRoundSwitched[sortedTeams[theTeam][i]] == roundCounter) ||
  369. (roundCounter - lastRoundSwitched[sortedTeams[theTeam][i]] < PTB_PLAYERFREQ)) continue
  370. sortedValidTargets[theTeam][n++] = sortedTeams[theTeam][i]
  371. }
  372. validTargetCounts[theTeam] = n
  373. }
  374.  
  375. sortTeam(theTeam) {
  376. // create list of players
  377. new n = 0, a = get_maxplayers()
  378. for (new i = 1; i <= a; ++i) {
  379. // Get only members of specified team
  380. if (playerTeam[i] != theTeam) continue
  381. sortedTeams[theTeam][n++] = i
  382. }
  383. // do a selection sort
  384. new swap, count = n
  385. for (new i = count-1; i > 0; --i){
  386. for (new k = i-1; k >= 0; --k){
  387. // compare players (kills better then other or if equal then with less deaths)
  388. if ( (kills[sortedTeams[theTeam][k]]<kills[sortedTeams[theTeam][i]])
  389. || ( (kills[sortedTeams[theTeam][k]]==kills[sortedTeams[theTeam][i]]) &&
  390. (deaths[sortedTeams[theTeam][k]]>deaths[sortedTeams[theTeam][i]]))) {
  391. // swap
  392. swap = sortedTeams[theTeam][k]
  393. sortedTeams[theTeam][k] = sortedTeams[theTeam][i]
  394. sortedTeams[theTeam][i] = swap
  395. }
  396. }
  397. }
  398. }
  399.  
  400. Float:score(team, toBeAdded=0, toBeRemoved=0){
  401. new Float:sumKD = 0.0
  402. new a = get_maxplayers()
  403. for (new i = 1; i <= a; ++i) {
  404. if ( (playerTeam[i]!=team&&i!=toBeAdded) || (i==toBeRemoved) )
  405. continue
  406. sumKD += fdivWorkaround(float(kills[i]), float(deaths[i]))
  407. }
  408. new Float:strength = float(teamCounts[team])
  409. if (sumKD) strength *= sumKD
  410. return strength
  411. }
  412.  
  413. doSwitch() {
  414. new text[256]
  415. //displayStatistics(0,true)
  416. // don't switch, if at least one team is empty
  417. if ( teamCounts[winnerTeam] == 0 || teamCounts[loserTeam] == 0 ) {
  418. copy(text,255, "PTB: Can't switch players, need players in each team.")
  419. doTypesay(text, 5, 0, 255, 0)
  420. say(text)
  421. return
  422. }
  423. // don't switch, if winner is alone (RULER!!!)
  424. if (teamCounts[winnerTeam] == 1) {
  425. copy(text,255, "PTB: Won't switch players, best player makes the winning team.")
  426. doTypesay(text, 5, 0, 255, 0)
  427. say(text)
  428. return
  429. }
  430. // don't switch, if both teams are full
  431. if (teamCounts[winnerTeam] >= PTB_MAXSIZE && teamCounts[loserTeam] >= PTB_MAXSIZE) {
  432. copy(text,255, "PTB: Can't switch players, both teams are full.")
  433. doTypesay(text, 5, 0, 255, 0)
  434. say(text)
  435. return
  436. }
  437. if (!PTB_DEADONLY || couldNotSwitchCounter > PTB_FORCESWITCH) {
  438. // choose from random top or bottom x
  439. createValidTargets(winnerTeam, false)
  440. createValidTargets(loserTeam, false)
  441.  
  442. if (validTargetCounts[winnerTeam] == 0 || validTargetCounts[loserTeam] == 0) {
  443. ++couldNotSwitchCounter
  444. copy(text,255, "PTB: Can't switch players, need valid target in each team.")
  445. doTypesay(text, 5, 0, 255, 0)
  446. say(text)
  447. return
  448. }
  449. }
  450. else {
  451. //say("switch dead")
  452. createValidTargets(winnerTeam, true)
  453. createValidTargets(loserTeam, true)
  454.  
  455. if (validTargetCounts[winnerTeam] == 0 || validTargetCounts[loserTeam] == 0) {
  456. if (++couldNotSwitchCounter > PTB_FORCESWITCH) {
  457. say("PTB: Couldn't switch dead, switching alive.")
  458. doSwitch()
  459. return
  460. }
  461. copy(text, 255,"PTB: Can't switch players, need valid target in each team.")
  462. doTypesay(text, 5, 0, 255, 0)
  463. say(text)
  464. return
  465. }
  466. }
  467. // Now search through the possible 1 to 1 swaps to equalize the strength as much as possible
  468. new Float:closestScore = floatabs(score(winnerTeam) - score(loserTeam))
  469. new Float:myScore, toLoser, toWinner
  470. new winner = 0
  471. new loser = 0
  472. for (new w = 0; w < validTargetCounts[winnerTeam]; ++w) {
  473. toLoser = sortedValidTargets[winnerTeam][w]
  474. for (new l = 0; l < validTargetCounts[loserTeam]; ++l) {
  475. toWinner = sortedValidTargets[loserTeam][l]
  476. myScore = floatabs(score(winnerTeam, toWinner, toLoser) - score(loserTeam, toLoser, toWinner))
  477. if (myScore < closestScore) {
  478. closestScore = myScore
  479. winner = toLoser
  480. loser = toWinner
  481. }
  482. }
  483. }
  484. if (winner == 0 && loser == 0) {
  485. copy(text, 255,"PTB: No switch would improve team balancing.")
  486. doTypesay(text, 5, 0, 255, 0)
  487. say(text)
  488. return
  489. }
  490. couldNotSwitchCounter = 0
  491. lastSwitchRound = roundCounter
  492. new winnerName[32], loserName[32]
  493. get_user_name(winner,winnerName,31)
  494. get_user_name(loser,loserName,31)
  495. // if one team is full, first move the the player from the full team ...
  496. if (teamCounts[winnerTeam] >= PTB_MAXSIZE){
  497. transferPlayer(winner)
  498. transferPlayer(loser)
  499. }
  500. else {
  501. transferPlayer(loser)
  502. transferPlayer(winner)
  503. }
  504. format(text,255,"PTB: Switching %s with %s.",winnerName,loserName)
  505.  
  506. if(get_pcvar_num(saychat) == 2 || get_pcvar_num(saychat) == 3){
  507. //say(text)
  508. //set_hudmessage(0, 255, 0, 0.05, 0.25, 0, 6.0, 5.0 , 0.5, 0.15, 1)
  509. //show_hudmessage(0, text )
  510. set_hudmessage(0, 255, 0, 0.05, 0.25, 0, 6.0, 5.0 , 0.5, 0.15, -1)
  511. ShowSyncHudMsg(0, g_MyMsgSync, "%s", text)
  512. client_print(0,print_chat,"PTB: Switching %s with %s.",winnerName,loserName)
  513. }else{
  514. doTypesay(text, 5, 0, 255, 0)
  515. client_print(0,print_chat,"PTB: Switching %s with %s.",winnerName,loserName)
  516. //say(text)
  517. }
  518. }
  519.  
  520. doTransfer() {
  521. //displayStatistics(0,true)
  522. new text[256]
  523. if (teamCounts[winnerTeam] == 0) {
  524. copy(text,255, "PTB: Can't switch players, need players in each team.")
  525. doTypesay(text, 5, 0, 255, 0)
  526. say(text)
  527. return
  528. }
  529. if (teamCounts[loserTeam] >= PTB_MAXSIZE) {
  530. copy(text,255, "PTB: Can't transfer player, losing team is full.")
  531. doTypesay(text, 5, 0, 255, 0)
  532. say(text)
  533. return
  534. }
  535. if (!PTB_DEADONLY || couldNotSwitchCounter > PTB_FORCESWITCH) {
  536. createValidTargets(winnerTeam, false)
  537. if (validTargetCounts[winnerTeam] == 0) {
  538. copy(text,255, "PTB: Can't transfer player, no valid target in winning team.")
  539. doTypesay(text, 5, 0, 255, 0)
  540. say(text)
  541. ++couldNotSwitchCounter
  542. return
  543. }
  544. }
  545. else {
  546. //say("switch dead")
  547. createValidTargets(winnerTeam, true)
  548. if (validTargetCounts[winnerTeam] == 0) {
  549. if (++couldNotSwitchCounter > PTB_FORCESWITCH) {
  550. say("PTB: Couldn't transfer dead, transferring alive.")
  551. doTransfer()
  552. return
  553. }
  554. copy(text,255, "PTB: Can't transfer player, no valid target in winning team.")
  555. doTypesay(text, 5, 0, 255, 0)
  556. say(text)
  557. return
  558. }
  559. }
  560. new Float:closestScore = floatabs(score(winnerTeam) - score(loserTeam))
  561. new Float:myScore, toLoser
  562. new winner = 0
  563. for (new w = 0; w < validTargetCounts[winnerTeam]; ++w) {
  564. toLoser = sortedValidTargets[winnerTeam][w]
  565. myScore = floatabs(score(winnerTeam, 0, toLoser) - score(loserTeam, toLoser, 0))
  566. if (myScore < closestScore) {
  567. closestScore = myScore
  568. winner = toLoser
  569. }
  570. }
  571. if (winner == 0) {
  572. copy(text, 255,"PTB: No transfer would improve team balancing.")
  573. doTypesay(text, 5, 0, 255, 0)
  574. say(text)
  575. return
  576. }
  577. couldNotSwitchCounter = 0
  578. new winnerName[32]
  579. get_user_name(winner,winnerName,31)
  580. transferPlayer(winner)
  581. format(text,255,"PTB: Transfering %s to the %s",winnerName, (winnerTeam == CTS) ? "Ts" : "CTs")
  582.  
  583. if(get_pcvar_num(saychat) == 2 || get_pcvar_num(saychat) == 3){
  584. //say(text)
  585. //set_hudmessage(0, 255, 0, 0.05, 0.25, 0, 6.0, 5.0 , 0.5, 0.15, 1)
  586. //show_hudmessage(0, text )
  587. set_hudmessage(0, 255, 0, 0.05, 0.25, 0, 6.0, 5.0 , 0.5, 0.15, -1)
  588. ShowSyncHudMsg(0, g_MyMsgSync, "%s", text)
  589. client_print(0,print_chat,"PTB: Transfering %s to the %s",winnerName, (winnerTeam == CTS) ? "Ts" : "CTs")
  590. }else{
  591. doTypesay(text, 5, 0, 255, 0)
  592. client_print(0,print_chat,"PTB: Transfering %s to the %s",winnerName, (winnerTeam == CTS) ? "Ts" : "CTs")
  593. //say(text)
  594. }
  595. }
  596.  
  597. checkTeamBalance() {
  598.  
  599. get_time("%m/%d/%Y - %H:%M:%S",lastTeamBalanceCheck,31 )
  600. calcTeamScores()
  601. ctStrength = score(CTS)
  602. tStrength = score(TS)
  603. ctRating = fdivWorkaround(ctStrength, tStrength)
  604. tRating = fdivWorkaround(tStrength, ctStrength)
  605. wtConditions[TS] = 0
  606. wtConditions[CTS] = 0
  607.  
  608. // compare scores for unequal rating scores
  609. if (teamScores[TS] - teamScores[CTS] > PTB_MAXSCORE && tRating >= PTB_MINRATING)
  610. wtConditions[TS]++
  611.  
  612. if (teamScores[CTS] - teamScores[TS] > PTB_MAXSCORE && ctRating >= PTB_MINRATING)
  613. wtConditions[CTS]++
  614.  
  615. // check streaks for unequal rating scores
  616. if (winStreaks[TS] > PTB_MAXSTREAK && tRating >= PTB_MINRATING)
  617. wtConditions[TS]++
  618.  
  619. if (winStreaks[CTS] > PTB_MAXSTREAK && ctRating >= PTB_MINRATING)
  620. wtConditions[CTS]++
  621.  
  622. // check ratings
  623. if (tRating >= PTB_MAXRATING)
  624. wtConditions[TS]++
  625.  
  626. if (ctRating >= PTB_MAXRATING)
  627. wtConditions[CTS]++
  628.  
  629.  
  630. // check ratings
  631. if (tRating >= PTB_SUPERRATING)
  632. wtConditions[TS]++
  633.  
  634. if (ctRating >= PTB_SUPERRATING)
  635. wtConditions[CTS]++
  636.  
  637.  
  638. // check team sizes for unequal ratings
  639. if (teamCounts[TS] > teamCounts[CTS] && tRating >= PTB_MINRATING)
  640. wtConditions[TS]++
  641.  
  642. if (teamCounts[CTS] > teamCounts[TS] && ctRating >= PTB_MINRATING)
  643. wtConditions[CTS]++
  644.  
  645. // check conditions
  646. if (wtConditions[TS] >= 2) {
  647. winnerTeam = TS
  648. loserTeam = CTS
  649. }
  650. else if (wtConditions[CTS] >= 2) {
  651. winnerTeam = CTS
  652. loserTeam = TS
  653. }
  654. else {
  655. winnerTeam = 0
  656. loserTeam = 0
  657. }
  658. }
  659.  
  660. manageWtjFile(id) {
  661. if (!PTB_SAVEWTJ) return
  662. //say("Trying to write wtj.log ....")
  663. //if (wtjCount[id] < 4) return
  664. //say("wtj.log should be written to now ....")
  665. new text[256], mapname[32], name[32], authid[32]
  666. get_mapname(mapname,31)
  667. get_user_name(id,name,31)
  668. get_user_authid(id,authid,31)
  669. format(text, 255, "%s <%s> %s", name, authid, mapname)
  670. log_to_file("wtj.log", text)
  671. }
  672.  
  673.  
  674. public menuclass(id) {
  675. if (!isBeingTransfered[id]) return PLUGIN_CONTINUE
  676. client_cmd(id,"slot1")
  677. isBeingTransfered[id] = false
  678. return PLUGIN_CONTINUE
  679. }
  680.  
  681. public jointeam(id) {
  682. new arg[2]
  683. read_argv(1,arg,1)
  684. if (isBeingTransfered[id]) return PLUGIN_HANDLED
  685. return checkTeamSwitch(id,str_to_num(arg)) // team is key pressed + 1
  686. }
  687.  
  688. public teamselect(id,key) {
  689.  
  690. return checkTeamSwitch(id,key+1) // team is key pressed + 1
  691. }
  692.  
  693. checkTeamSwitch(id,iNewTeam) {
  694.  
  695. // don't care where player joins
  696. if (!PTB_LIMITJOIN) return PLUGIN_CONTINUE
  697. // Protection for admins if ptb_limitjoin_immunity 1
  698. if (get_user_flags(id)&get_immunity_level_flag() && (get_pcvar_num(limitjoin_immunity) == 1)) return PLUGIN_CONTINUE
  699. // players is transfered so don't care with rest
  700. if (isBeingTransfered[id]) {
  701. //say("TRANSFER")
  702. isBeingTransfered[id] = false
  703. return PLUGIN_CONTINUE
  704. }
  705. //say("NO TRANSFER")
  706. // skip limiting for a few rounds into the map
  707. if (PTB_LIMITAFTER && roundCounter <= PTB_LIMITAFTER) return PLUGIN_CONTINUE
  708. // skip limiting for a small number of players
  709. if (get_playersnum() < PTB_LIMITMIN) return PLUGIN_CONTINUE
  710.  
  711. new iOldTeam = playerTeam[id]
  712.  
  713. // disallow free team choices in the first rounds of a map
  714. if (PTB_AUTOROUNDS && (iOldTeam==UNASSIGNED) && roundCounter<=PTB_AUTOROUNDS && !(get_user_flags(id) & ADMIN_KICK))
  715. iNewTeam = AUTO_TEAM
  716.  
  717. // prevent unwanted rejoining of the same team ...
  718. if (iNewTeam == iOldTeam) {
  719. //say("Preventing rejoining of the same team.")
  720. client_print(id,print_chat,"PTB: Joining to the same team is not allowed...")
  721. #if !defined MANUAL_SWITCH
  722. engclient_cmd(id,"chooseteam") // display menu again
  723. #endif
  724. return PLUGIN_HANDLED
  725. }
  726.  
  727. checkTeamBalance()
  728. //displayStatistics(0,true)
  729.  
  730. // Player for sure was in CT or T team and now is joining to the opposite team
  731. if ((iNewTeam==CTS&&iOldTeam==TS)||(iNewTeam==TS&&iOldTeam==CTS)){
  732. // If someone is in new team and old team weren't full
  733. // and the winning team is a destination team or in
  734. // new team is more players than in old then treat it as wtj
  735. if ( teamCounts[iNewTeam]&&(teamCounts[iOldTeam]<PTB_MAXSIZE)&&
  736. ((iNewTeam==winnerTeam)||(teamCounts[iNewTeam]>=teamCounts[iOldTeam])) ) {
  737. // player is wtjing
  738. new text[256],name[32]
  739. get_user_name(id,name,31)
  740. // Kick wtj player if reached set limit
  741. if (++wtjCount[id] >= PTB_WTJKICK && PTB_KICK) {
  742. format(text, 255, "PTB: Kicking %s for a WTJ count %d of %d.", name, wtjCount[id],PTB_WTJKICK )
  743. doTypesay(text, 5, 0, 255, 0)
  744. say(text)
  745. server_cmd("kick #%d",get_user_userid(id))
  746. return PLUGIN_HANDLED
  747. }
  748. // Announce about WTJ
  749. if (PTB_TELLWTJ) {
  750. if (iNewTeam == CTS) {
  751. format(text, 255, "PTB: The CTs are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  752. doTypesay(text, 5, 0, 50, 255)
  753. }
  754. else {
  755. format(text, 255, "PTB: The Ts are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  756. doTypesay(text, 5, 255, 50, 0)
  757. }
  758. say(text)
  759. }
  760. #if !defined MANUAL_SWITCH
  761. engclient_cmd(id,"chooseteam") // display menu again
  762. #endif
  763. return PLUGIN_HANDLED
  764. }
  765. // check for maximum team size
  766. if (teamCounts[iNewTeam] >= PTB_MAXSIZE) {
  767. client_print(id,print_chat,"PTB: Maximum team size prohibits team change.")
  768. #if !defined MANUAL_SWITCH
  769. engclient_cmd(id,"chooseteam") // display menu again
  770. #endif
  771. return PLUGIN_HANDLED
  772. }
  773. // check team size difference limits
  774. if ( teamCounts[iNewTeam]+1-teamCounts[iOldTeam] >= PTB_MAXDIFF ) {
  775. client_print(id,print_chat,"PTB: Maximum team size difference prohibits team change.")
  776. #if !defined MANUAL_SWITCH
  777. engclient_cmd(id,"chooseteam") // display menu again
  778. #endif
  779. return PLUGIN_HANDLED
  780. }
  781. return PLUGIN_CONTINUE // OK! He can join to the oppsoite team!!!
  782. }
  783.  
  784. // Player is choosing his team for the first time!
  785. if (iNewTeam==CTS||iNewTeam==TS){
  786. // Get opposite team
  787. new opposingTeam = (iNewTeam==CTS)? TS : CTS
  788. // Players is joining to one team but the opposite is not full
  789. // and his team is bettter then opposite or has more players
  790. if (teamCounts[iNewTeam] && teamCounts[opposingTeam]<PTB_MAXSIZE &&
  791. (iNewTeam==winnerTeam||(!winnerTeam&&teamCounts[iNewTeam]>teamCounts[opposingTeam]))) {
  792. new text[256],name[32]
  793. get_user_name(id,name,31)
  794. if (++wtjCount[id] >= PTB_WTJKICK && PTB_KICK) {
  795. format(text, 255, "PTB: Kicking %s for a WTJ count %d of %d.", name, wtjCount[id],PTB_WTJKICK)
  796. doTypesay(text, 5, 0, 255, 0)
  797. say(text)
  798. server_cmd("kick #%d", get_user_userid(id))
  799. return PLUGIN_HANDLED
  800. }
  801. if (iNewTeam==CTS) {
  802. if (wtjCount[id]>=PTB_WTJAUTO && is_user_connected(id)) {
  803. manageWtjFile(id)
  804. format(text, 255, "PTB: Forcing %s to the Ts (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  805.  
  806. engclient_cmd(id,"jointeam","1")
  807.  
  808. doTypesay(text, 5, 255, 50, 0)
  809. say(text)
  810. }
  811. else if (PTB_TELLWTJ) {
  812. format(text, 255, "PTB: The CTs are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  813. doTypesay(text, 5, 0, 50, 255)
  814. say(text)
  815. #if !defined MANUAL_SWITCH
  816. engclient_cmd(id,"chooseteam") // display menu again
  817. #endif
  818. }
  819. }
  820. else {
  821. if (wtjCount[id]>=PTB_WTJAUTO) {
  822. manageWtjFile(id)
  823. format(text, 255, "PTB: Forcing %s to the CTs (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  824.  
  825. engclient_cmd(id,"jointeam","2")
  826.  
  827. doTypesay(text, 5, 0, 50, 255)
  828. say(text)
  829. }
  830. else if (PTB_TELLWTJ) {
  831. format(text, 255, "PTB: The Ts are strong enough, %s (WTJ: %d/%d).", name, wtjCount[id],PTB_WTJKICK)
  832. doTypesay(text, 5, 255, 50, 0)
  833. say(text)
  834. #if !defined MANUAL_SWITCH
  835. engclient_cmd(id,"chooseteam") // display menu again
  836. #endif
  837. }
  838. }
  839. return PLUGIN_HANDLED
  840. }
  841. // check for maximum team size
  842. if (teamCounts[iNewTeam] >= PTB_MAXSIZE) {
  843. client_print(id,print_chat,"PTB: Maximum team size prohibits team join.")
  844. #if !defined MANUAL_SWITCH
  845. engclient_cmd(id,"chooseteam") // display menu again
  846. #endif
  847. return PLUGIN_HANDLED
  848. }
  849. // check team size difference limits
  850. if ( teamCounts[iNewTeam]-teamCounts[opposingTeam] >= PTB_MAXDIFF) {
  851. client_print(id,print_chat,"PTB: Maximum team size difference prohibits team join.")
  852. #if !defined MANUAL_SWITCH
  853. engclient_cmd(id,"chooseteam") // display menu again
  854. #endif
  855. return PLUGIN_HANDLED
  856. }
  857. return PLUGIN_CONTINUE // OK! He can join to the oppsoite team!!!
  858. }
  859.  
  860. // He is choosing the AUTO-SELECT but he was already in game (He wants to play fair!)
  861. if (iNewTeam==AUTO_TEAM&&(iOldTeam==CTS||iOldTeam==TS)) {
  862. //say("Changing team automatically.")
  863. new opposingTeam = (iOldTeam==CTS) ? TS : CTS
  864. if (teamCounts[opposingTeam] && ( (teamCounts[opposingTeam]>=PTB_MAXSIZE)
  865. || (iOldTeam==loserTeam) || (!loserTeam&&teamCounts[iOldTeam]<=teamCounts[opposingTeam])
  866. || (teamCounts[opposingTeam]+1-teamCounts[iOldTeam]>=PTB_MAXDIFF)) ) {
  867. client_print(id,print_chat,"PTB: You have better stay in your current team...")
  868. return PLUGIN_HANDLED
  869. }
  870. client_print(id,print_chat,"PTB: You have been auto-assigned...")
  871.  
  872. engclient_cmd(id,"jointeam",(opposingTeam==CTS)?"2":"1")
  873.  
  874. return PLUGIN_HANDLED
  875. }
  876. // He is choosing the team for the first time with AUTO-SELECT (What a nice kid!)
  877. if (iNewTeam==AUTO_TEAM) {
  878. /* this is the "always smaller team" version
  879. if (teamCounts[CTS] < teamCounts[TS] || teamCounts[TS] >= PTB_MAXSIZE) iNewTeam = CTS
  880. else if (teamCounts[TS] < teamCounts[CTS] || teamCounts[CTS] >= PTB_MAXSIZE) iNewTeam = TS
  881. // both teams have same size ...
  882. else if (winnerTeam && teamCounts[loserTeam]<PTB_MAXSIZE) iNewTeam = loserTeam
  883. else if (teamCounts[TS] >= PTB_MAXSIZE) iNewTeam = CTS
  884. else if (teamCounts[CTS] >= PTB_MAXSIZE) iNewTeam = TS
  885. else iNewTeam = (random_num(0,100) < 50) ? CTS : TS
  886. */
  887. // this version prefers the losing team (but still honors PTB_MAXDIFF)
  888. if (teamCounts[CTS] >= PTB_MAXSIZE) iNewTeam = TS
  889. else if (teamCounts[TS] >= PTB_MAXSIZE) iNewTeam = CTS
  890. else if (teamCounts[CTS]-teamCounts[TS] >= PTB_MAXDIFF) iNewTeam = TS
  891. else if (teamCounts[TS]-teamCounts[CTS] >= PTB_MAXDIFF) iNewTeam = CTS
  892. else if (winnerTeam) iNewTeam = loserTeam
  893. else if (teamCounts[CTS]<teamCounts[TS]) iNewTeam = CTS
  894. else if (teamCounts[TS]<teamCounts[CTS]) iNewTeam = TS
  895. // both teams have same size ...
  896. else iNewTeam = (random_num(0,100) < 50) ? CTS : TS
  897. // check for maximum team size
  898. if (teamCounts[iNewTeam]>=PTB_MAXSIZE) {
  899. client_print(id,print_chat,"PTB: Maximum team size prohibits team join.") // ??? - only a spectator???
  900. #if !defined MANUAL_SWITCH
  901. engclient_cmd(id,"chooseteam") // display menu again
  902. #endif
  903. return PLUGIN_HANDLED
  904. }
  905. client_print(id,print_chat,"PTB: You have been auto-assigned...")
  906.  
  907. engclient_cmd(id,"jointeam",(iNewTeam==CTS)?"2":"1")
  908.  
  909. return PLUGIN_HANDLED
  910. }
  911. return PLUGIN_CONTINUE
  912. }
  913.  
  914. public team_score(){
  915. new arg[2]
  916. read_data(1,arg,1)
  917. teamScores[ ( arg[0] == 'T' ) ? TS : CTS ] = read_data(2)
  918. }
  919.  
  920. public win_streaks(param[]){
  921. new winner = param[0]
  922. new looser = param[1]
  923. if (winStreaks[winner] < 0) {
  924. winStreaks[winner] = 1
  925. winStreaks[looser] = -1
  926. }
  927. else {
  928. winStreaks[winner]++
  929. winStreaks[looser]--
  930. }
  931. actAtEndOfRound()
  932. }
  933.  
  934. public round_end(){
  935. new param[12]
  936. read_data(2,param,8)
  937. if (param[7]=='c') {//%!MRAD_ctwin
  938. param[0] = CTS
  939. param[1] = TS
  940. }
  941. else if (param[7]=='t') {//%!MRAD_terwin
  942. param[0] = TS
  943. param[1] = CTS
  944. }
  945. else
  946. return // %!MRAD_rounddraw (both teams have left the game)
  947. set_task(4.5,"win_streaks",0,param,2)
  948. }
  949.  
  950. public new_round() {
  951. //if ( floatround(get_cvar_float("mp_roundtime") * 60.0) != read_data(1) ) return
  952. if ( floatround(get_cvar_float("mp_roundtime") * 60.0,floatround_floor) != read_data(1) ) return
  953. ++roundCounter
  954. announceStatus()
  955. }
  956.  
  957. // Happen only at team select (also auto-join)
  958. public team_join() {
  959. new arg[32]
  960. read_data(3,arg,31)
  961. lastRoundSwitched[ get_user_index(arg) ] = roundCounter
  962. }
  963.  
  964. // Can happen at begin of round or team select
  965. public team_assign() {
  966. new arg[2], team
  967. new i = read_data(1)
  968. read_data(2,arg,1)
  969. if ( arg[0] == 'C' )
  970. team = CTS
  971. else if ( arg[0] == 'T' )
  972. team = TS
  973. else
  974. team = UNASSIGNED
  975. teamCounts[playerTeam[i]]-- // Unregister from old team
  976. teamCounts[team]++ // Increase ammount in new team
  977. playerTeam[i] = team // Assign to new
  978. }
  979.  
  980. public game_restart(){
  981. roundCounter = 0
  982. lastSwitchRound = 0
  983. couldNotSwitchCounter = 0
  984. teamKills[0] = teamKills[1] = teamKills[2] = 0
  985. teamDeaths[0] = teamDeaths[1] = teamDeaths[2] = 0
  986. teamScores[0] = teamScores[1] = teamScores[2] = 0
  987. winStreaks[0] = winStreaks[1] = winStreaks[2] = 0
  988. wtConditions[0] = wtConditions[1] = wtConditions[2] = 0
  989. validTargetCounts[0] = validTargetCounts[1] = validTargetCounts[2] = 0
  990. new a = get_maxplayers()
  991. for (new i = 1; i <= a; ++i){
  992. kills[i] = 0
  993. deaths[i] = 0
  994. wtjCount[i] = 0
  995. lastRoundSwitched[i] = -999
  996. }
  997. }
  998.  
  999. public death_msg(){
  1000. new iWinner = read_data(1)
  1001. new iLoser = read_data(2)
  1002. if ( iWinner < 1 || iWinner > 32 || iLoser < 1 || iLoser > 32 )
  1003. return
  1004. if ( playerTeam[iWinner] == playerTeam[iLoser] )
  1005. return // no TKS!!!
  1006. kills[iWinner]++
  1007. deaths[iLoser]++
  1008. if (PTB_SCALEDOWN <= 1) return
  1009. if (kills[iWinner] + deaths[iWinner] >= PTB_MAXINCIDENTS) {
  1010. kills[iWinner] /= PTB_SCALEDOWN
  1011. deaths[iWinner] /= PTB_SCALEDOWN
  1012. }
  1013. if (kills[iLoser] + deaths[iLoser] >= PTB_MAXINCIDENTS) {
  1014. kills[iLoser] /= PTB_SCALEDOWN
  1015. deaths[iLoser] /= PTB_SCALEDOWN
  1016. }
  1017. }
  1018.  
  1019. calcTeamScores() {
  1020. teamDeaths[UNASSIGNED] = 0
  1021. teamDeaths[CTS] = 0
  1022. teamDeaths[TS] = 0
  1023. teamKills[UNASSIGNED] = 0
  1024. teamKills[CTS] = 0
  1025. teamKills[TS] = 0
  1026.  
  1027. new team, a = get_maxplayers()
  1028. for (new i = 1; i <= a; ++i) {
  1029. team = playerTeam[i]
  1030. teamKills[team] += kills[i]
  1031. teamDeaths[team] += deaths[i]
  1032. }
  1033.  
  1034. ctKD = fdivWorkaround(float(teamKills[CTS]), float(teamDeaths[CTS]))
  1035. tKD = fdivWorkaround(float(teamKills[TS]), float(teamDeaths[TS]))
  1036. }
  1037.  
  1038. announceStatus() {
  1039. if (!PTB_ANNOUNCE) return
  1040. checkTeamBalance()
  1041. new text[256]
  1042. if (winnerTeam == TS) {
  1043. format(text, 255, "PTB: The COUNTER-TERRORIST team could use some support.")
  1044. doTypesay(text, 5, 0, 50, 255)
  1045. say("PTB: The COUNTER-TERRORIST team could use some support.")
  1046. }
  1047. else if (winnerTeam == CTS) {
  1048. format(text, 255, "PTB: The TERRORIST team could use some support.")
  1049. doTypesay(text, 5, 255, 50, 0)
  1050. say("PTB: The TERRORIST team could use some support.")
  1051. }
  1052. else if (wtConditions[TS] > wtConditions[CTS]) {
  1053. format(text, 255, "PTB: Observing TERRORIST team advantage.")
  1054. doTypesay(text, 5, 255, 50, 0)
  1055. say("PTB: Observing TERRORIST team advantage.")
  1056. }
  1057. else if (wtConditions[CTS] > wtConditions[TS]) {
  1058. format(text, 255, "PTB: Observing COUNTER-TERRORIST team advantage.")
  1059. doTypesay(text, 5, 0, 50, 255)
  1060. say("PTB: Observing COUNTER-TERRORIST team advantage.")
  1061. }
  1062. else if (PTB_SAYOK) {
  1063. format(text, 255, "PTB: Teams look fine, no action required.")
  1064. doTypesay(text, 5, 200, 100, 0)
  1065. say("PTB: Teams look fine, no action required.")
  1066. }
  1067. }
  1068.  
  1069. public admin_ptb(id,level,cid) {
  1070. if (!cmd_access(id,level,cid,1))
  1071. return PLUGIN_HANDLED
  1072. new cmd[32], arg[32], lastcmd
  1073.  
  1074. if ( read_argv(1,cmd,31) == 0 ) { // no command - plain amx_ptb
  1075. //console_print(id,"PTB: Ptahhotep's Team Balancer %s", PTB_VERSION)
  1076. //console_print(id,"PTB: (ptahhotep@planethalflife.com)")
  1077. checkTeamBalance()
  1078. displayStatistics(id)
  1079. return PLUGIN_HANDLED
  1080. }
  1081. if (equali(cmd, "on") || equal(cmd, "1")) {
  1082. PTB_LIMITJOIN = true
  1083. PTB_SWITCH = true
  1084. PTB_ANNOUNCE = true
  1085. console_print(id,"PTB: Enabled all PTB actions.")
  1086. return PLUGIN_HANDLED
  1087. }
  1088. if (equali(cmd, "off") || equal(cmd, "0")) {
  1089. PTB_SWITCH = false
  1090. PTB_ANNOUNCE = false
  1091. PTB_LIMITJOIN = false
  1092. console_print(id,"PTB: Disabled all PTB actions.")
  1093. return PLUGIN_HANDLED
  1094. }
  1095. if (equal(cmd, "list") || equal(cmd, "help")) {
  1096. console_print(id,"PTB: Available Commands:")
  1097. console_print(id,"PTB: Team Join Control: ^"limitjoin^", ^"limitafter^", ^"limitmin^", ^"maxsize^", ^"autorounds^",")
  1098. console_print(id,"PTB: ^"maxdiff^", ^"wtjauto^", ^"wtjkick^", ^"kick^", ^"savewtj^"")
  1099. console_print(id,"PTB: Team Balancing Actions: ^"switch^", ^"switchafter^", ^"switchmin^", ^"switchfreq^", ^"playerfreq^",")
  1100. console_print(id,"PTB: ^"forceswitch^", ^"deadonly^"")
  1101. console_print(id,"PTB: Team Strength Limits: ^"maxstreak^", ^"maxscore^", ^"minrating^", ^"maxrating^", ^"superrating^"")
  1102. console_print(id,"PTB: Messages: ^"tellwtj^", ^"announce^", ^"sayok^", ^"typesay^"")
  1103. console_print(id,"PTB: Misc: ^"^", ^"status^", ^"list^", ^"help^", ^"on^", ^"off^", ^"save^", ^"load^"")
  1104. console_print(id,"PTB: To view all PTB settings, type ^"amx_ptb status^".")
  1105. console_print(id,"PTB: To view or change a single PTB setting, type ^"amx_ptb <setting> <on|off|value>^".")
  1106. console_print(id,"PTB: For PTB statistics, simply type ^"amx_ptb^".")
  1107. return PLUGIN_HANDLED
  1108. }
  1109. new arglen = read_argv(2,arg,31)
  1110. new status = equal(cmd, "status")
  1111.  
  1112. // team selection control
  1113. if ( status ) console_print(id,"PTB: ---------- Team Selection Control ----------")
  1114.  
  1115. // PTB_LIMITJOIN
  1116. if ( (lastcmd = equal(cmd, "limitjoin")) && arglen ) PTB_LIMITJOIN = check_param_bool(arg)
  1117. if ( status || lastcmd ) console_print(id,"PTB: (limitjoin) WTJ prevention is %s.", PTB_LIMITJOIN ? "ON" : "OFF")
  1118.  
  1119. // PTB_LIMITAFTER
  1120. if ( (lastcmd = equal(cmd, "limitafter")) && arglen ) PTB_LIMITAFTER = check_param_num(arg,0)
  1121. if ( status || lastcmd ) console_print(id,"PTB: (limitafter) Team limiting starts after %d round(s).", PTB_LIMITAFTER)
  1122.  
  1123. // PTB_LIMITMIN
  1124. if ( (lastcmd = equal(cmd, "limitmin")) && arglen ) PTB_LIMITMIN = check_param_num(arg,0)
  1125. if ( status || lastcmd ) console_print(id,"PTB: (limitmin) Team limiting needs at least %d player(s).", PTB_LIMITMIN)
  1126.  
  1127. // PTB_MAXSIZE
  1128. if ( (lastcmd = equal(cmd, "maxsize")) && arglen ) PTB_MAXSIZE = check_param_num(arg,0)
  1129. if ( status || lastcmd ) console_print(id,"PTB: (maxsize) Maximum team size is %d player(s).", PTB_MAXSIZE)
  1130.  
  1131. // PTB_MAXDIFF
  1132. if ( (lastcmd = equal(cmd, "maxdiff")) && arglen ) PTB_MAXDIFF = check_param_num(arg,1)
  1133. if ( status || lastcmd ) console_print(id,"PTB: (maxdiff) Maximum team size difference is %d.", PTB_MAXDIFF)
  1134.  
  1135. // PTB_AUTOROUNDS
  1136. if ( (lastcmd = equal(cmd, "autorounds")) && arglen ) PTB_AUTOROUNDS = check_param_num(arg,0)
  1137. if ( status || lastcmd ) console_print(id, "PTB: (autorounds) First %d rounds no free team choice.", PTB_AUTOROUNDS)
  1138.  
  1139. // PTB_WTJAUTO
  1140. if ( (lastcmd = equal(cmd, "wtjauto")) && arglen ) PTB_WTJAUTO = check_param_num(arg,0)
  1141. if ( status || lastcmd ) console_print(id,"PTB: (wtjauto) Auto-joining WTJ after %d tr(y/ies).", PTB_WTJAUTO)
  1142.  
  1143. // PTB_WTJKICK
  1144. if ( (lastcmd = equal(cmd, "wtjkick")) && arglen ) PTB_WTJKICK = check_param_num(arg,1)
  1145. if ( status || lastcmd ) console_print(id,"PTB: (wtjauto) Auto-kicking WTJ after %d tr(y/ies).", PTB_WTJKICK)
  1146.  
  1147. // PTB_KICK
  1148. if ( (lastcmd = equal(cmd, "kick")) && arglen ) PTB_KICK = check_param_bool(arg)
  1149. if ( status || lastcmd ) console_print(id,"PTB: (kick) WTJ kicking is %s.", PTB_KICK ? "ON" : "OFF" )
  1150.  
  1151. // PTB_SAVEWTJ
  1152. if ( (lastcmd = equal(cmd, "savewtj")) && arglen ) PTB_SAVEWTJ = check_param_bool(arg)
  1153. if ( status || lastcmd ) console_print(id,"PTB: (savewtj) Saving to wtj.log is %s.", PTB_SAVEWTJ ? "ON" : "OFF");
  1154.  
  1155. // team balancing actions
  1156. if ( status ) console_print(id,"PTB: ---------- Team Balancing Actions ----------")
  1157.  
  1158. // PTB_SWITCH
  1159. if ( (lastcmd = equal(cmd, "switch")) && arglen ) PTB_SWITCH = check_param_bool(arg)
  1160. if ( status || lastcmd ) console_print(id,"PTB: (switch) Team switching is %s.", PTB_SWITCH ? "ON" : "OFF")
  1161.  
  1162. // PTB_SWITCHAFTER
  1163. if ( (lastcmd = equal(cmd, "switchafter")) && arglen ) PTB_SWITCHAFTER = check_param_num(arg,0)
  1164. if ( status || lastcmd ) console_print(id,"PTB: (switchafter) Switching starts after %d round(s).", PTB_SWITCHAFTER)
  1165.  
  1166. // PTB_SWITCHMIN
  1167. if ( (lastcmd = equal(cmd, "switchmin")) && arglen ) PTB_SWITCHMIN = check_param_num(arg,0)
  1168. if ( status || lastcmd ) console_print(id,"PTB: (switchmin) Switching needs at least %d player(s).", PTB_SWITCHMIN)
  1169.  
  1170. // PTB_PLAYERFREQ
  1171. if ( (lastcmd = equal(cmd, "playerfreq")) && arglen ) PTB_PLAYERFREQ = check_param_num(arg,0)
  1172. if ( status || lastcmd ) console_print(id,"PTB: (playerfreq) Individual players are switched every %d round(s) at maximum.", PTB_PLAYERFREQ)
  1173.  
  1174. // PTB_SWITCHFREQ
  1175. if ( (lastcmd = equal(cmd, "switchfreq")) && arglen ) PTB_SWITCHFREQ = check_param_num(arg,1)
  1176. if ( status || lastcmd ) console_print(id,"PTB: (switchfreq) Switch occurs every %d round(s) at maximum.", PTB_SWITCHFREQ)
  1177.  
  1178. // PTB_FORCESWITCH
  1179. if ( (lastcmd = equal(cmd, "forceswitch")) && arglen ) PTB_FORCESWITCH = check_param_num(arg,0)
  1180. if ( status || lastcmd ) console_print(id,"PTB: (forceswitch) Forcing switch after %d unsuccessful switch(es).", PTB_FORCESWITCH)
  1181.  
  1182. // PTB_DEADONLY
  1183. if ( (lastcmd = equal(cmd, "deadonly")) && arglen ) PTB_DEADONLY = check_param_bool(arg)
  1184. if ( status || lastcmd ) console_print(id,"PTB: (deadonly) Switching dead only is %s.",PTB_DEADONLY ? "ON" : "OFF" )
  1185.  
  1186. // messages
  1187. if ( status ) console_print(id,"PTB: ---------- Messages ----------")
  1188.  
  1189. // PTB_TELLWTJ
  1190. if ( (lastcmd = equal(cmd, "tellwtj")) && arglen ) PTB_TELLWTJ = check_param_bool(arg)
  1191. if ( status || lastcmd ) console_print(id,"PTB: (tellwtj) Telling about WTJ tries is %s.",PTB_TELLWTJ ? "ON" : "OFF")
  1192.  
  1193. // PTB_ANNOUNCE
  1194. if ( (lastcmd = equal(cmd, "announce")) && arglen ) PTB_ANNOUNCE = check_param_bool(arg)
  1195. if ( status || lastcmd ) console_print(id,"PTB: (announce) Announcements are %s.",PTB_ANNOUNCE ? "ON" : "OFF")
  1196.  
  1197. // PTB_SAYOK
  1198. if ( (lastcmd = equal(cmd, "sayok")) && arglen ) PTB_SAYOK = check_param_bool(arg)
  1199. if ( status || lastcmd ) console_print(id,"PTB: (sayok) ^"OK^" announcements are %s.",PTB_SAYOK ? "ON" : "OFF")
  1200.  
  1201. // PTB_TYPESAY
  1202. if ( (lastcmd = equal(cmd, "typesay")) && arglen ) PTB_TYPESAY = check_param_bool(arg)
  1203. if ( status || lastcmd ) console_print(id,"PTB: (typesay) typesay usage is %s.",PTB_TYPESAY ? "ON" : "OFF")
  1204.  
  1205. // team strength limits
  1206. if ( status ) console_print(id,"PTB: ---------- Team Strength Limits ----------")
  1207.  
  1208. // PTB_MAXSTREAK
  1209. if ( (lastcmd = equal(cmd, "maxstreak")) && arglen ) PTB_MAXSTREAK = check_param_num(arg,1)
  1210. if ( status || lastcmd ) console_print(id,"PTB: (maxstreak) Maximum accepted win streak is %d.", PTB_MAXSTREAK)
  1211.  
  1212. // PTB_MAXSCORE
  1213. if ( (lastcmd = equal(cmd, "maxscore")) && arglen ) PTB_MAXSCORE = check_param_num(arg,1)
  1214. if ( status || lastcmd ) console_print(id,"PTB: (maxscore) Maximum accepted team score difference is %d.", PTB_MAXSCORE)
  1215.  
  1216. // PTB_MINRATING
  1217. if ( (lastcmd = equal(cmd, "minrating")) && arglen ) PTB_MINRATING = check_param_float(arg,1.0)
  1218. if ( status || lastcmd ) console_print(id,"PTB: (minrating) Minimum critical strength rating is %.2f.",PTB_MINRATING)
  1219.  
  1220. // PTB_MAXRATING
  1221. if ( (lastcmd = equal(cmd, "maxrating")) && arglen ) PTB_MAXRATING = check_param_float(arg,1.0)
  1222. if ( status || lastcmd ) console_print(id,"PTB: (maxrating) Maximum critical strength rating is %.2f.",PTB_MAXRATING)
  1223.  
  1224. // PTB_SUPERRATING
  1225. if ( (lastcmd = equal(cmd, "superrating")) && arglen ) PTB_SUPERRATING = check_param_float(arg,1.0)
  1226. if ( status || lastcmd ) console_print(id,"PTB: (superrating) Super critical strength rating is %.2f.",PTB_SUPERRATING)
  1227.  
  1228. // PTB_MAXINCIDENTS
  1229. if ( (lastcmd = equal(cmd, "maxincidents")) && arglen ) PTB_MAXINCIDENTS = check_param_num(arg,1)
  1230. if ( status || lastcmd ) console_print(id,"PTB: (maxincidents) Maximum incidents before internal player score scale down is %d.", PTB_MAXINCIDENTS)
  1231.  
  1232. // PTB_SCALEDOWN
  1233. if ( (lastcmd = equal(cmd, "scaledown")) && arglen ) PTB_SCALEDOWN = check_param_num(arg,1)
  1234. if ( status || lastcmd ) console_print(id,"PTB: (scaledown) Integer scale down factor for player scores is %d.", PTB_SCALEDOWN)
  1235.  
  1236. // misc
  1237. if ( status ) {
  1238. console_print(id,"PTB: ---------- Misc ----------")
  1239. console_print(id,"PTB: To enable or disable PTB, type ^"admin_ptb <on|1|off|0>^".")
  1240. console_print(id,"PTB: To view or change a single PTB setting, type ^"amx_ptb <setting> <on|off|value>^".")
  1241. console_print(id,"PTB: To view a brief overview of PTB commands, type ^"amx_ptb help^" or ^"amx_ptb list^".")
  1242. console_print(id,"PTB: For PTB statistics, simply type ^"amx_ptb^".")
  1243. }
  1244.  
  1245. return PLUGIN_HANDLED
  1246. }
  1247.  
  1248. stock displayStatistics(id,bool:toLog = false) {
  1249. //say("displayStatistics")
  1250. new text[256]
  1251. // time
  1252. /*format(text, 255, "PTB: Statistics generated at: %s", lastTeamBalanceCheck)
  1253. if (toLog) log_amx(text)
  1254. console_print(id,text)*/
  1255. // connected players
  1256. format(text, 255, "PTB: Connected players: %d", get_playersnum())
  1257. if (toLog) log_amx(text)
  1258. console_print(id,text)
  1259. // team sizes
  1260. format(text, 255, "PTB: Team sizes: CTs %d, Ts %d", teamCounts[CTS], teamCounts[TS])
  1261. if (toLog) log_amx(text)
  1262. console_print(id,text)
  1263. // team scores
  1264. format(text, 255, "PTB: Team scores: CTs %d, Ts %d", teamScores[CTS], teamScores[TS])
  1265. if (toLog) log_amx(text)
  1266. console_print(id,text)
  1267. // Kills:Deaths
  1268. format(text, 255, "PTB: Team kills:deaths: CTs %d:%d, Ts %d:%d", teamKills[CTS], teamDeaths[CTS], teamKills[TS], teamDeaths[TS])
  1269. if (toLog) log_amx(text)
  1270. console_print(id,text)
  1271. // Kills/Deaths
  1272. format(text, 255, "PTB: Team kills/deaths: CTs %.2f, Ts %.2f", ctKD , tKD )
  1273. if (toLog) log_amx(text)
  1274. console_print(id,text)
  1275. // strength
  1276. format(text, 255, "PTB: Team strengths: CTs %.2f, Ts %.2f",ctStrength , tStrength )
  1277. if (toLog) log_amx(text)
  1278. console_print(id,text)
  1279. // rating
  1280. format(text, 255, "PTB: Team ratings: CTs %.2f, Ts %.2f",ctRating,tRating )
  1281. if (toLog) log_amx(text)
  1282. console_print(id,text)
  1283. // won rounds
  1284. if (winStreaks[CTS] > 0) {
  1285. format(text, 255, "PTB: Last %d round(s) won by CTs.", winStreaks[CTS])
  1286. if (toLog) log_amx(text)
  1287. console_print(id,text)
  1288. }
  1289. else if (winStreaks[TS] > 0) {
  1290. format(text, 255, "PTB: Last %d round(s) won by Ts.", winStreaks[TS])
  1291. if (toLog) log_amx(text)
  1292. console_print(id,text)
  1293. }
  1294.  
  1295. // winning team
  1296. switch(winnerTeam){
  1297. case CTS: format(text, 255, "PTB: The CTs are the winning team.")
  1298. case TS: format(text, 255, "PTB: The Ts are the winning team.")
  1299. default: format(text, 255, "PTB: Teams are balanced.")
  1300. }
  1301. if (toLog) log_amx(text)
  1302. console_print(id,text)
  1303.  
  1304. /*format(text, 255, "PTB: These statistics might be already outdated.")
  1305. if (toLog) log_amx(text)
  1306. console_print(id,text)
  1307.  
  1308. format(text, 255, "PTB: To view a brief overview of PTB commands, type ^"amx_ptb help^" or ^"amx_ptb list^".")
  1309. if (toLog) log_amx(text)
  1310. console_print(id,text)
  1311.  
  1312. format(text, 255, "PTB: To view all PTB settings, type ^"amx_ptb status^".")
  1313. if (toLog) log_amx(text)
  1314. console_print(id,text)*/
  1315. }
  1316.  
  1317. public client_connect(id){
  1318. kills[id] = 0
  1319. deaths[id] = 0
  1320. isBeingTransfered[id] = false
  1321. playerTeam[id] = UNASSIGNED
  1322. lastRoundSwitched[id] = -999
  1323. wtjCount[id] = 0
  1324. get_user_info(id,"_vgui_menus",clientVGUIMenu[id],1)
  1325. clientVGUIMenu[id][0] = '0'
  1326.  
  1327. return PLUGIN_CONTINUE
  1328. }
  1329.  
  1330. public client_disconnect(id) {
  1331. kills[id] = 0
  1332. deaths[id] = 0
  1333. isBeingTransfered[id] = false
  1334. playerTeam[id] = UNASSIGNED
  1335. lastRoundSwitched[id] = -999
  1336. wtjCount[id] = 0
  1337. // redundant team size check
  1338. teamCounts[UNASSIGNED] = 0
  1339. teamCounts[CTS] = 0
  1340. teamCounts[TS] = 0
  1341.  
  1342. new a = get_maxplayers()
  1343. for (new i = 1; i <= a; ++i)
  1344. ++teamCounts[playerTeam[i]]
  1345.  
  1346.  
  1347. if (clientVGUIMenu[id][0] != '0') {
  1348. set_user_info( id, "_vgui_menus", clientVGUIMenu[id] )
  1349. clientVGUIMenu[id][0] = '0'
  1350. }
  1351.  
  1352. return PLUGIN_CONTINUE
  1353. }
  1354.  

_________________
<<eb@>>Team Website - Közösség
17Buddies - Általam készített pályák.
GameBanana - Általam készített pályák/vágott hangok.

Kép
Kép


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 1 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 4 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole