Game Development Community

Page«First 1 2 3 Next»
#41
09/08/2008 (2:26 pm)
function onServerDestroyed()
{
   // This function is called as part of a server shutdown.
}


//-----------------------------------------------------------------------------

function onMissionLoaded()
{
   // Called by loadMission() once the mission is finished loading.
   // Nothing special for now, just start up the game play.
   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;

   // DATABLOCK CACHE CODE <<
   if ($Pref::Server::EnableDatablockCache)
     resetDatablockCache();
   // DATABLOCK CACHE CODE >>

   // AFX SCRIPT BLOCK <<
   afxEndMissionNotify();
   // AFX SCRIPT BLOCK >>
}


//-----------------------------------------------------------------------------

function startGame()
{
   if ($Game::Running) {
      error("startGame: End the game first!");
      return;
   }

   // 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;
   }

   // Start the game timer
   if ($Game::Duration)
      $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
   $Game::Running = true;
   
   // AFX SCRIPT BLOCK <<
   // Start the AIManager
   startAIManager();
   // AFX SCRIPT BLOCK >>
}

function endGame()
{
   // Game specific cleanup...
   if (!$Game::Running)  {
      error("endGame: No game running!");
      return;
   }
   
   // AFX SCRIPT BLOCK <<
   // Stop the AIManager
   stopsAIManager();
   // AFX SCRIPT BLOCK >>

   // 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");
}
#42
09/08/2008 (2:27 pm)
function onCyclePauseEnd()
{
   $Game::Cycling = false;

   // Just cycle through the missions for now.
   %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;
      }
   }
   loadMission(%file);
}


//-----------------------------------------------------------------------------
// 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);

   // AFX SCRIPT BLOCK <<
   // This is where we create the afxCamera
   /*%this.camera = new afxCamera()
   {
      dataBlock = DefaultCameraData;
   };*/
   %this.camera = new AdvancedCamera() 
   {
      dataBlock = AdvCameraData;
   };
   // AFX SCRIPT BLOCK >>
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);

    toggleFirstPerson(1); // switch on enter game
   // Setup game parameters, the onConnect method currently starts
   // everyone with a 0 score.
   %this.score = 0;

   // Create a player object.
   %this.spawnPlayer(true);
}

function GameConnection::onClientLeaveGame(%this)
{
   if (isObject(%this.camera))
      %this.camera.delete();
   if (isObject(%this.player))
      %this.player.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 connections camera
    %this.camera.clearPlayerObject();
    %this.camera.clearTargetObject();
    %this.clearCameraObject();
  //%this.clearCameraObject();

  %corpse = %this.player;

  // interrupt active spellcasting
  if (isObject(%this.player.spellBeingCast))
  {
    %spell = %this.player.spellBeingCast;
    %spell.interrupt();
    %this.player.spellBeingCast = "";
  }
  
  // Clear out the name on the corpse
  %corpse.setShapeName("dead orc");
  %corpse.setEnergyLevel(0);

  // Switch the client over to the death cam and unhook the player object.
  if (isObject(%this.camera) && isObject(%corpse)) 
  {
    //%this.camera.setMode("Corpse",%corpse);
    %this.camera.setOrbitMode(%corpse, %corpse.getTransform(), 0.5, 4.5, 4.5);
    %this.setControlObject(%this.camera);
    snapAtlasGeometryMorph();
  }
  
  // Dole out points and display an appropriate message
  if (%damageType $= "SelfDestruction" || %sourceClient == %this) 
  {
    %this.incScore(-1);
    messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
  }
  else if (%sourceClient != 0)
  {
    %sourceClient.incScore(1);
    messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
    if (%sourceClient.score >= $Game::EndGameScore)
      cycleGame();
  }
}
#43
09/08/2008 (2:27 pm)
//-----------------------------------------------------------------------------

function GameConnection::spawnPlayer(%this, %first_spawn, %xfm, %body_type, %morph_from)
{
   // clear out old linkages between player and client
   if (isObject(%this.player))
   {
     %this.player.client = "";
     %this.player = "";
   }

   // create player and drop him somewhere
   if (%xfm != 0)
     %spawnPoint = %xfm;
   else
    %spawnPoint = pickSpawnPoint();

   return %this.createPlayer(%spawnPoint, %first_spawn, %body_type, %morph_from);
}   


//-----------------------------------------------------------------------------

