Game Script (GSC) is the scripting language used in Call of Duty 4 for creating custom game modes, server logic, and gameplay mechanics. CoD4 Unleashed Server extends the standard GSC functionality with powerful new features.
GSC scripts use a C-like syntax with functions, variables, and control structures:
// Function definitionmyFunction() { variable = "Hello World"; iprintln(variable);}// Function with parametersadd(a, b) { return a + b;}// Conditional logiccheckValue(value) { if (value > 10) { iprintln("Greater than 10"); } else { iprintln("Less than or equal to 10"); }}
CoD4 Unleashed supports both .gsc and .gsx file extensions. When loading scripts, the server will first try to load .gsx files, allowing you to use extended functionality while maintaining compatibility with standard scripts.
CoD4 Unleashed provides comprehensive type checking:
if (isDefined(variable)) { iprintln("Variable exists");}if (isString(variable)) { iprintln("Variable is a string");}if (isInt(variable)) { iprintln("Variable is an integer");}if (isFloat(variable)) { iprintln("Variable is a float");}if (isArray(variable)) { iprintln("Variable is an array");}if (isBool(variable)) { iprintln("Variable is a boolean");}if (isVector(variable)) { iprintln("Variable is a vector");}
// Called when a player connectsCodeCallback_PlayerConnect() { self.pers["score"] = 0; self.pers["deaths"] = 0;}// Called when a player is damagedCodeCallback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime) { // Custom damage logic if (sMeansOfDeath == "MOD_FALLING") { iDamage = int(iDamage * 0.5); // Reduce fall damage }}// Called when a player is killedCodeCallback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration) { self.deaths++; if (isPlayer(attacker)) { attacker.kills++; }}
GSC supports threaded execution for concurrent operations:
// Start a function in a new threadthread myFunction();// Thread with parametersthread delayedMessage("Hello", 5);delayedMessage(message, delay) { wait delay; iprintln(message);}// Endon - terminate thread when event occursmonitorPlayer() { self endon("disconnect"); self endon("death"); for(;;) { // This loop will end when player disconnects or dies wait 1; iprintln("Still alive: " + self.name); }}
GSC does not have try-catch blocks. Use assertions and careful validation to prevent script errors.
// Assertions for debuggingassertEx(isDefined(variable), "Variable must be defined");assertEx(isArray(players), "Players must be an array");// Validationif (!isDefined(self) || !isPlayer(self)) { return; // Early exit}if (value < 0 || value > 100) { value = clamp(value, 0, 100);}