[Script] Teamkillers display
#1
Here's my script
[Image: JS3xNex.png]
For those who want to know how it works, I added in extra comments (more than I normally would) to make things easier to understand:
// scripts/teamkillers_display2.cfg
// written by Thrawn


bind K [show_teamkillers]

//don't save any of this to saved.cfg
persistidents 0

alias show_teamkillers [
  newmenu Teamkillers
  alias templist1 []
  alias templist2 []
  alias tmp []
  alias tmp2 []
  
  menuitem (concatword "| CN | " (c 3) "Teamkills" (c 5) " | " (c 2) "Name" (c 5) " |") -1
  alias tklist []

  // Old Method//
  //loop _cn 20 [
  //  if (isclient $_cn) [
  //    if (> (player $_cn tks) 0) [
  //      add2list _tklist $_cn
  //      menuitem (concatword "| " $_cn " | " (c 3) (player $_cn tks) (c 5) " | " (c 2) (player $_cn name)) -1
  //    ]
  //  ]
  //]
  //if (= (listlen $_tklist) 0) [ menuitem (concatword (c 0) "No Teamkills detected! :D") -1] []
  
  if (! (watchingdemo)) [alias tmp (+ 1 (highestcn))] [alias tmp 20] //highestcn doesn't work in demos
  loop _cn $tmp [
    if (isclient $_cn) [
      if (> (player $_cn tks) 0) [
      
        //create a list where each entry is the number of teamkills combined with client number in a single entry
        //l0 adds leading zeros to normalize number lengths
        add2list templist1 (concatword (l0 3 (player $_cn tks)) (l0 2 $_cn))
          //--Note, this will badly break the script if any one client has more than 999 teamkills in a match,
          //--  or if their cn is higher than 99. But, those are both so unlikely that it's safe to assume neither will occur
      ]
    ]
  ]
  
  if (= (listlen $templist1) 0) [ menuitem (concatword (c 0) "No Teamkills detected! :D") -1 ] [
    
    //since teamkills are the first 3 digits of each item, effectively sort by number of teamkills, then by cn
    alias templist1 (sortlist $templist1) //Note: sortlist sorts in ascending order (lowest-to-highest)
    
    //strip the first 3 digits containg teamkills, as they were only for sorting; leave behind the 2 digit client numbers
    looplist $templist1 tmp [ add2list templist2 (substr $tmp 3) ]
    
    //reverse list (we want descending (highest-to-lowest) sorting of teamkills)
    looplist $templist2 tmp [ push tmp2 $tmp ]    
    loop i (listlen $templist2) [
      add2list tklist $tmp2
      pop tmp2
    ]
    
    //We've got the sorted list of client numbers of teamkillers, we're good to go! :D
    looplist $tklist _cn [
      if (< $_cn 10) [
      
        //strip leading zero from single-digit client numbers (having a leading zero causes odd behavior and breaks the script)
        alias _cnf (substr $_cn 1)
      ] [
        alias _cnf $_cn //If double-digit, just copy the value
      ]
      menuitem (concatword "|  " $_cnf " | " (c 3) (player $_cnf tks) (c 5) " | " (c 2) (player $_cnf name)) -1
    ]
  ]
  
  showmenu Teamkillers
  
  onrelease [closemenu Teamkillers; delmenu Teamkillers]
]

persistidents 1 //Turn saving to saved.cfg back on

It's all thanks to the undocumented 'player' / 'playerinfo' command. It can actually pull a lot of different information, but a lot of it is not terribly useful. For those who are interested, it can return the following player attributes in the current version of the game (1.2.0.2):
// If the player with the specified client number is the local player (yourself)
  magcontent
  ammo
  primary
  curweapon
  nextprimary
//

// Additionally, if you are in spectate mode, or coop mode, or if the player is on your team
  health
  armour
  attacking
  scoping
  x // Yes, you can grab the xyz coordinates with cubescript
  y
  z
//

// Additionally, for any player
  name
  team
  ping
  pj
  state
  role
  frags
  flags
  points
  deaths
  tks
  alive
  spect
  cn // Only useful to get the local players cn, (the 'player1' / 'playerinfolocal' command doesn't require a cn argument. Alternatively, for the purposes of the 'player' / 'playerinfo' command, cn -1 always refers to the local player)
  skin_cla
  skin_rvsf
  skin
  ip // Same as the ip address you get from /whois. Censored under the same conditions
//
Thanks given by: +f0r3v3r+ , gy_be , hure , Vext , RandomPanda