function sendPlayerSpellBookToClient(%client, %spellbook)
{
  %ghost_idx = %client.GetGhostIndex(%spellbook);
  //echo("SPELLBOOK ON SERVER " @ %spellbook @ " " @ %ghost_idx);
  if (%ghost_idx == -1)
    schedule(100, 0, "sendPlayerSpellBookToClient", %client, %spellbook);
  else
    commandToClient(%client, 'SetPlayerSpellBook', %ghost_idx);
}

function sendClientPlayerToClient(%client, %player)
{
  %ghost_idx = %client.GetGhostIndex(%player);
  //echo("PLAYER ON SERVER " @ %player @ " " @ %ghost_idx);
  if (%ghost_idx == -1)
    schedule(100, 0, "sendClientPlayerToClient", %client, %player);
  else
    commandToClient(%client, 'SetClientPlayer', %ghost_idx);
}

$default_body_type = "OrcMageAvatar";
//$default_body_type = "SpaceOrcMageAvatar";

function GameConnection::createPlayer(%this, %spawnPoint, %first_spawn, %body_type, %morph_from)
{
  if (isObject(%this.player))
  {
    error("Attempting to create an extra player character!");
    return %this.player;
  }
  hideCursor();
  %morph = isObject(%morph_from);

  if (!isObject(%body_type))
    %body_type = $default_body_type;

  // Create the player object
  %player = new Player() 
  {
    dataBlock = %body_type;
    client = %this;
  };

  %player_name = stripChars(detag(getTaggedString(%this.name)),"\cp\co\c6\c7\c8\c9");
  %player.setShapeName(%player_name);
  if (!%morph)
  {
     %player.setEnergyLevel(50);
  }
  else
  {
     %player.setEnergyLevel(%morph_from.getEnergyLevel());
     %player.setDamageLevel(%morph_from.getDamageLevel());
     %player.copyHeadRotation(%morph_from);
  }

  %player.setLookAnimationOverride(true);
  %player.setTransform(%spawnPoint);
  MissionCleanup.add(%player);

  if (!%morph)
  {
     // Create player's spellbook
     %my_spellbook = new afxSpellBook() 
     {
       dataBlock = SpellBookData;
     };
     MissionCleanup.add(%my_spellbook);

     %this.spellbook = %my_spellbook;
  }

  schedule(0, 0, "sendClientPlayerToClient", %this, %player);

  if (!%morph)
  {
    schedule(0, 0, "sendPlayerSpellBookToClient", %this, %my_spellbook);
  }

  // Update the camera to start with the player
 // if (!%morph)
     //%this.camera.setTransform(%player.getEyeTransform());

  // Give the client control of the player
  %this.player = %player;

   %player.setInventory(CrossbowImage,1);
   %player.setInventory(CrossbowAmmo,100);
   //MP5
   %player.setInventory(MP5Image,1);
   %player.setInventory(MP5Ammo,100);
   //socom
   %player.setInventory(hk_mk23_SOCOMImage,1);
   %player.setInventory(hk_mk23_SOCOMAmmo,100);
   //m16
   %player.setInventory(m16Image,1);
   %player.setInventory(m16Ammo,100);
   // Mount the hk_mk23_SOCOMImage image in the player's hand.
   %player.mountImage(m16Image,0);
  // We set the camera system to run in 3rd person mode around the %player
  
  if (!%morph)
  {
     /*%this.setControlObject(%player);
     %this.camera.setCameraSubject(%player);   
     %this.camera.setThirdPersonMode();
     %this.camera.setThirdPersonOffset("0 -3 3");
     %this.camera.setThirdPersonSnap();
     %this.setCameraObject(%this.camera);*/
    
    //%this.camera.setCameraSubject(%player); 
    //ADVANCED
    %this.setControlObject(%player);
    %this.camera.setPlayerObject(%player);
    %this.camera.setGodViewMode();
    %this.camera.setFollowTerrainMode(false);
    %this.camera.setVerticalFreedomMode(false);
    %this.setCameraObject(%this.camera);
  }
  else
  {
     if (%this.getControlObject() != %this.camera)
     {
       %this.camera.setCameraSubject(%player); 
       %this.setControlObject(%player);
     }
  }
   //%this.advCamera.setPlayerObject(%player);  %this.advCamera.setThirdPersonMode();  %this.advCamera.setFollowTerrainMode(false);  %this.advCamera.setVerticalFreedomMode(false);  %this.setCameraObject(%this.advCamera);
  if (!%morph)
  {
     if (%first_spawn)
       DisplayScreenMessage(%this, "Welcome to the Arcane-FX Demo.");
     else
       DisplayScreenMessage(%this, "Welcome back.");
  }
ServerConnection.setFirstPerson(false); 
  return %player;
}

