Map scripting

From WolfWiki
Revision as of 17:12, 12 November 2005 by WeblionX (Talk | contribs) (Cleaned code, Do both customalliesimage and customalliedimage work?)

Jump to: navigation, search

General information

The ETPro team has improved and changed the scripting system to a quite big extent. This article presents some of the new ETPro map scripting features.

Scripting Examples by duke'ku

Here I'll show a few examples of the new scripting allowed in ETPro, and attempt to explain what exactly it's doing. First off, I'll start with a simple example, where a model (in this case, a dinghy) is inserted into the map.

create
{
   scriptname "dinghy1"
   origin "2650 600 100"
   classname "misc_gamemodel"
   modelscale 1
   contents 1
   mins "-90 -90 -25"
   maxs "90 90 25"
   clipmask 1
      model "models/mapobjects/dinghy_sd/dinghy.md3"   
}

This isn't exactly the cleanest example of scripting (mainly due to my lackluster job of clipping the model off,) but what it produces is this: http://games.theteamkillers.net/rtcw/dinghy/2004-01-14-234844-battery.jpg

Now, to break down how it works. The create{ } command will place an entity into the map, at the spot specified by the "origin" key. The scriptname specifies the name that the entity will have in the map, and it is what seperates it from other entities in the map (which can cause quite a few problems).

create
{
   scriptname "dinghy1"
   origin "2650 600 100"
}

