Gather alias, link players, mix teams

Paste Your small code(s) here, ex. small aliases, identifiers

Gather alias, link players, mix teams

Postby Cristian » Sun Nov 02, 2008 1:24 am

Someone requested this one.

It's like the other gather-mix-split-alias I pasted.

But this one should be able to place "linked" data into the same variable.

If you have linked player1 and player3, the alias should put player1 and player3 into the same variable, which would be either %team.1 or %team.2

This will link player3-5 to player1
Code: Select all
/addlink player1 player3 player4 player5 

If you wish to link player6 to player1
Code: Select all
/addlink player1 player6 






Lets say that we link player5 and player8 to player1

Code: Select all
/addlink player1 player5 player8


And then we do the /mixplayers alias

Code: Select all
/mixplayers player1 player2 player3 player4 player5 player6 player7 player8 player9 player10 


And the result would be something like:

Code: Select all
Team 1 -> [[b]player1 player5 player8[/b]] player2 player7
Team 2 -> player3 player9 player6 player4 player10



If you think you can optimize it, please do. This was my way to do the job, I couldn't figure out a better way.


Code: Select all
alias addLink {
  if (!%linkInc) { set %linkInc 1 }
  var %found = 0
  var %x = 1
  while (%x <= %linkInc) {
    if ($gettok($eval($+(%,links.,%x),2),1,32) ==  $1) {
      var %found = 1
      set $+(%,links.,%x) $+($eval($+(%,links.,%x),2),$chr(32),$2-)
    }
    inc %x
  }
  if (%found == 0) {
    if (!%linkInc) { set %linkInc 1 } | else { inc %linkInc }
    set $+(%,links.,%linkInc) $1-
  }
}
alias isLinked {
  var %x = 1
  while (%x <= %linkInc) {
    if ($gettok($eval($+(%,links.,%x),2),1,32) ==  $1) {
      return $eval($+(%,links.,%x),2)
    }
    inc %x
  }
}

alias mixplayers {
  unset %terrorist
  unset %counter-terrorist

  var %players = $1-
  var %totalPlayers = $numtok($1-,32)

  var %team.1
  var %team.2

  var %totalTeams = $var(%team.*,0)
  var %used

  var %totalPlayerLinks = $totalPlayerLinks(links)
  var %totalLinks = $var(%links.*,0)
  var %x = 1
  while (%x <= %totalPlayers) {
    var %r = $r(1,%totalPlayers)
    var %r2 = $r(1,%totalTeams)
    var %player = $gettok($1-,%x,32)
    if ($isLinked(%player)) {
      var %x1 = $numtok($isLinked(%player),32)
      var %x2 = $numtok($eval($var(%team.*,%r2),2),32)
      if ($calc(%x1 + %x2) > 5) { continue }
      set $var(%team.*,%r2) $eval($var(%team.*,%r2),2) $isLinked(%player)
      var %c = 10
      while (%c) {
        if ($istok($isLinked(%player),$gettok(%players,%c,32),32)) {
          var %used = $addtok(%used,%c,32)
        }
        dec %c
      }
    }
    inc %x
  }
  while ($numtok(%team.1 %team.2,32) < %totalPlayers) {
    var %r = $r(1,%totalPlayers)
    var %r2 = $r(1,%totalTeams)
    var %player = $gettok($1-,%r,32)

    if (!$istok(%used,%r,32)) {
      if (!$matchtok(%team.1 %team.2,$+(*,%player,*),0,32)) {
        if ($numtok($eval($var(%team.*,%r2),2),32) < $calc(%totalPlayers /2)) {
          set $var(%team.*,%r2) $eval($var(%team.*,%r2),2) %player
          var %used = $addtok(%used,%r,32)
        }
      }
    }
  }
  ;set %terrorist %team.1
  ;set %counter-terrorist %team.2
    set %terrorist $sortLinked(%team.1)
    set %counter-terrorist $sortLinked(%team.2)

  ;echo -at Team 1 -> $sortLinked(%team.1)
  ;echo -at Team 2 -> $sortLinked(%team.2)
  .unset %links.*
}

alias totalPlayerLinks {
  var %x = 1
  var %inc
  var %totalLinks = $var($+(%,$1,.*))

  while (%x <= %totalLinks) {
    inc %inc $numtok($eval($var($+(%,$1,.*),%x),2),32)
    inc %x
  }
  return %inc
}

alias setplayers {
  unset %z
  var %players = $1-
  var %numbers = $numtok($1-,32)

  var %c = 1
  while (%c <= %numbers) {
    var %z = $addtok(%z,$gettok(%players,%c,32),32)
    inc %c
  }
  while (%c <= 10) {
    var %z = $addtok(%z,$+(X,%c),32)
    inc %c
  }

  return $replace($sortLinked(%z),$chr(32),$+($chr(32),-,$chr(32)))
}

alias sortLinked {
  var %players = $1-
  var %numbers = $numtok($1-,32)

  var %x = 1
  while (%x <= %numbers) {
    if (!$matchtok(%result,$gettok(%players,%x,32),0,32)) {

      if ($isLinked($gettok(%players,%x,32))) {
        var %result = $addtok(%result,$+([,$isLinked($gettok(%players,%x,32)),]),32)
      }
    }
    inc %x
  }
  var %x = 1
  while (%x <= %numbers) {
    if (!$matchtok(%result,$gettok(%players,%x,32),0,32)) {
      var %result = $addtok(%result,$gettok(%players,%x,32),32)
    }
    inc %x
  }
  return %result
}


I hope this could be useful to other as well.
//Sumsar
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Gather alias, link players, mix teams

Postby Lukemob » Mon Dec 01, 2008 1:24 pm

Sumsar supports gathering as well as I see :) Nice Sumsar
Lukemob
 

Re: Gather alias, link players, mix teams

Postby Cristian » Mon Dec 01, 2008 7:48 pm

yeah sometimes, I just hope others can use it, and I can see it in action on a channel :)
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar


Return to Mirc Scripting Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron