Steal and Deliver Docs

In this tutorial i will show you how to make a map in which you can steal and
deliver docs. The result is available as a prefab prefab_steal_and_deliver_docs

You should have read the following tutorials before starting this:

– How stuff works
– First mapscript

No must, however. More experienced users just wanting a refresher do not want to
read these. For beginners it is recommended.

Some notes before starting: i am not trying to be general with this tutorial.
There are many many ways to do it. I just show you one way. For example: the
mission is on allies side to steal and deliver, not axis. Do changes wherever
you please, or ask a question and i will add it to the FAQs.

The preparations, as always, consist of preparing entities in Radiant and
writing the actual mapscript.

In Radiant, you need:

– team_CTF_redflag -> this is the stuff you steal and deliver
– trigger_flagonly_multiple -> this is your delivery point
– 2 misc_gamemodels -> to visually represent the delivery status

team_CTF_redflag
———————

This entity is for allies. It will be what you steal and deliver.

Here are my key-val pairs for this entity:

{
“classname” “team_CTF_redflag”
“origin” “0 994 316”
“model” “models/multiplayer/secretdocs/secretdocs.md3”
“message” “the docs”
“scriptname” “docs”
“scale” “0.5”
“angle” “270”
}

The important parts are the scriptname (to link this entity to the script), the
message (which is the name of the object ingame), and the model path (needed to
display the model).

trigger_flagonly_multiple
———————

This entity is your delivery point.

Here are my key-val pairs for this entity:

{
“classname” “trigger_flagonly_multiple”
“spawnflags” “1”
}

Here the only important thing is the spawnflags set to 1, which means it will
allow only red_flags to be delivered. Red flags are flags carried by allies.

2 misc_gamemodels
———————

We now already have a basic framework. It would work, when we had a mapscript
for it. But this is probably not what you want. You will see that without the
following two entities and integrating them into the script you will not have
a nice visual representation of the whole process of stealing and delivering.
You want to see exactly where you deliver, and what you deliver. So you
probably want a model representing the delivery model in a transulcent way.
Then, when someone delivers the objective, you want the transulcent model to
disappear, and the complete model appear.

Here is how this goes, it requires basically just preparations here, and a
setstate command at the right places in the script.

So to make it short, on your delivery point add two misc_gamemodels, and place
them exactly on the same origin.

Here are my key-val pairs for these entities:

{
“scriptname” “docs_trans”
“targetname” “docs_trans”
“model” “models/multiplayer/secretdocs/secretdocs_trans_red.md3”
“origin” “0 -988 288”
“classname” “misc_gamemodel”
}

{
“scriptname” “docs_full”
“targetname” “docs_full”
“classname” “misc_gamemodel”
“origin” “0 -988 288”
“model” “models/multiplayer/secretdocs/secretdocs.md3”
}

Here is something you should be interested in: the targetname. The scriptname
and the targetname are very similar. The only difference is that the scriptname
will connect this entity to the script (it goes from the map inside the script),
while the targetname let’s you speak to an entity from inside the script (it
goes from the script to the map). So the targetname is just a name for the
entity. Mostly people just give the scriptname and the targetname the same name.

The mapscript
———————

game_manager
{
spawn
{
wait 200
wm_allied_respawntime 1
wm_axis_respawntime 1
wm_set_round_timelimit 20
wm_setwinner 0
}

trigger endgame
{
wm_announce “Allies win”
wait 3000
wm_setwinner 1
wm_endround
}
}

docs
{
spawn
{
}

trigger stolen
{
wm_announce “Documents stolen”
}

trigger dropped
{
wm_announce “Documents dropped”
}

trigger returned
{
wm_announce “Documents returned”
}

trigger captured
{
wm_announce “Documents captured”
setstate docs_trans invisible
setstate docs_full default
trigger game_manager endgame
}
}

docs_full
{
spawn
{
wait 200
setstate docs_full invisible
}
}

docs_trans
{
spawn
{
wait 200
setstate docs_trans default
}
}

By now, you should have no problem understanding how the script gets reached.
You already know that there are scriptnames for entities, and some code sections
in the mapscript are specially made for them. In this mapscript this is:
game_manager, docs, docs_full, docs_trans.

game_manager
———————

The game_manager contains the usual. The only thing new to you should be this
section here:

trigger endgame
{
wm_announce “Allies win”
wait 3000
wm_setwinner 1
wm_endround
}

This is a trigger section. Not exactly an event, but something you define
yourself. We called this trigger section “endgame”. When you look at the code
inside: this will print “Allies win”, then wait for 3 seconds, then set the
winner of the round, and then actually end the round. This trigger section will
get triggered in the captured event of the docs entity.

docs
———————

The docs sections has 5 events: spawn, trigger stolen, trigger dropped,
trigger returned, trigger captured. Pretty self-explanatory. In the trigger
captured we do the actual interesting stuff.

trigger captured
{
wm_announce “Documents captured”
setstate docs_trans invisible
setstate docs_full default
trigger game_manager endgame
}

We use the setstate command here. You can setstate an entity in the following
states: invisible, underconstruction and default. Here we just set the
targetname of docs_tran to invisible and the targetname of docs_full to default.
We swap the visual state, so to speak. Then we make something like a function
call, which is we say “trigger”, then name to which entity section it should
jump (game_manager here), and inside this game_manager section to which place
(here endgame). So this will jump to this place and continue executing there.

docs_trans and docs_full
———————

Here we just setstate the entities in the spawn event.

That’s it, enjoy.