//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- // Game duration in secs, no limit if the duration is set to 0 $Game::Duration = 20 * 60; // When a client score reaches this value, the game is ended. $Game::EndGameScore = 3; // Pause while looking over the end game screen (in secs) $Game::EndGamePause = 5;//was 10 changed (efa) 3/31/07 $Team1 = new ScriptObject() { teamId = 1; name = Red; score = 0; numPlayers = 0; }; $Team2 = new ScriptObject() { teamId = 2; name = Blue; score = 0; numPlayers = 0; }; //----------------------------------------------------------------------------- // Functions that implement game-play //----------------------------------------------------------------------------- function onServerCreated() { // Server::GameType is sent to the master server. // This variable should uniquely identify your game and/or mod. $Server::GameType = "UMHB"; // Server::MissionType sent to the master server. Clients can // filter servers based on mission type. //$Server::MissionType = "Deathmatch"; $Server::MissionType = $Pref::Server::MissionType; // GameStartTime is the sim time the game started. Used to calculated // game elapsed time. $Game::StartTime = 0; // Load up all datablocks, objects etc. This function is called when // a server is constructed. exec("./audioProfiles.cs"); exec("./camera.cs"); exec("./markers.cs"); exec("./triggers.cs"); exec("./inventory.cs"); exec("./shapeBase.cs"); exec("./item.cs"); exec("./health.cs"); exec("./staticShape.cs"); exec("./weapons/weapon.cs"); exec("./radiusDamage.cs"); exec("./teamObjectives.cs"); exec("./flag.cs"); // ***** Do the weapons ****** exec("./weapons/crossbow.cs"); exec("./weapons/grenades.cs"); exec("./weapons/rocket_launcher.cs"); exec("./weapons/mxrocket_launcher.cs"); exec("./weapons/rifle.cs"); exec("./weapons/machinegun.cs"); exec("./weapons/shotgun.cs"); exec("./weapons/pistol.cs"); exec("./slot1.cs"); // first weapon, the one displayed and ready to use. exec("./players/player.cs"); //really, player collision control and effects exec("./players/playerRed.cs"); exec("./players/playerBlue.cs"); //exec("./playerData.cs"); //(jmf) - teleporter script files exec("./customParticles.cs"); exec("./multiTeleportTrigger.cs"); //multiteleporters (efa) exec("./fxShapes.cs"); exec("./scene.cs"); //more special effects (efa) exec("./envAudioProfiles.cs"); //add environment speci effects (rain, etc) (efa) exec("./environment.cs"); //add environment speci effects (rain, etc) (efa) exec("./chimneyfire.cs"); //added bots to the game (efa) 2/03/08 exec("./players/playerOrc.cs"); exec("./aiBots.cs"); // exec("./aiPlayer.cs"); //added 5/22/08 (efa) // *** vehicles *** exec("./vehicle_damage.cs"); exec("./vehicle.cs"); exec("./car.cs"); exec("./jeep.cs"); //working in this (efa) 2/19/08 exec("./hover1.cs"); //works (efa) //****** Do the moving doors ****** added 2/25/08 (efa) - not mine just added exec("./doors/door.cs");//this has sound profiles in it, sort of a base door (efa) 2/25/08 exec("./doors/doorBlue.cs"); //I made this from door.cs and modified the *.dts and *.jpg file (efa) 2/25/08 //exec("./doors/doorMetal.cs"); //exec("./doors/doorgrey1.cs"); //exec("./doors/doorWood.cs"); exec("./doors/doorMetalMove.cs"); // modified 3/4/08 (DKT) //exec("./doors/doorMetalBars.cs"); //**** Special effects ***** added 2/25/08 (efa) - not mine just added exec("./fxEffects/window.cs"); //not tested 2/25/08 (efa) exec("./fxEffects/destroyableBarrel.cs"); //works 2/25/08 (efa) exec("./fxEffects/particles.cs"); //not tested 2/25/08 (efa) exec("./fxlights/fxlights.cs"); //fxlights exec("./fxlights/fxSpotLight1.cs"); exec("./fxlights/fxSpotLight2.cs"); exec("./fxlights/fxRedLight.cs"); exec("./fxlights/fxYellowLight.cs"); exec("./fxlights/fxBlueLight.cs"); exec("./fxlights/fxLantern.cs"); //(jmf) - invisibility script file exec("./invisible.cs"); } function onServerDestroyed() { // This function is called as part of a server shutdown. } //----------------------------------------------------------------------------- function onMissionLoaded() { echo("In onMissionLoaded()"); // Called by loadMission() once the mission is finished loading. // Nothing special for now, just start up the game play. //if(!$pref::HostMultiPlayer) //{ startGame(); //} } function onMissionEnded() { // Called by endMission(), right before the mission is destroyed // Normally the game should be ended first before the next // mission is loaded, this is here in case loadMission has been // called directly. The mission will be ended if the server // is destroyed, so we only need to cleanup here. cancel($Game::Schedule); $Game::Running = false; $Game::Cycling = false; } //--------------------------------------------------------------------------- function startGame() { echo("In startGame()"); if ($Game::Running) { error("startGame: End the game first!"); return; } // Keep track of when the game started $Game::StartTime = $Sim::Time; // Inform the client we're starting up for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'GameStart'); // Other client specific setup.. %cl.score = 0; } $lastPos = ""; $onHunt = 0; // Start the AIManager if UseBots is set to true (efa) 2/13/08 if($pref::UseBots) { new ScriptObject(AIManager) {}; MissionCleanup.add(AIManager); AIManager.think(); } // Start the game timer if ($Game::Duration) $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" ); $Game::Running = true; } function endGame() { if (!$Game::Running) { error("endGame: No game running!"); return; } // Stop the AIManager //AIManager.delete(); //(efa) commented out, we are not running the AI 3/29/07 // Stop any game timers cancel($Game::Schedule); // Inform the client the game is over for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'GameEnd'); } // Delete all the temporary mission objects resetMission(); $Game::Running = false; } function onGameDurationEnd() { // This "redirect" is here so that we can abort the game cycle if // the $Game::Duration variable has been cleared, without having // to have a function to cancel the schedule. if ($Game::Duration && !isObject(EditorGui)) cycleGame(); } //----------------------------------------------------------------------------- function cycleGame() { // This is setup as a schedule so that this function can be called // directly from object callbacks. Object callbacks have to be // carefull about invoking server functions that could cause // their object to be deleted. if (!$Game::Cycling) { $Game::Cycling = true; $Game::Schedule = schedule(0, 0, "onCycleExec"); } } function onCycleExec() { // End the current game and start another one, we'll pause for a little // so the end game victory screen can be examined by the clients. endGame(); $Game::Schedule = schedule($Game::EndGamePause * 1000, 0, "onCyclePauseEnd"); } function onCyclePauseEnd() { $Game::Cycling = false; // Just cycle through the missions for now. (uncommented this (efa) 6/16/08) %search = $Server::MissionFileSpec; for (%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search)) { if (%file $= $Server::MissionFile) { // Get the next one, back to the first if there // is no next. %file = findNextFile(%search); if (%file $= "") %file = findFirstFile(%search); break; } } $Team1.score = 0; $Team2.score = 0; $Game::TeamFlagCaptures[1] = 0; //reset the number of flags capture(efa) 6/16/08) $Game::TeamFlagCaptures[2] = 0; loadMission($Game::mission); } //----------------------------------------------------------------------------- // GameConnection Methods // These methods are extensions to the GameConnection class. Extending // GameConnection make is easier to deal with some of this functionality, // but these could also be implemented as stand-alone functions. //----------------------------------------------------------------------------- function GameConnection::onClientEnterGame(%this) { commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime); // Create a new camera object. %this.camera = new Camera() { dataBlock = Observer; }; MissionCleanup.add( %this.camera ); %this.camera.scopeToClient(%this); // Setup game parameters, the onConnect method currently starts // everyone with a 0 score. %this.score = 0; %this.team = 0; //default team is 0 "Observer" commandToClient( %this, 'SetMissionType', $Pref::Server::MissionType ); if($Pref::Server::MissionType !$= "DeathMatch") { if( $Team1.numPlayers <= $Team2.numPlayers ) { %this.joinTeam(1); } else { %this.joinTeam(2); } // Update client with status of the individual teams messageClient(%this, 'MsgClientTeamUpdate', "", $Team1.name, $Team1.teamId, $Team1.score); messageClient(%this, 'MsgClientTeamUpdate', "", $Team2.name, $Team2.teamId, $Team2.score); return; } // Create a player object. %this.spawnPlayer(); } function GameConnection::onClientLeaveGame(%this) { %this.leaveTeam(); if (isObject(%this.camera)) %this.camera.delete(); if (isObject(%this.player)) %this.player.delete(); //Destroy AIManager and kill the AIs AIGroup.delete(); //AIManager.delete(); } //----------------------------------------------------------------------------- function GameConnection::onLeaveMissionArea(%this) { // The control objects invoked this method when they // move out of the mission area. } function GameConnection::onEnterMissionArea(%this) { // The control objects invoked this method when they // move back into the mission area. } //----------------------------------------------------------------------------- function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc) { // Clear out the name on the corpse %this.player.setShapeName(""); // Switch the client over to the death cam and unhook the player object. if (isObject(%this.camera) && isObject(%this.player)) { %this.camera.setMode("Corpse",%this.player); %this.setControlObject(%this.camera); } %this.player = 0; %this.schedule( 5000, "spawnPlayer" ); // Doll out points and display an appropriate message if($Pref::Server::MissionType $= "DeathMatch") { echo("In onDeath for DeathMatch Game Type"); if (%damageType $= "Suicide" || %sourceClient == %this) { %this.incScore(-1); messageAll('MsgClientKilled','%1 takes his own life!',%this.name); } else { %sourceClient.incScore(1); messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name); if (%sourceClient.score >= $Game::EndGameScore) cycleGame(); } } else if($Pref::Server::MissionType $= "TeamSlayer") { echo("In onDeath for TeamSlayer Game Type"); if (%damageType $= "Suicide" || %sourceClient == %this) { %this.incScore(-1); %this.team.score--; messageAll('MsgClientScoreChangedTeam', "", %this.score, %this, %this.team.teamId); messageAll('MsgTeamScoreChanged', "", %this.team.score, %this.team.teamId); messageAll('MsgClientKilled','%1 takes his own life!',%this.name); messageAll('MsgTeamPointLost','%1 team loses a point!',%this.team.name); } else if(%sourceClient.team.teamid == %this.team.teamid) { %this.incScore(-1); %this.team.score--; messageAll('MsgClientScoreChangedTeam', "", %this.score, %this, %this.team.teamId); messageAll('MsgTeamScoreChanged', "", %this.team.score, %this.team.teamId); messageAll('MsgClientKilled','%1 nailed by his own team mate %2!', %this.name, %sourceClient.name); messageAll('MsgTeamPointLost','%1 team loses a point!', %this.team.name); } else { %sourceClient.incScore(1); %sourceClient.team.score++; messageAll('MsgClientScoreChangedTeam', "", %sourceClient.score, %sourceClient, %sourceClient.team.teamId); messageAll('MsgTeamScoreChanged', "", %sourceClient.team.score, %sourceClient.team.teamId); messageAll('MsgClientKilled','%1 gets nailed by %2!', %this.name, %sourceClient.name); messageAll('MsgTeamPointGained','Chalk one up for the %1 team!', %sourceClient.team.name); if(%sourceClient.team.score >= $Game::EndGameScore) { cycleGame(); } } } else if($Pref::Server::MissionType $= "CaptureTheFlag") { echo("In onDeath for CaptureTheFlag Game Type"); if (%damageType $= "Suicide" || %sourceClient == %this) { //%this.incScore(-1); //%this.team.score--; messageAll('MsgClientKilled','%1 takes his own life!',%this.name); } else if(%sourceClient.team.teamid == %this.team.teamid) { //%this.incScore(-1); //%this.team.score--; messageAll('MsgClientKilled','%1 nailed by his own team mate %2!', %this.name, %sourceClient.name); } else { //%sourceClient.incScore(1); //%sourceClient.team.score++; messageAll('MsgClientKilled','%1 gets nailed by %2!', %this.name, %sourceClient.name); } } } //----------------------------------------------------------------------------- function GameConnection::spawnPlayer(%this) { if( !$Game::Running ) { return; } // Combination create player and drop him somewhere %spawnPoint = pickSpawnPoint(%this); %this.createPlayer(%spawnPoint); } //fzj 3-29-2007 function GameConnection::displayTeamHUD(%client, %teamid) { echo("FZ - GameConnection::displayTeamHUD called"); echo("FZ - calling commandToClient... displayTeamHUD"); commandToClient(%client, 'displayTeamHUD', %teamid); //put back (efa) 6/25/08 } //----------------------------------------------------------------------------- function GameConnection::createPlayer(%this, %spawnPoint) { if (%this.player > 0) { // The client should not have a player currently // assigned. Assigning a new one could result in // a player ghost. error( "Attempting to create an angus ghost!" ); } // Create the player object if($Pref::Server::MissionType $= "DeathMatch") { %player = new Player() { dataBlock = PlayerPistol; client = %this; }; } else if($Pref::Server::MissionType !$= "DeathMatch") { if(%this.team.teamId == 1) { %player = new Player() { dataBlock = PlayerPistolRed; client = %this; }; } else if(%this.team.teamId == 2) { %player = new Player() { dataBlock = PlayerPistolBlue; client = %this; }; } } MissionCleanup.add(%player); //set up the slot based inventory %player.setInventory(slot1,$SLOTPISTOL); // first weapon, the one displayed and ready to use. %player.setInventory(slot2,$SLOTNOTHING); // second weapon, the one hidden, in reserve. %player.setInventory(slot3,$SLOTGRENADE); // used for grenades (efa) 2/16/08 // Player setup... %player.setTransform(%spawnPoint); %player.setShapeName(%this.name); // Starting equipment %player.setInventory(RocketLauncher,0); %player.setInventory(RocketAmmo,0); // %player.mountImage(RocketLauncherImage,0); %player.setInventory(MxRocketLauncher,0); %player.setInventory(MxRocketAmmo,0); %player.setInventory(Crossbow,0); %player.setInventory(CrossbowAmmo,0); %player.setInventory(Rifle,0); %player.setInventory(RifleAmmo,0); //%player.mountImage(RifleImage,0); %player.setInventory(MachineGun,0); %player.setInventory(MachineGunAmmo,0); //%player.mountImage(MachineGunImage,0); %player.setInventory(ShotGun,0); %player.setInventory(ShotGunAmmo,0); //%player.mountImage(ShotGunImage,0); %player.setInventory(Pistol,1); //the 1 blocks picking up more, shows we have this weapon %player.setInventory(PistolAmmo,100); %player.mountImage(PistolImage,0); %player.setInventory(Grenade,1); //the 1 blocks picking up more, shows we have this weapon %player.setInventory(GrenadeAmmo,5); // %player.mountImage(GrenadeImage,0); %player.client.displayWeaponHUDTWO("NOTHING"); %player.client.setGAmountHud(%player.inv[Grenade]); //was gAmmo %player.client.displayTeamHud(%this.team.teamId); //added by fzj 3/29/2007 // Update the camera to start with the player %this.camera.setTransform(%player.getEyeTransform()); commandToServer("use","slot1"); //(efa) 2/25/08 reload weapons // Give the client control of the player %this.player = %player; %this.setControlObject(%player); } //----------------------------------------------------------------------------- // Support functions //----------------------------------------------------------------------------- function pickSpawnPoint(%client) { if( $Pref::Server::MissionType !$= "DeathMatch" ) { echo("Selecting spawn point for nonDeathMatch Game Type"); %groupName = "MissionGroup/" @ %client.team.name @ "TeamDropPoints"; %group = nameToID(%groupName); if (%group != -1) { %count = %group.getCount(); if (%count != 0) { %index = getRandom(%count-1); %spawn = %group.getObject(%index); return %spawn.getTransform(); } else { error("No " @ %client.team.name @ " team spawn points found in " @ %groupName); } } else { error("Missing " @ %client.team.name @ " team spawn points group " @ %groupName); } } else { echo("Selecting spawn point for DeathMatch Game Type"); %groupName = "MissionGroup/PlayerDropPoints"; %group = nameToID(%groupName); if (%group != -1) { %count = %group.getCount(); if (%count != 0) { %index = getRandom(%count-1); %spawn = %group.getObject(%index); return %spawn.getTransform(); } else { error("No spawn points found in " @ %groupName); } } else { error("Missing spawn points group " @ %groupName); } } // Could be no spawn points, in which case we'll stick the // player at the center of the world. return "0 0 300 1 0 0 0"; } function GameConnection::joinTeam( %this, %teamid ) { //We only have 2 teams so if team is greater than 2 or less than 0 its invalid. if( %teamid > 2 || %teamid < 0 ) { return false; } //If we already are on that team return. if( %teamid == %this.team.teamId ) { return false; } %this.score = 0; %this.leaveTeam(); if( %teamid == 1 ) { %this.team = $Team1; $Team1.numPlayers++; } if( %teamid == 2 ) { %this.team = $Team2; $Team2.numPlayers++; } MessageAll( 'MsgClientJoinTeam', '\c2%1 joined the %2 side', %this.name, %this.team.name, %this.team.teamId, %this, %this.sendGuid, %this.score, %this.isAdmin, %this.isSuperAdmin); %this.spawnPlayer(); } function GameConnection::leaveTeam( %client ) { MessageAll( 'MsgClientDropTeam', "", %client.name, %client, %client.team.teamId ); if(%client.team == $Team1) { $Team1.numPlayers--; MessageAll( 'MsgClientLeaveTeam', '\c2%1 left the %2 team.', %client.name, %client.team.name, %client); } else if(%client.team == $Team2) { $Team2.numPlayers--; MessageAll( 'MsgClientLeaveTeam', '\c2%1 left the %2 team.', %client.name, %client.team.name, %client); } if( %client.player ) { if( %client.player.getMountedImage( $FlagSlot ) != 0 ) { newflag( %client.player.getMountedImage( $FlagSlot ).item, %client.player); %client.player.unmountImage( $FlagSlot ); if(%client.team.teamId == 1) { echo("Setting Blue Team Flagged Dropped"); $BlueTeamFlagDropped = true; } else if(%client.team.teamId == 2) { echo("Setting Red Team Flagged Dropped"); $RedTeamFlagDropped = true; } } %client.player.delete(); } } //Added to Kill the "On need relight" error in the console. function onNeedRelight() { }