Here's a revision of the old Battlefield 2 stats gatherer, the bf2s.com site changes a bit so this code has to aswell.
It can use a player's nickname or PID to check the stats.
It now uses flags aswell to let the user customize what returns.
It can return ID, Name, Rank, Global score, Kills, Deaths, Score per minute, Total time played and the server they are playing formatted as , in any order and customisable default message
Overall, simpler and alot better :)
Usage: !bf2stats [nick/id] [flags]
Just type !bf2stats for info
;Battlefield 2 Stats Checker (Revision 2 - 07/06/06)
;Made by Daveoh on Quakenet @ #kidswithguns
;Thanks to bf2s.com for providing Battlefield 2 stats!
;Edit to how seen fit, but please include these first four lines :)
on *:TEXT:!bf2stats*:#:{ if (%bf2stats != $null) { halt } | unset %bf2stats.*
set -u3 %bf2stats 1
if ($2 == $null) { msg $chan Usage: !bf2stats <player name/id> [flags inrgst] | msg $chan Flags: i = id $chr(124) n = Name $chr(124) r = Rank $chr(124) g = Global score $chr(124) k = Kills $chr(124) d = Deaths $chr(124) s = SPM $chr(124) t = Time $chr(124) v = Server | msg $chan The order of the flags affects the outcome, each flag can only be used once | halt }
checkbf2stats $iif($2 isnum,id,name) $2 $chan $3
}
alias checkbf2stats {
if ($4 != $null) { set %bf2stats.custom $4 }
set %bf2stats.chan $$3
set %bf2stats.player $$2
set %bf2stats.type $$1
if ($1 == id) { if ($sock(bf2id)) { sockclose bf2id } | sockopen bf2id bf2s.com 80 }
elseif ($1 == name) { if ($sock(bf2id)) { sockclose bf2name } | sockopen bf2name bf2s.com 80 }
}
on *:sockopen:bf2id:{
sockwrite -n $sockname GET $+(/player/,%bf2stats.player,/) HTTP/1.0
sockwrite -n $sockname Host: bf2s.com
sockwrite -n $sockname user-agent: Mozilla/??
sockwrite -n $sockname Connection: Keep-Alive
sockwrite -n $sockname $crlf
}
on 1:sockread:bf2id:{
:nextread
if ($sockerr > 0) return
sockread %temp
if ($sockbr == 0) return
if ($len(%temp) < 250) { var %temp = $remove(%temp, ) }
if (%bf2stats.done == 1) { if (%bf2stats.custom == $null) {
;Customize the default message here! :D Useable values = :name: :id: :rank: :global: :kills: :deaths: :spm: :time: :server:
set %bf2stats.msg :name: :id: :rank: :global: :kills: :deaths: :spm: :time: :server: }
else { var %a = 1
while (%a <= $len(%bf2stats.custom)) {
if ($+(:,$right($left(%bf2stats.custom,%a),1),:) isin %bf2stats.msg) { ;flag already used }
else set %bf2stats.msg %bf2stats.msg $+(:,$right($left(%bf2stats.custom,%a),1),:)
if (%a == $len(%bf2stats.custom)) { set %bf2stats.msg $replace(%bf2stats.msg,:n:,:name:,:i:,:id:,:r:,:rank:,:g:,:global:,:k:,:kills:,:d:,:deaths:,:s:,:spm:,:t:,:time:,:v:,:server:) }
inc %a
} }
msg %bf2stats.chan $replace(%bf2stats.msg,$chr(32),$+($chr(32),$chr(124),$chr(32)),:id:,Id: %bf2stats.player,:name:,Name: %bf2stats.playername,:rank:,Rank: %bf2stats.playerrank,:global:,Global points: %bf2stats.global,:kills:,Kills: %bf2stats.kills,:deaths:,Deaths: %bf2stats.deaths,:spm:,Score Per Min: %bf2stats.spm,:time:,Total time played: %bf2stats.totaltime,:server:,Server: %bf2stats.servername %bf2stats.mapname %bf2stats.ip)
unset %bf2stats.*
}
if (%bf2stats.next == global) { set %bf2stats.global $remove(%temp,<td>,</td>) | unset %bf2stats.next }
if (%bf2stats.next == total) { set %bf2stats.totaltime $remove(%temp,<td nowrap="nowrap">,</td>) | unset %bf2stats.next }
if (%bf2stats.next == SPM) { set %bf2stats.spm $remove(%temp,<td>,</td>) | unset %bf2stats.next }
if (%bf2stats.killsin == 1) { set %bf2stats.kills $gettok($remove(%temp,<td>,</td>),1,47) | unset %bf2stats.killsin }
if (%bf2stats.killsin > 1) { dec %bf2stats.killsin }
if (%bf2stats.deathsin == 1) { set %bf2stats.deaths $gettok($remove(%temp,<td>,</td>),1,47) | unset %bf2stats.deathsin | set %bf2stats.done 1 }
if (%bf2stats.deathsin > 1) { dec %bf2stats.deathsin }
if (<h1 id="page-title">* iswm $remove(%temp, )) {
if (<h1 id="page-title">Player Stats</h1> == %temp) { msg %bf2stats.chan Sorry, $replace(%bf2stats.type,name,player) %bf2stats.player doesn't seam to exist | unset %bf2stats.* | sockclose bf2id | halt }
else {
set %bf2stats.playername $gettok($gettok(%temp,3,62),1,60)
set %bf2stats.playerrank $gettok($gettok(%temp,4,62),1,60)
} }
if (<td>Global</td> == %temp) set %bf2stats.next global
if (<td>Total</td> == %temp) set %bf2stats.next total
if ("Score per minute" isin %temp) set %bf2stats.next SPM
if (<th colspan="2">Kills</th> == %temp) set %bf2stats.killsin 4
if (<th colspan="2">Deaths</th> == %temp) set %bf2stats.deathsin 4
if (* $+ %bf2stats.playername $+ * iswm %temp) {
if (<strong>* iswm %temp) {
set %bf2stats.servername $remove($gettok(%temp,5-,60),</em></a></strong></p>,em>)
set %bf2stats.mapname - $remove($gettok(%temp,2,60),em>)
set %bf2stats.ip - $gettok($gettok(%temp,4,60),4,47)
}
else { set %bf2stats.servername Offline }
}
goto nextread
}
on *:sockopen:bf2name:{
sockwrite -n $sockname GET $+(/find.php?pid=,%bf2stats.player) HTTP/1.0
sockwrite -n $sockname Host: bf2s.com
sockwrite -n $sockname user-agent: Mozilla/??
sockwrite -n $sockname Connection: Keep-Alive
sockwrite -n $sockname $crlf
}
on 1:sockread:bf2name:{
:nextread
if ($sockerr > 0) return
sockread %temp
if ($sockbr == 0) return
if (Location:* iswm %temp) { checkbf2stats id $gettok(%temp,3,47) %bf2stats.chan | return }
if (%bf2stats.namein == 1) { unset %bf2stats.namein | checkbf2stats id $gettok(%temp,3,47) %bf2stats.chan | return }
if (%bf2stats.namein > 0) { dec %bf2stats.namein | goto nextread }
if (*Couldn't find a thing, sorry.* iswm %temp) { msg %bf2stats.chan Sorry, $replace(%bf2stats.type,name,player) %bf2stats.player doesn't seam to exist | unset %bf2stats.* | return }
if (*Players Found (via EA)* iswm %temp) {
set %bf2stats.namein 4
}
goto nextread
}
I\'ve PMed you this in IRC Daveoh, but would it be possible to add a Now Playing On function?
So for example !stats aBF2Player kgp would return
<Bot> Kills: 13,245 | Global: 135,156 | Playing On: 213.150.38.157:16867
If they were not playing on a server, it could just put \"Not online\" or something.
Loads and LOADS of people have requested this function :)