In-game Map Entities

From The DarkMod Wiki
Revision as of 02:34, 1 November 2020 by Geep (talk | contribs) (Add 2 sentences saying why alpha channel and how differs from Startpack method, with ref)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

originally written by grayman

Create an "atdm:map_of" entity as if you intend to place it in the player's inventory at the start of the mission. Then turn off the "inv_map_start" spawnarg.

For example, create one with these spawnargs:

"name" "MapOfSewer"
"inv_map_start" "0"
"inv_name" "Sewer Map"
"gui" "guis/map_of_sewer.gui"

Create a gui file called "map_of_sewer.gui" with the following contents, and put it into your guis directory:

windowDef Desktop
{
       rect 0,0,640,480
       nocursor 1
 
       windowDef background_map
       {
               rect 64,48, 512, 384
               background "guis/assets/game_maps/map_of_sewer"
               visible 1
       }
}

Create the image you want displayed (your map) in "map_of_sewer.tga", with an alpha channel. (The alpha channel supports a map with a ragged edge. Unlike the method in Startpack_Mappers'_Guide#Adding_an_In-game_Map_to_your_FM, here, a custom .mtr or .def file is unneeded for such support.)

Put that image into guis/assets/game_maps/.

Retrieve a copy of guis/assets/game_maps/map_of_icon.tga from startmap.pk4 and place it into guis/assets/game_maps/.

Create an "atdm:static_custom_item" entity with these spawnargs:

"name" "SewerMap"
"inv_map_start" "0"
"model" "models/darkmod/readables/scroll_rolled_up.lwo" (or use whatever model you prefer)
"sr_class_1" "R"
"sr_effect_1_1" "effect_script"
"sr_effect_1_1_arg1" "FrobSewerMap"
"sr_state_1" "1"
"sr_type_1" "STIM_FROB"

The "sr_*" spawnargs describe how your custom entity will react to a frob stim.

Place the following code inside your *.script file:

void FrobSewerMap()
{
       // Put MapOfSewer into inventory, replacing the frobbed scroll named SewerMap.
       // MapOfSewer shows the sewer map when used while in inventory.
       // Make sure HUD shows the map icon.

       $player1.replaceInvItem($SewerMap,$MapOfSewer);
       $player1.setCurInvItem("Sewer Map"); // provide inventory name, not item name
}

void main() // this might already be there; skip if so
{
}

When you play the mission, frobbing the custom item that looks like a scroll will cause the script to run, which replaces the custom item in your inventory with the "atdm:map_of" entity you created at the top of this note.

From here on, it's as if the game gave you the map at mission start. Hit your "use" key and your map should appear on the screen.