Why are you making it so hard on yourself? And what is the purpose of nick $+ %trackhost.var ?
You can make this so much simpler by creating a hash table that contains sites as items, and the data being their previous nicks.
Hashtable
item=data
some.host.com=john jake
some.other.host.net=mary lisa
on !*:JOIN:#:{
var %nicks = $hget(trackhost,$site)
if %nicks { echo -t # Known nicks: %nicks }
if !$istok(%nicks,$nick,32) { hadd trackhost $site %nicks $nick }
}
Btw, there are a lot of people with dynamic addresses, and on some networks, people get a random address, which basically means a script like this isn't fullproof at all. There's no guarantee their $site will be the same now as next time they connect.
Note that you ought to built in an if check to make sure that your hash table is open, or put this event in a group like #trackhost which should only be on if your hash table is loaded, and off if it's not loaded.
Greets