First off, you won't be able to write a function that returns 0 if the server is down. Servers are determined as 'down' when something like 2,000-5,000 milliseconds have passed and the server hasn't replied, so if you wanted to wait until that had passed before returning 0 the game would simply freeze for that long.
So you need an asynchronous option, which is totally possible. That just means it won't return true/false, you'll have a callback to handle whether it's up or down.
function pingServer(%ip) {
pingSingleServer(%ip, 4096);
}
package handlePing {
function onSimplePingReceived(%host,%ping,%index) {
if(%index == 4096) return myPingServerUp(%ping);
Parent::onSimplePingReceived(%host,%ping,%index);
}
function onSimplePingTimeout(%host,%index) {
if(%index == 4096) return myPingServerDown(%ping);
Parent::onSimplePingTimeout(%host,%index);
}
};
function myPingServerUp(%ping) {
// do your stuff
}
function myPingServerDown(%ping) {
// do your stuff
}
pingServer("127.0.0.1:24000");