mIRC Home    About    Download    Register    News    Help

Print Thread
#150823 09/06/06 10:06 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Lo all,

I'm trying to create a script, that can count tagged nicks.
Say people are making two teams, and they tag up, using:
[TEAM1]John
[TEAM1]Tim
[TEAM2]Susan

Now, I want to count the amount of nicks in [TEAM1] and the amount in [TEAM2]. So in the above example, I want to return: TEAM1 (2) - TEAM2 (1).

Now, I have:
$mid($gettok($nick($active,1),1,93),2)

This will just take TEAM1 or TEAM2 from the nick.
But the teams are not limited to team1 or team2, there can be many teams.

I think I need to create a variable for each 'team' found, see if it exists and then count all of them. Can anyone help me getting this going?

Thanks for the help

#150824 09/06/06 10:59 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
look this
Code:
 over

alias teamcount  {
var %all = $nick(#,0)
var %i = 1
while (%i <= %all) {
if team1 isin $nick(#,%i) { inc %teamcount1 }
elseif team2 isin $nick(#,%i) { inc %teamcount2 }
inc %i
}
msg # Team One: %teamcount1
msg # Team Two: %teamcount2
}


maybe that will be a start

#150825 09/06/06 11:12 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Thx for that Mike.
It is definately a start yes, but one problem.

The actual names of the teams could be anything.
So, I should start with finding the names of teams, and then adding the number (=count) to it.

[TEAM1] could just aswell be [ALPHA]
[TEAM2] could just aswell be [BETA]

Any idea, how to participate on that?
Thx again.

EDIT:
The only fixed part is the [ and ] brackets.
They will always be there, and the teamname will always be between those.

Last edited by OrionsBelt; 09/06/06 11:13 PM.
#150826 09/06/06 11:37 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Try this. I original tested this using a text file filled with [randomtag]randomnick. I made a few changes so it should work with a channel, but I have no way to test it.

Code:
alias tags {
  var %chan = [color:red]#channel[/color] %i = 1, %l = $nick(%chan,0), %nick, %team, %teams, %cteam, %teamcount, %playercount
  while (%i <= %l) {
    %nick = $nick(%chan,%i)
    if ($regex(%nick,/^\[.+\].+/i)) {
      %team = $mid($gettok(%nick,1,93),2-)
      if (!$istok(%teams,%team,32)) %teams = $+(%teams,$chr(32),%team)
      hadd -m %team $+(player,$calc($hget(%team,0).item  + 1)) %nick
      inc %playercount
    }
    inc %i
  }
  %teams = $sorttok(%teams,32)
  %teamcount = $numtok(%teams,32) | %i = 1
  echo -a There are $iif(%playercount,%playercount,0) players on $iif(%teamcount,%teamcount,0) teams
  while (%i <= %teamcount) {
    %cteam = $gettok(%teams,%i,32)
    echo -a Team %cteam $+($chr(40),$hget(%cteam,0).item,$chr(41))
    hfree %cteam
    inc %i
  }
}

#150827 09/06/06 11:42 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Tried your code exactly as you wrote it.
Made it run by typing: /tags
Resulted in: There are 0 players on 0 teams

Edit:
I modified the: "var %chan = #channel" as well now :tongue:
Still same result

Last edited by OrionsBelt; 09/06/06 11:45 PM.
#150828 09/06/06 11:44 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
If you don't mind could you tell me the server and channel you are on? PM it if necessary.

#150829 09/06/06 11:57 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Done that.

I checked the code a bit, and fixed some errors I made.
It now replies:

There are 234 players on 29 teams
Team -asc- (1)
* /hfree: insufficient parameters (line 141, tests.mrc)

Line 141: hfree %cteam

And there is halts.
I think this is actually what I'm looking for, once it continues to process the teams that is.

#150830 10/06/06 12:07 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Try replacing the line

hfree %cteam

with

.hfree -s %cteam

Since there is a - at the beginning of the team name, mIRC thinks you're trying to use switches with hfree. So, I use -s to display the result of the command but then silence it using the . prefix. It seems to solve the problem.

Edit: If you have already attempted to run the code, I suggest you close out of mIRC and re-open it using the fixed code unless you want to manually hfree all of those tables. None of them were cleared since the first code error'd at the first team.

#150831 10/06/06 12:12 AM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Amazing.
Yes, that seems to work perfectly.

Just one other thing.
What if the teamname is []TEAM[]Nick

Any way of including that? Or shall I just say, that they are not following the rules?

#150832 10/06/06 12:14 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Sorry, forgot to fully edit the code blush

I'll edit this again.

Last edited by schaefer31; 10/06/06 12:19 AM.
#150833 10/06/06 12:27 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Ok.

Find

Code:
    if ($regex(%nick,/^\[.+\].+/i)) {
      %team = $mid($gettok(%nick,1,93),2-)
      if (!$istok(%teams,%team,32)) %teams = $+(%teams,$chr(32),%team)
      hadd -m %team $+(player,$calc($hget(%team,0).item  + 1)) %nick
      inc %playercount
    }


Replace with

Code:
    if ($regex(%nick,/^\[.+\].+/)) {
      %team = $mid($gettok(%nick,1,93),2-)
      hadd -m %team $+(player,$calc($hget(%team,0).item  + 1)) %nick
      if (!$istok(%teams,%team,32)) %teams = $+(%teams,$chr(32),%team)
      inc %playercount
    }
    if ($regex(%nick,/^\[\].+\[\].+/)) {
      %team = $gettok($gettok(%nick,2,93),1,91)
      hadd -m %team $+(player,$calc($hget(%team,0).item  + 1)) %nick
      if (!$istok(%teams,%team,32)) %teams = $+(%teams,$chr(32),%team)
      inc %playercount
    }

#150834 10/06/06 12:38 AM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Jup, this works brilliantly.
Exactly how I needed it.

Thanks A LOT schaefer cool


Link Copied to Clipboard