Use the /scid command to switch the server connection the script is running on.
With scid you can either specify a connection id or use the -a switch to run the command on all connections. You can specify the command you want to run on the same line as /scid, or simply use it to switch servers and then program as usual afterward.
So you can either:
on *:connect:{
if ($network == relay_to) { set %relay_to $cid }
}
on *:text:*:#:{
if ($network == relay_from) {
scid %relay_to msg #somechan $1-
;scid %relay_to
;msg #somechan $1-
}
}
OR
on *:text:*:#:{
if ($network == relay_from) {
scid -a if ($network == relay_to) { msg #somechan $1- }
}
}