Game Development Community

Flag Models and code

by Harold "LabRat" Brown · 04/03/2002 (1:40 pm) · 3 comments

OK I finished up the basic flag information for the 3 "flags" I was making for the Realm Wars demo.

Right now you can add a flag to a mission, people can pick them up and when you die the flag drops where you were killed.

Everything is packaged into a zip that contains the flag.cs file, a readme.txt with information on what other files need to be changed and the 3 flag .dts files, the texture files I used and the Milkshape 3D files for all 3 flags.
realmwars.feylab.com/downloads/rw_flags.zip

[Code Snippit - flag.cs]
$flagslot = 2;

datablock ShapeBaseImageData(Flag1Image)
{
   shapeFile = "rw/data/shapes/flag/flag1.dts";
   item = Flag1;
   mountPoint = 2;
   offset = "0 0 0";

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";
   cloakable = false;
};

datablock ItemData(Flag1)
{
   category = "Flag";
   className = "Flag";
   image = Flag1Image;
   shapefile = "~/data/shapes/flag/flag1.dts";
   mass = 55;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 3;
   pickUpName = "a flag";
   computeCRC = true;

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";

   isInvincible = true;
};

datablock ShapeBaseImageData(Flag2Image)
{
   shapeFile = "~/data/shapes/flag/flag2.dts";
   item = Flag2;
   mountPoint = 2;
   offset = "0 0 0";

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";
   cloakable = false;
};

datablock ItemData(Flag2)
{
   category = "Flag";
   className = "Flag";
   image = Flag2Image;
   shapefile = "~/data/shapes/flag/flag2.dts";
   mass = 55;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 3;
   pickUpName = "a flag";
   computeCRC = true;

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";

   isInvincible = true;
};

datablock ShapeBaseImageData(Flag3Image)
{
   shapeFile = "~/data/shapes/flag/sphere.dts";
   item = Flag3;
   mountPoint = 2;
   offset = "0 0 0";

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";
   cloakable = false;
};

datablock ItemData(Flag3)
{
   category = "Flag";
   className = "Flag";
   image = Flag3Image;
   shapefile = "~/data/shapes/flag/sphere.dts";
   mass = 55;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 3;
   pickUpName = "a flag";
   computeCRC = true;

   lightType = "PulsingLight";
   lightColor = "0.5 0.5 0.5 1.0";
   lightTime = "1000";
   lightRadius = "3";

   isInvincible = true;

};

function Flag::onPickup(%this, %flag, %player, %amount)
{
   if (%player.getClassName() $= "Player" && %player.getMountedImage($FlagSlot) == 0) {
    	serverPlay3D(WeaponPickupSound,%flag.getTransform());
    	%player.incInventory(%this,1);
     	%player.mountImage(%this.image, $FlagSlot);
     	%flag.delete();
   }
}


function newflag(%flag,%player)
{
	echo("newflag" SPC %flag SPC %player);
	%obj = new Item() {
      dataBlock = %flag;
      static = false;
      rotate = false;
   };
   
   %obj.position=%player.position;
   MissionCleanup.add(%obj);
}
[end code snippit - flag.cs]

[code snippit - readme.txt]
For the flags to work correctly you will also need to add the following:

In game.cs:

After the following:
exec("./player.cs");
       exec("./chimneyfire.cs");
       exec("./aiPlayer.cs");

Add:



In player.cs:
exec("./flag.cs");
At the top of the Armor::onDisabled function add:
if ( %obj.getMountedImage($FlagSlot) != 0) {
   	newflag(%obj.getMountedImage($FlagSlot).item,%obj);
   	%obj.unmountImage($FlagSlot);
   	}


You must set your player maxInv for the flags:

maxInv[Flag1] = 1;
maxInv[Flag2] = 1;
maxInv[Flag3] = 1;

in the datablock PlayerData(LightMaleHumanArmor)

Once you have done that start up your Realm Wars open the mission you wish to add a map to. Go into the editer and select the Editor Creator. Pick a flag from the list and add it to your map. Save, close the game and restart.

[end code snippit - readme.txt]

#1
04/03/2002 (3:31 pm)
If you get the realm wars Team assault build 5, Ive put those flags in, in a mission, and put the code in to have it capture, then respawn for a capture the flag style game (right now you dont win on capture, you just get 50 pts).

http://phil.23v.com/builds/RWTA-build5.zip

Phil.
#2
04/03/2002 (4:04 pm)
is that meshed with the team objective stuff, phil?
#3
01/06/2008 (1:44 pm)
Awsome, old resource, but still VERY helpful. I would like to tell everyone to make one change though to your flag.cs file.

Under "datablock ShapeBaseImageData(Flag1Image)" change shapeFile = "rw/data/shapes/flag/flag1.dts"; to shapeFile = "~/data/shapes/flag/flag1.dts";

This will allow you to "see" the flag on your back. I'm sure many of you noticed this though. There's a problem when you enable this to mount. If you throw or drop the flag, it isn't unmounted. Because of this, you aren't able to pick it back up! Add this above "function newflag(%flag,%player)":

function Flag::onInventory(%this,%obj,%amount)
{
// Makes sure no flags are mounted if you don't have any
// left in your inventory.
if (!%amount && (%slot = %obj.getMountSlot(%this.image)) != -1)
%obj.unmountImage(%slot);
}

That will unmount any flag from flagslot when it is thrown. This will allow you to pick it back up again.