How to make a jetpack using ACS or ZScript?

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
Nailz the Ravager
Posts: 94
Joined: Tue Jun 12, 2018 12:29 pm
Graphics Processor: Not Listed

How to make a jetpack using ACS or ZScript?

Post by Nailz the Ravager »

Hi there. I need some help. How to make a jetpack that can be turned on and off using the Space [/ i] button and which will use the player's ammunition?
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: How to make a jetpack using ACS or ZScript?

Post by ramon.dexter »

Here you, go, something more fancy. A jetpack that behaves the same as the jetpack in duke nukem 3d. Made in zscript. Activated and deactivated from inventory item. Uses the inventory item as an ammo. Could be easily modified to use any kind of ammo.

Code: Select all

class JetPack : CustomInventory
{
	int jetpackSwitch;

	Default
	{
		
		-Solid
		+inventory.invbar
		+inventory.AlwaysPickup
				
		Tag "Jetpack";
		inventory.icon "I_NEDV";
		inventory.amount 100;
		inventory.maxamount 100;
		inventory.interhubamount 100;
	}
	
	States
	{
		Spawn:
			JETP A -1; //supply your own sprite
			Stop;

		Use: 
			TNT1 A 0
			{
				if(invoker.jetpackSwitch == 0) {return ResolveState("Activate");}
				if(invoker.jetpackSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
			Stop;
		Activate:
			TNT1 A 0
			{
				invoker.jetpackSwitch = 1;
				A_Giveinventory("jetpackActive", 1);
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.jetpackSwitch = 0;
				A_TakeInventory("PowerJetpack", 1);
				A_TakeInventory("jetpackActive", 1);
			}
			Stop;
	}

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
class PowerJetpack : PowerFlight //PowerLightAmp
{
	int jetpack_tics; 

    override void attachtoowner(actor user)
    {
        jetpack_tics = 0;
        super.attachtoowner(user);
    }

    override void doeffect()
    {
		Super.doEffect();
		
		if(owner.countinv("JetPack") <= 1)  // * here to check if player has the ammo that the jetpack uses. Otherwise it will just work even when the desired item is depleted.
        {
            owner.takeinventory("jetpackActive", 1);
			self.destroy();
			return;
		}

        jetpack_tics++;

        if(jetpack_tics == 35)
        {
            owner.takeinventory("JetPack", 1); //this could be changed to use any kind of ammo or other type of item. Just to make sure you also change the checker up here *
            jetpack_tics = 0;
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "I_BLNK";
		//==--------------------------
	}
}

class jetpackActive : PowerupGiver
{
	Default
	{
		//flags
		//==--------------------------
		+INVENTORY.AUTOACTIVATE;
		+INVENTORY.FANCYPICKUPSOUND;
		//==--------------------------
		//powerup conf
		//==--------------------------
		powerup.Duration 0x7FFFFFFD;
		powerup.Type "PowerJetpack";
		//==--------------------------
		//inventory conf
		//==--------------------------
		Inventory.MaxAmount 1;
		Inventory.UseSound "pickups/slowmo";
		//==--------------------------
	}
	
	States
	{
		Spawn:
			TNT1 A 0;
			Stop;
	}

}
Nailz the Ravager
Posts: 94
Joined: Tue Jun 12, 2018 12:29 pm
Graphics Processor: Not Listed

Re: How to make a jetpack using ACS or ZScript?

Post by Nailz the Ravager »

ramon.dexter wrote:Here you, go, something more fancy. A jetpack that behaves the same as the jetpack in duke nukem 3d. Made in zscript. Activated and deactivated from inventory item. Uses the inventory item as an ammo. Could be easily modified to use any kind of ammo.

Code: Select all

class JetPack : CustomInventory
{
	int jetpackSwitch;

	Default
	{
		
		-Solid
		+inventory.invbar
		+inventory.AlwaysPickup
				
		Tag "Jetpack";
		inventory.icon "I_NEDV";
		inventory.amount 100;
		inventory.maxamount 100;
		inventory.interhubamount 100;
	}
	
	States
	{
		Spawn:
			JETP A -1; //supply your own sprite
			Stop;

		Use: 
			TNT1 A 0
			{
				if(invoker.jetpackSwitch == 0) {return ResolveState("Activate");}
				if(invoker.jetpackSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
			Stop;
		Activate:
			TNT1 A 0
			{
				invoker.jetpackSwitch = 1;
				A_Giveinventory("jetpackActive", 1);
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.jetpackSwitch = 0;
				A_TakeInventory("PowerJetpack", 1);
				A_TakeInventory("jetpackActive", 1);
			}
			Stop;
	}

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
class PowerJetpack : PowerFlight //PowerLightAmp
{
	int jetpack_tics; 

    override void attachtoowner(actor user)
    {
        jetpack_tics = 0;
        super.attachtoowner(user);
    }

    override void doeffect()
    {
		Super.doEffect();
		
		if(owner.countinv("JetPack") <= 1)  // * here to check if player has the ammo that the jetpack uses. Otherwise it will just work even when the desired item is depleted.
        {
            owner.takeinventory("jetpackActive", 1);
			self.destroy();
			return;
		}

        jetpack_tics++;

        if(jetpack_tics == 35)
        {
            owner.takeinventory("JetPack", 1); //this could be changed to use any kind of ammo or other type of item. Just to make sure you also change the checker up here *
            jetpack_tics = 0;
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "I_BLNK";
		//==--------------------------
	}
}

class jetpackActive : PowerupGiver
{
	Default
	{
		//flags
		//==--------------------------
		+INVENTORY.AUTOACTIVATE;
		+INVENTORY.FANCYPICKUPSOUND;
		//==--------------------------
		//powerup conf
		//==--------------------------
		powerup.Duration 0x7FFFFFFD;
		powerup.Type "PowerJetpack";
		//==--------------------------
		//inventory conf
		//==--------------------------
		Inventory.MaxAmount 1;
		Inventory.UseSound "pickups/slowmo";
		//==--------------------------
	}
	
	States
	{
		Spawn:
			TNT1 A 0;
			Stop;
	}

}
THANK YOU!!!
THANK YOU VERY MUCH!!!
Post Reply

Return to “Scripting”