function BroadcastClearObjectSelection(%match_obj)
{
  %count = ClientGroup.getCount();
  for (%i = 0; %i < %count; %i++)
  {
    %cl = ClientGroup.getObject(%i);
    if( !%cl.isAIControlled() )
    {
      if (isObject(%match_obj))
      {
        %sel_obj = %cl.getSelectedObj();
        if (%sel_obj $= %match_obj)
          %cl.clearSelectedObj();
      }
      else
      {
        %cl.clearSelectedObj();
      }
    }
  }
}

//-----------------------------------------------------------------------------
// Support functions
//-----------------------------------------------------------------------------

function pickSpawnPoint(%groupName) 
{
   if (!isObject(%groupName))
      %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";
}
#44
09/08/2008 (2:29 pm)
You will have to remove some of my weapon adding functions though. in createplayer

remove this
player.setInventory(CrossbowImage,1);   %player.setInventory(CrossbowAmmo,100);   //MP5   %player.setInventory(MP5Image,1);   %player.setInventory(MP5Ammo,100);   //socom   %player.setInventory(hk_mk23_SOCOMImage,1);   %player.setInventory(hk_mk23_SOCOMAmmo,100);   //m16   %player.setInventory(m16Image,1);   %player.setInventory(m16Ammo,100);   // Mount the hk_mk23_SOCOMImage image in the player's hand.   %player.mountImage(m16Image,0);
#45
09/08/2008 (2:38 pm)
Thanks a lott, I really appretiate all the help, got it working perfectly now. Thanks a bunch, there's no way i could have done it without ur help. Now im gunna play around with the cursor bit that terrence gave us.
#46
09/09/2008 (6:11 am)
Ive never used the spell so i dont know. look at the code and see what its doing. its prolly trying to set the camera control or something like that.
#47
09/10/2008 (10:55 am)
Mines already pretty smooth but i think the problem has to with we are using the MoveManager yaw instead of forcing the player to turn towards the cursor. I'm sure it is real close to what we need.

the biggest things i noticed is i can place the cursor behind the player and he stays facing the other director and the projectiles are just a little off from the cursor, they shoot more on the right edge of the cursor instead of the middle.
#48
09/11/2008 (12:54 pm)
Discovered a further camera related bug. When the player dies the game will crash, as I am guessing it is still trying to use the death cam from the afx camera system. I am not sure where to look to find the bit which is doing this, obviously it is the ondeath function in game.cs, but I am not sure if there is anything elsewhere too. I am trying to find out now. I just thought you should know about the bug and I will get back to you if come up with a viable alternative to the afx death cam, I was thinking about maybe using the advanced camera third person mode, or even just keep the camera as it is but invoke the zoom function.
#49
09/11/2008 (2:43 pm)
I have mine to leave it as god mode so when the player dies all that happens is he falls over.
#50
09/11/2008 (3:59 pm)
I changed the GameConnection::onDeath function in game.cs by removing this code:

// clear connections camera
    %this.camera.clearPlayerObject();
    %this.camera.clearTargetObject();
    %this.clearCameraObject();
  //%this.clearCameraObject();
// Switch the client over to the death cam and unhook the player object.
  if (isObject(%this.camera) && isObject(%corpse)) 
  {
    //%this.camera.setMode("Corpse",%corpse);
    %this.camera.setOrbitMode(%corpse, %corpse.getTransform(), 0.5, 4.5, 4.5);
    %this.setControlObject(%this.camera);
    snapAtlasGeometryMorph();
  }

I simply deleted these two sections of code to make it so that it remains in god mode. Deleting the second bit of code, the if statement, on its own (i,e keep the first bit of code) makes it third person.

I still have an issue where if you press space bar to respawn the player, it crashes again, I assume because it has been set to restart the afx camera. Any idea where I would need to look to find what is doing that?
#51
09/11/2008 (4:40 pm)
Also, have you noticed the camera issue where if you go to close to the back of a building , the camera zooms in on the player. I am considering wether this is the best option. I think the alternatives include either altering the camera so that it is directly above, or closer too, the player, that way walls/objects cannot obscure the view. Or maybe look into the possibility of using an alpha fade on any objects obscuring the camera, I know some people have done this in tge, but I am not certain about tgea though.
#52
09/12/2008 (6:18 am)
That is part of advanced camera, basically it does a ray cast from the camera to the player, if there is something in the way it moves the camera so you can always see the player. You can just remove the raycast if you want.
#53
09/12/2008 (7:30 am)
-
#54
09/15/2008 (6:22 am)
Nope. i've been concentrating on art.
Page«First 1 2 3 Next»