the value of %p is the target carried from the alias to the ctcp reply, that ping code also sends the message dynamically, meaning if you use it in pm it will msg you via pm if you use it in a channel it will msg the channel, rather than static(1 target) like your code.
Also, var is temporary, once the alias function is complete %p would unset, the point of setting %p is to eliminate the need for manually setting a channel, like ur code does: %p #channel