Friday, 8 February 2013

CE3 Entities 101

Here's some information you may all find useful.

It looks like an awful lot of stuff is happening in Lua scripts rather then in the C++ code. This includes spawning of objects and loading meshes for instance. I guess it's a good thing since scripters can change many of the game parameters without changing the code.

File Structure


Every entity is basically split between two files: .ent file in Game/Entities/... and .lua file in Game/Scripts. Generally the Game folder is where you want to be looking for pretty much anything assets related. The files are stored in .pak archives which can be uncompressed with a 7-zip or WinRAR like any regular archive. I'd recommend uncompressing these archives and having a look around. Also extracted files take priority over those in the archives so you don't have to put modified files back into .pak files.


Modifying Entity Parameters


The .ent file only contains the location of the .lua file which contains entity logic and some parameters including model and animation graph files. For example in Game/Scripts/Entities/actor/player.lua you'll find something like this:

Player = {
 AnimationGraph = "HumanMaleFullBody.xml",
 UpperBodyGraph = "HumanMaleUpperBody.xml",
 type = "Player",
 foreignCollisionDamageMult = 0.1,  vehicleCollisionDamageMult = 7.5,
  Properties =
 {   -- AI-related properties
  soclasses_SmartObjectClass = "Player",
  groupid = 0,
  esFaction = "Players",
  commrange = 40; -- Luciano - added to use SIGNALFILTER_GROUPONLY
  -- AI-related properties over
  voiceType = "player",
  aicharacter_character = "Player",
  Perception =
  {
   --how visible am I
   camoScale = 1,
   --movement related parameters
   velBase = 1,
   velScale = .03,
   --ranges      sightrange = 50,
  } ,
  --
  fileModel = "Objects/characters/SDK_player/SDK_Player.cdf",
  clientFileModel = "Objects/characters/SDK_player/SDK_Player.cdf",
  fpItemHandsModel = "Objects/Weapons/Agent_fp/Agent_fp_Global.chr",
  objFrozenModel= "Objects/characters/SDK_player/SDK_Player.cdf",

So you can replace the player model simply by editing parts of this script.

For the minions I think we can use Grunt entity with some modifications which is going to be much easier then creating a new one from scratch. The relevant file is under Game/Scripts/entities/ai/grunt_x.lua.

Adding New Entities


If you wish to create new entity (for example something to put on the map) simply create a new .ent (i.e. Game/Entities/MyEntity.ent) file which contains only this line:
<Entity
Name="MyEnity"
Script="Scripts/Entities/Others/MyEnity.lua"
/>
And a corresponding .lua file which implements the following methods:
-- Class MyEnity
MyEntity = {
  Editor =
  {
    Icon = "MyIcon.bmp" -- icon for the editor (stock icons are under Editor/ObjectIcons)
  },
  Properties =
  {
    object_3DModel = "path/to/MyModel.cgf",
  },
}
function MyEntity:OnInit()
  self:OnReset()
end
function MyEntity:OnReset()
  --this will set the selected 3D Model on the entity
  if (self.Properties.object_MyModel ~= "") then
    self:LoadObject(0, self.Properties.object_3DModel);
  end
end
Now if you open the editor you'll be able to place your entity on the map from the Entities/Others menu.

2 comments: