Menu

Wiki usage

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
Edit Sidebar
Main > SpawnNewThingsIntoStockMapsWithScripting

Spawn new things into stock maps with only scripting

Today we are going to make the Fire a Flak88 tutorial again, but this time by pure scripting, no mapping involved at all. You can put this in "The Hunt" if you want. Or even better: you could script away the existing Flak88:s in the hunt and replace it with one that fires as soon as someone uses the trigger to set the bomb. They will ruin their pants for sure (:twisted:).

If you like to mess with existing maps, like the ones shipped with MOH:AA or ones that others made that you don't have the *.map file for: you can still add a usable Flak88 ( Or any other model you have, standard or self made ). The scripting parts for the Flak88 is exactly the same as in the Fire a Flak88 tutorial. But setting up a Flak88 turret and a trigger is done like this:


 // ARCHITECTURE: Bjarne Grönnevik
 // SCRIPTING: Bjarne Grönnevik
 spawn_a_flak88:
   // Spawn a script model and give it a targetname
   local.flak = spawn script_model "targetname" "flak88"
   // Set the model to be drawn/used
   local.flak model "statweapons/flak88turret.tik"
   // Set where it should be
   local.flak.origin = ( -100.0 .0 0.0 )
   // Set where it should point at
   local.flak.angles = ( 0.0 0.0 0.0 )
   // Set how big it should be
   local.flak.scale = 1.0
   // Create the trigger and give it a targetname
   local.trigger = spawn trigger_use "setthread" "fire_flak88"
   // Set where it should be
   local.trigger.origin = ( 0.0 100.0 0.0 )
   // Set the size of it
   local.trigger setsize ( -50 -50 -50 ) ( 50 50 50 )
 end

And to initiate the spawning of the Flak88, write this in the main method ( after level waittill prespawn )


 thread spawn_a_flak88

Done!

How to figure out the location (origin) you need

You tell the game where to place an object by specifying its 'origin' as a set of three co-ordinates (X, Y, Z). To find out the correct origin to use for the object you're spawning, the easiest method is to stand in the location you wish to have the object in and then use the coord command in the console. This will show you the coordinates of your current location, as well as the 'angles' which specify the direction in which you are facing.

Another method for finding out the origin of a particular location is to use Scorpio Midget's 3D BSP Viewer, also known as "MOHAA Tools", to generate a .map file from the .bsp. While the .map file is not suitable for re-compilation, you shouldn't have any trouble loading it into MOHRadiant (although it's possible some brushes could be lost and hence some parts of the map might not be visible). You can then place whatever objects you wish via the usual methods, then check what their origins are by looking in the entity inspector, and copy these origins into your script.

Also note that you can perform mathematical operations on the origins - they are vectors. If, for example, there is an existing entity in the map called "foo", and you wish to spawn an object above it, you could spawn the object, setting "local.bar" to point to the spawned object, and then set the spawned entity's origin like this:


 local.bar.origin = $foo.origin + ( 0 0 100)

which will place the spawned entity 100 units (about the height of a player) above "foo".

Some scripting tips

Tired of shutting down MOH:AA, editing the cript and then restarting MOH:AA each time to make a tiny script edit? Use the "editscript" and "restart" commands in the console.

  1. use editscript in the console to get a window ( in the game ) where you can edit the level script of the currenlly loaded map.
  2. Edit the script.
  3. Save ( CTRL+s ) the script.
  4. use restart in the console to restart the map using the new version of the script.

You can also use the ~np~Alt-Tab~/np~ key (under Windows, or similar on other operating systems) to an editor like Notepad to modify your map script.

Good luck now!

Good-bye!

That's all you need to know for now... I bet your evil brain is already thinking about how to combine this simple stuff with other simple stuff into a really complex thing that will blow up players in a completely new way. Remember, make it fun... fun is better than cool and complex. Ask any player.

Thanx to Nemesis, for teaching me how to make a Flak88 fire at all...

Recent Changes Printable View Page History Edit Page [Attributes] [Printable View] [WikiHelp]
Page last modified on February 02, 2005, at 11:53 PM