Spawning weapons

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
reyd34
Posts: 2
Joined: Thu Aug 20, 2020 8:36 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Italy

Spawning weapons

Post by reyd34 »

Some days ago I started making a map where I created a sector in which the player can obtain a different weapon every 30 seconds.
There are two rules for that:
  • 1)I can spawn a new weapon only if the player has grabbed the one spawned in the sector.
    2)After obtaining a weapon the player must wait at least 30 seconds before I spawn another one.
For some reason the code I wrote seems to be executed just for 1 cycle (1 spawning).


Here's the code:

Code: Select all


//Weapons Spawn

global int 1:pickup1;//variable used for spawning

script 3 enter {
		
		if(pickup1==0){
			int weapon = Random(27,33);//choose weapon to spawn
			Thing_Spawn(1,weapon,0,1);//spawn item
			pickup1=1;
		}
}


//If the player leaves the sector I wait N seconds before spawing
script 4 (void){
	delay(35*30);//30 seconds, where 35 tics=1 seconds
	pickup1=0;
}
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Spawning weapons

Post by Jarewill »

I think the issue here is that the script doesn't loop and terminates after spawning the weapon once.
Add this to the end of script 3 and see if it works:

Code: Select all

Delay(1);
Restart;
User avatar
reyd34
Posts: 2
Joined: Thu Aug 20, 2020 8:36 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Italy

Re: Spawning weapons

Post by reyd34 »

Thanks Jarewill, the script seems to work prefectly :thumb:
Post Reply

Return to “Scripting”