Author Topic: Make level endings with a GUI  (Read 892 times)

0 Members and 1 Guest are viewing this topic.

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
Make level endings with a GUI
« on: July 02, 2014, 01:04:27 AM »
Original text by solarsplace (Arx - End of Sun) on  Doom3World with modifications by me (grammatical corrections mostly)


Here are the exact steps needed in order to:

- ingame, walk up to a GUI, set focus on the GUI, click a button and load another level.

This assumes that you know how to get a simple GUI made and into your map.

- for this you need two maps, replace yourmapname1.map and yourmapname2.map with the real names of your maps.

1 - Create a simple GUI to change the level. You can use the following code as a base if you want. This is a very simple GUI with a button on it. when clicked, the "onAction" code triggers a trigger_once entity placed in the yourmapname1.map called "trigger_once_1"

Code: [Select]

windowDef Desktop
{
   rect 0,0,640,480
     

    windowDef button1
   {
   rect 270,170,100,100
   visible 1

   backcolor 1,0,0,1
   forecolor 1,1,1,1
   textscale 0.1
   textalign 1
   text  "End Level"
   onAction{
         set "cmd" "activate trigger_once_1" ;
   }
   }
}



Save this as change_level.gui or whatever you like.

2 - Create a trigger_once entity in the map and make sure it is called "trigger_once_1" add a key val pair of "call" "next_map"

3 - In the same folder as yourmapname1.map create a text file called yourmapname1.script  and put the following code in it:

Code: [Select]

void next_map()
{
   sys.print ("\n Now ending this level\n"); //will NOT show this in the console if the next code is successful.
   sys.trigger ($target_endlevel_1);

4 - Create a target_endlevel entity in yourmapname1.map and call it "target_endlevel1" give it a key val pair of "nextMap" "yourmapname2.map" and thats it.


There may very well be a way to do it without using a script file, but using them makes life easier, it permits to write to the console and debug our code and see where it might be going wrong.   

Zombie

  • Guest
Re: Make level endings with a GUI
« Reply #1 on: July 02, 2014, 02:28:26 AM »
Nice tutorial!

But I would make one modification on there.

Instead of:

Code: [Select]
   onAction{
         set "cmd" "activate trigger_once_1" ;
   }

Use:

Code: [Select]
onAction {
set "cmd" "activate" ;

}

And then target the func_static where the GUI lives to the endlevel entity

This is much cleaner than specifying a hard fixed entity in the GUI to target.

It also allows reusability in the future.

I hope this helps!