The code above will do nothing, it creates an entity (not even of a specified type, it will do nothing) and places into the map at 2650,600,100. To find your position on a map to place an entity (you'll need to find an origin for almost every entity), use the command "/viewpos".

create
{
   scriptname "dinghy1"
   origin "2650 600 100"
   classname "misc_gamemodel"
}

Now, the code has advanced a bit further and the entity now has a specified type, misc_gamemodel. A misc_gamemodel is a model placed into the map during load (compared to a misc_model, which are permanently static objects that get compiled into the map at compile). Misc_gamemodels can be used for almost anything, from walls (although this would be a terrible way of making a map) to moving tanks (all of the vehicles, construction boxes, command posts, etc. in game are all misc_gamemodels), but in this script it's just used for placing a model (provided with the ET mapping tools, available at http://www.qeradiant.com).

create
{
   scriptname "dinghy1"
   origin "2650 600 100"
   classname "misc_gamemodel"
   modelscale 1
   contents 1
}

Now, the model has a defined scale, 1. A scale of .5 would cause it to be half of the size of the model in the file that will be referenced, and a scale of 2 would cause it to be twice the size. Most flags that are used on an entity can be found in the entities.def file that is provided with the mapping tools.

create
{
   scriptname "dinghy1"
   origin "2650 600 100"
   classname "misc_gamemodel"
   modelscale 1
   contents 1
   mins "-90 -90 -25"
   maxs "90 90 25"
   clipmask 1
   model "models/mapobjects/dinghy_sd/dinghy.md3"   
}

Now, for the clipping. The contents flag specifies the type of surfaceflag that the entity will be. Surfaceflags that are defined in the ET source (found in src/game/surfaceflags.h, if you're interested) are listed here. The mins and maxs specify how far out from the origin of the model (in each direction) the clipping will extend to. The coordinates on this model aren't accurate, but they get the job done.

This was a very basic example of scripting, and now I'll be listing some more advanced examples of scripting.

Example 1: Battery's Back Door and Dynamite

//bani
create
{
   scriptName "backdoor"
   classname "func_explosive"
   targetname "backdoor"
   origin "4608 -4594 1024"
   mins "-63 -10 0"
   maxs "63 10 128"
   spawnflags 1   // AXIS_OBJECTIVE(1)
   eflags 65536   // EF_FAKEBMODEL
   svflags 1   // SVF_NOCLIENT
}

//bani
create
{
   scriptName "backdoor_obj"
   classname "trigger_objective_info"
   targetname "backdoor_obj"
   target "backdoor"
   origin "4608 -4601 1024"
   mins "-95 -85 0"
   maxs "95 85 128"
   spawnflags 17   // AXIS_OBJECTIVE(1) | CUSTOMIMAGE
   track "the Back Door"
   shortname "Back Door"
   customaxisimage "gfx/limbo/cm_radar_maindoor"
}

//bani - bug fixes
create
{
   scriptName "bugfix1"
   classname "func_fakebrush"
   origin "3632 -4313 881"
   contents 65536  // CONTENTS_PLAYERCLIP
   mins "-40 -1 -20"
   maxs "40 1 10"
}

Example 2: Fueldump and Spawning at the Command Post

create
{
   scriptName "fueldumphq_obj"
   classname "team_WOLF_objective"
   targetname "fueldumphq_obj"
   origin "-10853 -2036 6"   // z = CC_FILTER_ALLIES(2) | CC_FILTER_SPAWNS(4)
   spawnflags 2   // TEAM_ALLIES(2)
}

create
{
   scriptName "fueldumphq_spawn1"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "11072 -2448 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn2"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10995 -2448 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn3"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10918 -2448 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn4"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10841 -2448 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn5"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "11072 -2288 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn6"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10995 -2288 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{      
   scriptName "fueldumphq_spawn7"      
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10918 -2288 512"
   spawnflags 2   // TEAM_ALLIES
}

create
{
   scriptName "fueldumphq_spawn8"
   classname "team_CTF_bluespawn"
   targetname "fueldumphq_spawn"
   origin "-10841 -2288 512"
   spawnflags 2   // TEAM_ALLIES
}

Hopefully you'll be able to understand what each of those flags are doing. If you can't figure it out, see if you can figure it out from the entities.def file (from [1], this is not the original ET entities.def file but everything in it should work - it contains new things that weren't included with the stock def), or come and bug the ETPro team (|Rain|, [av]bani, zinx, fretn, s2ikkyo) on irc.freenode.net, #etpro.

Contents Flags

  • SOLID 1
  • LIGHTGRID 4•
  • LAVA 8
  • SLIME 16
  • WATER 32
  • FOG 64
  • MISSILECLIP 128
  • ITEM 256
  • MOVER 16384
  • AREAPORTAL 32768•
  • PLAYERCLIP 65536
  • MONSTERCLIP 131072°
  • TELEPORTER 262144
  • JUMPPAD 524288
  • CLUSTERPORTAL 1048576•
  • DONOTENTER 2097152°
  • DONOTENTER_LARGE 4194304°
  • ORIGIN 16777216
  • BODY 33554432•
  • CORPSE 67108864•
  • DETAIL 134217728•
  • STRUCTURAL 268435456•
  • TRANSLUCENT 536870912
  • TRIGGER 1073741824
  • NODROP 2147483648

Not all of these surfaceflags will work, but the ones you will want to use should work. If you've tested something and it doesn't work properly, send an email to dukeku AT theteamkillers DOT net and I'll fix it here.

° These, as far as I know, are bot only commands - they will have no effect on other players.
• These are flags that should not be used in a script, they're either reserved for strict-in game usage that doesn't relate to something that you would do in a script such as this, or are reserved for entities that are compiled into the map and have absolutely no use in game.

Originally posted in the ETPro forums by duke'ku.

Scripting Examples by Rain

Additionally, players may modify keys on existing entities with the set command.

Example 1: Oasis Axis Garrison spawn marker fix

Here are a couple of examples from the oasis map script (etpro/maps/oasis.script):

axis_garrison_wobj
{
        spawn
        {
                set
                {
                        origin "7089 4852 -415"
                }
        }
}

This changes the position of the spawn marker for the Axis garrison to (7089, 4852, -415). (This was done to correct player spawn location after setautospawn usage was fixed.)

Example 2: Oasis caves water fix

Here's another example:

water_tunnel
{
        spawn
        {
                // rain - these are put into the world as CONTENTS_SOLID,
                // which is a Bad Thing if WolfReviveBBox gets called
                // while we're in the water
                wait 100
                set
                {
                        contents 32 // CONTENTS_WATER
                        clipmask 32 // CONTENTS_WATER
                }
        }
        [...]

As described by the comments, this fixes the problem that sometimes caused players to be pushed around uncontrollably while underwater in the tunnel.

Both create and set recognize some keys that can't normally be used while mapping. Normally, most of these are computed automatically (often at map compile time); however, there are some cases when the compiled value is unusable, and there are some cases where you might want to set these values when spawning a new entity.

Additional supported keys

The additional keys supported are:

KeyDescription
minsA point describing the location of the lower corner of the bounding box. (ent->r.mins)
maxsA point describing the location of the upper corner of the bounding box. (ent->r.maxs)
contentsContents flags - description above (ent->r.contents)
svflagsServer flags (ent->r.svFlags)
clipmaskBrush content types to collide with. (ent->clipmask)
count2entity-specific (ent->count2)
eflagsEntity flags (ent->s.eFlags)
pos_trTypePosition trajectory type (ent->s.pos.trType)
pos_trDeltaPosition trajectory delta Δ (ent->s.pos.trType)
apos_trTypeAngle trajectory type (ent->s.apos.trType)
pos_trDeltaAngle trajectory delta Δ (ent->s.apos.trType)
classname_nospawnChanges the class name, but doesn't re-spawn the entity. (ent->classname)
customaxisimageCustom command map image for the Axis team
customalliesimage
customalliedimage
Custom command map image for the Allied team
allowteamsTeams allowed to use an entity (ent->allowteams)

(You may wish to refer to the ET SDK for additional information.)

The func_fakebrush entity

Finally, ET Pro offers the func_fakebrush entity (also available by ORing EF_FAKEBMODEL (65536 or 0x10000) to eFlags), which allows the limited ability to spawn brush entities. The fake model must be a hexahedron, defined by mins and maxs, and will not work for all brush entity types.

Originally posted in the ETPro forums by Rain.