Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
2009XboxLiveKid

Basic helpfull scripts

Recommended Posts

Hi, so I know next to nothing on Scripting, but I know that in order to do cooler things for my maps, scripting can help.

 

What are some basic and helpfull scripts that you guys use, and what do they do?

 

(If possible point me in the right direction to learn how to script)

Share this post


Link to post

One script that I get a lot of use out of is this:

 

script 1 ENTER
{
	while (ThingCount(T_NONE, 2) > 0)
	Delay(35);
	{
		Door_Open(1, 16, 0);
	}
}

 

This is just a simple script that will wait until all of the monsters of a given type, or TID, are dead and then perform an action.

 

If you take a look at the wiki page for ThingCount you'll see we can specify a type and a tid. Because I want the action performed at the end of my arena that has a whole bunch of different types of monsters, I'm telling it to ignore the type (T_NONE) and only count actors that I've given the specific tag to (which is 2, in this case).

 

Once all the "tag 2" monsters are dead, the script will wait 35 tics (which is roughly equal to 1 second), and then perform the action. In this case, it will open a door. See the wiki page on Door_Open for further info on that one.

 

I absolutely love this script because it's essentially the 666 and 667 tag specials from Dead Simple, except we can use any arrangement of monsters, and have it perform any action we want. The script could trigger after a boss encounter with 3 Cyberdemons, or after a horde of 300 Pinkys. Instead of opening a door, it could lower a floor, raise a ceiling, spawn extra monsters, make the lights flicker, whatever we need! Definitely take a look at the Loops wiki page for more information on the various kinds of loops we can set up, as well.

 

One thing worth noting is that this script is currently set to start running as soon as we enter the map (and will continue to check its state, even if the script isn't used until the very last fight). This is unnecessary. We really only need it to start checking whether our tagged monsters are dead or alive once we're actually in the appropriate fight. In that case, we can make it a closed script by using (void) instead of ENTER. Take a look at the wiki page for Script types to get a better understanding of these (they're important!).

 

As a closed script instead, we can simply activate it at the start of our encounter (with a switch, or by crossing a linedef, for example), and save on resources.

 

You'll want to spend some time on the zdoom wiki. For me personally, learning some basic ACS came down to jumping between a lot of different sources. Reading the wiki, finding random threads on the zdoom or DW forums, or cracking open maps in the editor to see how other people did stuff.

 

 

Edited by RonnieJamesDiner

Share this post


Link to post
4 hours ago, RonnieJamesDiner said:

One script that I get a lot of use out of is this:

 


script 1 ENTER
{
	while (ThingCount(T_NONE, 2) > 0)
	Delay(35);
	{
		Door_Open(1, 16, 0);
	}
}

 

This is just a simple script that will wait until all of the monsters of a given type, or TID, are dead and then perform an action.

 

The way this script is written can be a bit misleading on what it's actually doing. The curly brackets enclose a block of statements, and such a block is often used for loops (or if-conditions). But they can also be placed anywhere in the code, but only affect variable scope in this case (although I don't know if even that is the case in ACS).

If there is a block directly following the loop then only the first statement is the body of the loop, which is the case here -  the Delay() is the body of the loop. In cases like this it helps to indent the single statement to make it more clear that it's the body of the loop. The Delay() being the body of the loop also means that the following block is not part of the loop, and is effectively redundant.

 

A more clear way to write the script would be something like this:

 

script 1 ENTER
{
	while (ThingCount(T_NONE, 2) > 0)
		Delay(35);
  
  	Door_Open(1, 16, 0);
}

 

Share this post


Link to post

Light fade and glow loops

For 16 sectors tagged sequentially this will set a light glow on each one from 1 to 16 every 5 tics. There are more complex ones you can do but this kind of thing is what I use to make all my light sequences. Super fast with sequential tagging

Script 1 ENTER
{
	int light1;
	light1 = 1;

	while(light<=15){
                     light_glow(light1, 256, 128, 35);
                     delay(5);
                     light1++;
                     }
}

Hopefully I didn't fuck that up :D

Share this post


Link to post

@boris Yeahh, I can't even remember how I got into the habit of writing the script like that (most of my scripts, actually). I figured it wasn't correct, given the nearly identical example on the wiki page is different, but it always seemed to work for me so I never gave it much thought. I appreciate the explanation, though! (Even if I don't completely understand what you said...) :P

 

What do you mean by "body" of the loop? Er... what I'm asking is, what does "body" actually mean in this context?

Share this post


Link to post
16 hours ago, RonnieJamesDiner said:

@boris Yeahh, I can't even remember how I got into the habit of writing the script like that (most of my scripts, actually). I figured it wasn't correct, given the nearly identical example on the wiki page is different, but it always seemed to work for me so I never gave it much thought. I appreciate the explanation, though! (Even if I don't completely understand what you said...) :P

 

What do you mean by "body" of the loop? Er... what I'm asking is, what does "body" actually mean in this context?

 

The "body" are the instructions that are executed in your loop (or your if-statement). That can be either a single line - like your Delay() - or a block enclosed by the curly brackets, like in Bridgeburner's script.

Share this post


Link to post

If you wanna get into scripting, you might wanna have a look in the "ACS functions" category in the ZDoom wiki. There's the list of all the pre-built functions you can use.

If you know about loops, variables and conditions, you know all you need to know to make basic scripts which will handle a lot of stuff at once.

Oh and don't forget the semicolons too.

Share this post


Link to post

I don't know how useful those scripts of mine actually are, but they do nice stuff...

 

Custom Sector Glow

// SECTOR GLOW


script 1 OPEN {

    int sector = 1;            // sector tag
    int start = 160;          // brightness start
    int end = 255;           // brightness end
    int step = 8;              // in-/decrement between steps
    int pause = 2;            // pause between steps
    
    int counter = start;
    bool countup = TRUE;
    bool countdown = FALSE;

    while (TRUE) {
        // count up
        if (countup == TRUE) {
            if (counter < end) {
                Light_ChangeToValue(sector, counter);
                Delay(pause);
                counter += step;
            } else {
                countup = FALSE;
                countdown = TRUE;
            }
        }
        // count down
        if (countdown == TRUE) {
            if (counter > start) {
                Light_ChangeToValue(sector, counter);
                Delay(pause);
                counter -= step;
            } else {
                countup = TRUE;
                countdown = FALSE;
            }
        }
    }
}

 

Thing Re- and De-Activator

// THING ACTIVATOR SEQUENCE

// tag dormant things, e.g. lights with consecutive tags (1,2,3,4...)


script 1 (int first, int last, int pause) {
    int x1 = first;
    int y1 = last;
    while (TRUE) {
        if (x1 <= y1) {
            Thing_Activate(x1);
            Delay(pause);
            Thing_Deactivate(x1);
            x1 += 1;
        } else x1 = first;
    }
}

 

Floor Shaker

// FLOOR SHAKER

// raise & lower floors in sequence


script 1 (int first, int last, int raise) {
    int x1 = first;           // first sector
    int y1 = last;            // last sector
    int speed = 64;        // raise / lower speed
    int pause = 16;        // time between sectors
    while (TRUE) {
        if (x1 <= y1) {
            Floor_RaiseByValue(x1, 64, raise);
            Delay(16);
            Floor_LowerByValue(x1, 64, raise);
            x1 += 1;
        } else x1 = first;
    }
}
Edited by vedan

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×