|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
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
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
look this 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
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
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.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
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. 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
}
}
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
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.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
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.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
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?
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
Sorry, forgot to fully edit the code  I'll edit this again.
Last edited by schaefer31; 10/06/06 12:19 AM.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
Ok. Find 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 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
}
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Jup, this works brilliantly. Exactly how I needed it. Thanks A LOT schaefer 
|
|
|
|
|