Need help with ACS scripts.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Need help with ACS scripts.

Post by Mav3r1ck »

I was watching scripting tutorial videos and decided to tried it myself.

Code: Select all

int LineTrigger1 = 0;
script 1 (void)
{
	if(LineTrigger1 == 0)
	{
	    LineTrigger1 = 1;
		Stairs_BuildDown(2, 16, 16, 0, 0);
	}
	else if(LineTrigger1 == 1)
	Delay(1);
}
Above is the code I am using and it's setup to be used only once when I cross one of the two linedefs it applies to but I noticed something. When I remove the LineTrigger and Delay at the bottom the code still works fine. That being said do I need the LineTrigger1 and Delay at the bottom? or can I remove them without any drawbacks?

And also Is there a way to improve the code?
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Need help with ACS scripts.

Post by Cherno »

Let's analyse this :ugeek:

Code: Select all

int LineTrigger1 = 0;//makes sense to have a variable keep track of wether the script has been executed yet since there is more than one line that could trigger it
script 1 (void)//consider using names scripts instead
{
	if(LineTrigger1 == 0)//check if the script has been executed yet
	{
	    LineTrigger1 = 1;//it hasn't, so we make sure it won't execute again.
		Stairs_BuildDown(2, 16, 16, 0, 0);
	}
	else if(LineTrigger1 == 1)
	Delay(1);//the script has already been executed, but since we don't want anything to happen in that case, we don't need any code here. In fact, this line and the one before it are unneccessary. 
}
So yes, you can remove these two lines. Only if the linedef can trigger more than once, and you want something to happen if it has already been triggered once, do you need any further code. Delay(1) just means that the script waits for one second before running the following code line.
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Need help with ACS scripts.

Post by Mav3r1ck »

Would you be able to give me an example of a script that spawns a monster repeatedly each time it's triggered?
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Need help with ACS scripts.

Post by Cherno »

Place a MapSpot at the desired spawn location, give it a tid, and set it's angle. Spawned monsters will spawn at this location with the same angle.

Code: Select all

Script "SpawnMonster" (void)
{
     SpawnSpotFacingForced
     (
          "DoomImp",//the class name of the actor to spawn
          99,//the tid of the actor (usually a MapSpot) that you want to spawn at, with the spawned actor having the MapSpot's angle
          666//the tid you want the spawned actor to have. Useful if you want to access it later. Could be 0 otherwise.
     );
}
A little bit more advanced: Pass three parameters to this script when executing it to have more control over which monster type to spawn, which mapspot to spawn at, and which tid to give the spawned monster.

Code: Select all

[code]
Script "SpawnMonster" (int actorType,int mapSpotTid,int newTid)
{
     str className = DoomImp"";//default in case we accidently pass more then 2 or less than 0 as actorType
     switch(actorType)
     {
          case 0:
          className = "DoomImp";
          break;
	
         case 1:
        className = "ZombieMan";
        break;
	
         case 2:
         className = "Demon";
         break;
   }
     SpawnSpotFacingForced
     (
          className,//the class name of the actor to spawn
          mapSpotTid,
          newTid
     );
}
[/code]
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Need help with ACS scripts.

Post by Mav3r1ck »

How would you suggest I name my scripts?
User avatar
Redneckerz
Spotlight Team
Posts: 1124
Joined: Mon Nov 25, 2019 8:54 am
Graphics Processor: Intel (Modern GZDoom)

Re: Need help with ACS scripts.

Post by Redneckerz »

Mav3r1ck wrote:How would you suggest I name my scripts?
The above script to spawn a monster carries the name ''SpawnMonster''.

So name your scripts logicaly. You have a script that pushes a wall of fire? WallFire or something, and not something like YellowEgg.

Unless that is not what you are looking for, but just trying to lend a hand.
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Need help with ACS scripts.

Post by Mav3r1ck »

I used Translations in Slade 3 to recolor the original doom monsters into custom ones. That being said, is the method I'm using the best option? Or is their more methods?

I know this is unrelated to the topic but I was curious.

EDIT: Thx for the help with the scripting.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Need help with ACS scripts.

Post by Cherno »

User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Need help with ACS scripts.

Post by Mav3r1ck »

Code: Select all

int LineTrigger1 = 0;
script 14 (void)
{
	if (LineTrigger1 == 0)
	{
		LineTrigger1 = 1;

Code: Select all

int LineTrigger1 = 0;
script 14 (void)
{
	if (LineTrigger1 == 0)
	{
		LineTrigger1++;
So is the coding on the bottom equivalent to the coding at the top?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Need help with ACS scripts.

Post by gwHero »

Mav3r1ck wrote:
So is the coding on the bottom equivalent to the coding at the top?
Yes.
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Need help with ACS scripts.

Post by Mav3r1ck »

Thank you for the help.
Post Reply

Return to “Scripting”