// DEFINE ISSPECTATOR() // // Purpose: // * Example of creating a custom isSpectator() function // // License: // * CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/ // * Home page: https://warzone.atlassian.net/wiki/display/EGG/Players+API // // ///////////////////////////////////////////////////////////////// void (function DefineIsSpectator() { var self = { file: "Define.isSpectator.js", ver : 1.0 }; var dependencies = { "Util.js" : 1.0, "Define.js" : 1.0, "Define.scavengerPlayer.js" : 1.0, // make sure scavengerPlayer global exists "Define.enumStruct.js": 1.0, // caching enumStruct() "Players.js": false // ensure Players.js not yet provided } uNeed(self, dependencies); // Util.js // ///////////////////////////////////////////////////////////////// // PUBLIC: DEFINE ISSPECTATOR() // if (Define.hasNative("countStruct")) { // Use faster count functions Define("isSpectator", function isSpectator32(playerID) { // scavs can't be spectators if (playerID >= maxPlayers) return false; // we can only identify specators in first few seconds of game if (gameTime > 15000) return undefined; // the player is a spectator if they have a sat uplink return countStruct(SAT_UPLINK, playerID); }); } else { // Use slower enum functions Define("isSpectator", function isSpectator31(playerID) { // scavs can't be spectators if (playerID >= maxPlayers) return false; // we can only identify specators in first few seconds of game if (gameTime > 15000) return undefined; // the player is a spectator if they have a sat uplink return enumStruct(playerID, SAT_UPLINK).length; }); } // ///////////////////////////////////////////////////////////////// // INTERNAL: CONFIRM AVAILABILITY uProvide(self); // Util.js })();