Yeah, the on text event needs more parameters than you have given it (you are missing the channel).
Also, have a /set command at the beginning of the remote file won't do anything. You'd probably want to do an on load event, but even then, here this script is being copy pasted as text and probably not loaded. My suggestion to change it: at the beginning of any script that uses the variables, declare a local variable of the same name equal to the global variable if it exists, else the default value.
Example, at the beginning of a script that uses %hn:
var %hn $iif(%hn,$v1,assign)
That way, the rest of the script can remain constant.
Otherwise, there is going to have to be some mandatory manual configuration from the user.
I didn't really look at the rest, but if it works, then great.