How To Cog - Chapter 1.4 - Templates

Templates are JK's blueprints for creating objects in the game. Every object you see in the game (and many you don't) is created from a template stored in either the level's .jkl file or the static.jkl. Using a cog, we can create things based on these templates in a game. Here's what the (abbreviated) template section of the first Narshaada level looks like:

##### Templates information ####
Section: TEMPLATES

World templates 210

#Name:           Based On:        Params:
_actor           none             orient=(0.000000/0.000000/0.000000) type=actor collide=1 move=physics thingflags=0x20000000 mass=150.000000 physflags=0x4a4f maxrotvel=200.000000 maxvel=1.000000 health=40.00 maxhealth=40.00 maxrotthrust=180.00 jumpspeed=1.50 eyeoffset=(0.000000/0.000000/0.037000) minheadpitch=-80.00 maxheadpitch=80.00 lightoffset=(0.000000/0.070000/0.040000) lightintensity=0.80 
walkplayer       _actor           type=player thingflags=0x20000401 light=0.200000 model3d=ky.3do size=0.065000 movesize=0.065000 puppet=ky.pup soundclass=ky.snd cog=kyle.cog surfdrag=3.000000 airdrag=0.500000 staticdrag=0.300000 health=100.00 maxhealth=100.00 maxthrust=2.00 typeflags=0x1 error=0.50 fov=0.71 chance=1.00 
_decor           none             orient=(0.000000/0.000000/0.000000) type=cog collide=1 move=path 
_structure       _decor           collide=3 thingflags=0x8 
_walkstruct      _structure       thingflags=0x400048 
2x8catwalk       _walkstruct      model3d=c2x8.3do size=0.412822 movesize=0.412822 
4x4elev          _walkstruct      model3d=e4x4.3do size=0.336311 movesize=0.336311 soundclass=med_elev.snd 
_humanactor      _actor           size=0.065000 movesize=0.065000 surfdrag=3.000000 airdrag=0.500000 maxvel=0.500000 maxthrust=0.80 typeflags=0x80000 
_weapon          none             orient=(0.000000/0.000000/0.000000) type=weapon collide=1 move=physics thingflags=0x20000000 timer=10.000000 mass=5.000000 physflags=0x200 maxrotvel=90.000000 damageclass=0x2 typeflags=0x1 
_explosion       none             orient=(0.000000/0.000000/0.000000) type=explosion typeflags=0x1 damageclass=0x4 
+laserhit        _explosion       thingflags=0x1 light=0.200000 timer=0.500000 sprite=bryx.spr soundclass=exp_laserhit.snd typeflags=0x33 blasttime=0.300000 maxlight=0.400000 
+smflash         _explosion       thingflags=0x1 light=0.400000 timer=0.100000 typeflags=0x0 
+laserfleshhit   +laserhit        soundclass=exp_fleshy.snd 
+bryarbolt       _weapon          thingflags=0x20000001 light=0.400000 model3d=bry0.3do size=0.001000 movesize=0.001000 soundclass=bry.snd creatething=+smflash maxrotvel=0.000000 vel=(0.000000/4.000000/0.000000) explode=+laserhit fleshhit=+laserfleshhit damage=30.000000 mindamage=10.000000 typeflags=0x20440d rate=15.000000 
+stlaser         +bryarbolt       model3d=str0.3do soundclass=stlaser.snd vel=(0.000000/6.000000/0.000000) rate=10.000000 
+elaser          +stlaser         vel=(0.000000/4.000000/0.000000) damage=12.000000 mindamage=5.000000 
reeyeesgun       _humanactor      thingflags=0x20000400 model3d=rystr.3do size=0.072900 movesize=0.072900 puppet=rystr.pup soundclass=rystr.snd cog=actor_rb.cog weapon=+elaser health=50.00 maxhealth=50.00 maxthrust=0.90 maxrotthrust=70.00 jumpspeed=1.20 typeflags=0x1 fireoffset=(0.014700/0.080000/0.034000) aiclass=rydefault.ai 
2x3door          _structure       model3d=d2x3.3do size=0.180710 movesize=0.180710 soundclass=sm_door.snd 
3x10catwalk      _walkstruct      model3d=c3x10.3do size=0.522160 movesize=0.522160 
crate4_3         _walkstruct      model3d=crt4-3.3do size=0.173196 movesize=0.173196 
crane            _decor           thingflags=0x400 model3d=cran.3do size=0.075000 movesize=0.075000 cog=xcrane.cog 
funicular        _walkstruct      model3d=01func.3do size=0.369225 movesize=0.369225 soundclass=funicular.snd 
end
################################

Most of the templates stay the same from one JKL to another. That's because most of the objects created are weapons, projectiles, powerups, standard actors, etc. These things will be in all of the original levels and most custom ones.

All templates have a name, a base template, and a list of arguments. A template's name is what cogs will use to refer to it in their symbols section. Some names have an underscore before them to signify that they're just base templates. JK doesn't care if there's an underscore there or not, it's more of a comment. The plus sign before some of the names usually means that the template is a projectile, explosion, or particle cloud. Like the underscore, it's more comment than syntax.

After the template's name comes their base (parent) template. All of the parent template's properties will be given to the child template. But if the child template has a property that the parent also has, the child's property value will be used instead. Any template can be a base template, but it must come before the template that uses it - you cannot use a parent template that comes after its child template in the list. If no parent template is needed, you can write none instead of a template name.

Next comes the list of arguments. These are all the properties that the template has specific values for (in some cases there are default values for properties not defined). Remember that child templates will inherit properties they don't have defined from their parents (parent templates may have a parent of their own). The "cog" property tells JK that the template has a cog assigned to it. This cog should come from the cogscripts list.

From a cog, you will be able to retrieve the value of and change most of these properties once there is an actual thing created from the template. You cannot change a template from cog, only the thing created from it. Let's say you want to place a stormtrooper in your level. Although just about everybody uses a level editor to do this, you can do it manually by adding an entry to the things section in your .jkl file. This entry will consist of the template name and a position to create the thing at.

The template's cog is storm.cog. As soon as the level loads and your stormtrooper is created, storm.cog will begin receiveing events from its stormtrooper. Because this is a class cog, every stormtrooper in the level will be sending events to this one cog. The first event storm.cog will receive is created. This tells the cog that your stormtrooper has been created in the level.


Previous: JK Levels Up: How To Cog Next: Inventory
  • Create:
This page was last modified 14:05, 14 April 2006.   This page has been accessed 1,268 times.