(SOLVED) Cigarette Script Questions

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
Doominer441
Posts: 213
Joined: Thu Oct 24, 2013 9:04 pm
Preferred Pronouns: They/Them

(SOLVED) Cigarette Script Questions

Post by Doominer441 »

Hello, I'm trying to implement a sanity system into my mod. You lose sanity during certain events, and you can regain sanity by smoking cigarettes and drinking whiskey. The sanity itself is just an inventory item, but right now I'm working on the implementation of the cigarettes. I mostly have the functional, but my attempt to get the cigarette items to spawn is failing.

There are two kinds of cigarettes, filtered and unfiltered, with different potencies. I don't want to give the player a full pack every time, and so to avoid having to define 8 different new actors for each type of cigarette and each degree of fullness, I tried to implement an args-based spawner to do this. Unfortunately, it doesn't do anything at all.

Code: Select all

Actor Sanity : Inventory 
{
	Tag "Sanity"
	Inventory.MaxAmount 100 // Sets the max amount that can be held in the inventory
}

ACTOR CigaretteCooldown : PowerupGiver
{
	Powerup.Type "PowerCigaretteCooldown"
	+AUTOACTIVATE
}

ACTOR PowerCigaretteCooldown : Powerup
{
	Powerup.Duration -30
}

ACTOR Cigarettes1 : CustomInventory
{
	//$Title Pack of Filtered Cigarettes
	//$Category Items
	+INVENTORY.KEEPDEPLETED
	+INVENTORY.INVBAR
	Inventory.Icon CIG1A0
	Inventory.PickupSound "misc/inventorypickup"
	Inventory.UseSound "misc/invuse"
	Inventory.Pickupmessage "I found a pack of filtered cigarettes..."
	Inventory.Amount 1
	Inventory.MaxAmount 20
	States
	{
	Spawn:
		CIG1 A -1
		Stop
	Use:
		TNT1 A 0 A_JumpIfInventory("Sanity", 0, "SanFull")
		TNT1 A 0 A_JumpIfInventory("PowerCigaretteCooldown", 1, "DontSmoke")
		TNT1 A -1 ACS_NamedExecuteAlways("Filtered_Cigarettes")
		Stop
	SanFull:
		TNT1 A 0 A_Print("I don't feel like smoking right now...")
		Fail
	DontSmoke:
		TNT1 A 0 A_Print("I just smoked, I should wait...")
		Fail
	}
}

Actor Cigarettes2 : Cigarettes1
{
	//$Title Pack of Unfiltered Menthols
	Inventory.Icon CIG2A0
	Inventory.Pickupmessage "I found a pack of unfiltered menthols..."
	States
	{
	Spawn:
		CIG2 A -1
		Stop
	Use:
		TNT1 A 0 A_JumpIfInventory("Sanity", 0, "SanFull")
		TNT1 A 0 A_JumpIfInventory("PowerCigaretteCooldown", 1, "DontSmoke")
		TNT1 A -1 ACS_NamedExecuteAlways("Unfiltered_Cigarettes")
		Stop
	SanFull:
		TNT1 A 0 A_Print("I don't feel like smoking right now...")
		Fail
	DontSmoke:
		TNT1 A 0 A_Print("I just smoked, I should wait...")
		Fail
	}
}

Actor CigaretteSmoker : CustomInventory
{ 
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	Pickup:
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		Stop
  }
}

Actor CigaretteSmoke
{
   Radius 0
   Height 1
   Speed 3
   VSpeed 5
   +RANDOMIZE
   PROJECTILE
   RENDERSTYLE TRANSLUCENT
   ALPHA 0.35
   States
   {
   Spawn:
		SMKE ABCDEFGH 2
		Stop 
   }
}

Actor CigaretteButtSpawn : CustomInventory
{ 
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	Pickup:
		TNT1 A 0 A_FireCustomMissile("CigaretteButtSpawner",0,0,0,1)
		Stop
  }
}

ACTOR CigaretteButtSpawner
{
	States
	{
	Spawn:
		TNT1 AA 1 A_CustomMissile("CigButt",random(2,-2),0,0,0)
		Stop
	}
}

ACTOR CigButt
{
	Speed 7
	BounceFactor 0.4
	Mass 1
	ReactionTime 70
	PROJECTILE
	+DOOMBOUNCE
	-NOGRAVITY
	-NOBLOCKMAP
	States
	{
	Spawn:
	   CIGF ABCD 2 A_Countdown
	   Goto Spawn+1
	Death:
	   CIGF A 0 A_Jump(64,4)
	   CIGF A 0 A_Jump(85,4)
	   CIGF A 0 A_Jump(128,4)
	   CIGF A 350
	   Stop
	   CIGF B 350
	   Stop
	   CIGF C 350
	   Stop
	   CIGF D 350
	   Stop
	}
}

Actor CigPackSpawner 272
{
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(Args[1] == 1, "Filtered")
		TNT1 A 0 A_JumpIf(Args[1] == 2, "Unfiltered")
		Loop
	Filtered:
		TNT1 A 0 A_JumpIf(Args[2] == 1, "QuarterFiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 2, "HalfFiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 3, "ThirdFiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 4, "FullFiltered")
		Loop
	QuarterFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 5)
		Stop
	HalfFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 10)
		Stop
	ThirdFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 15)
		Stop
	FullFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 20)
		Stop
	Unfiltered:
		TNT1 A 0 A_JumpIf(Args[2] == 1, "QuarterUnfiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 2, "HalfUnfiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 3, "ThirdUnfiltered")
		TNT1 A 0 A_JumpIf(Args[2] == 4, "FullUnfiltered")
		Loop
	QuarterUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 5)
		Stop
	HalfUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 10)
		Stop
	ThirdUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 15)
		Stop
	FullUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 20)
		Stop
  }
}
This is all I have for my implementation, I'm not sure where the failure arises, it simply doesn't spawn them with no other sign of failure. Could anyone please help me?
Last edited by Doominer441 on Mon Mar 04, 2024 10:27 am, edited 3 times in total.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Cigarette Script Questions

Post by Jarewill »

I copied your CigPackSpawner code and it seems to work fine for me.
My only idea what could be going wrong for you is that you are using wrong args.
Arrays index from 0, so args[1] is actually the second arg.

If that's not the case then please upload a sample map that we could test.
User avatar
Doominer441
Posts: 213
Joined: Thu Oct 24, 2013 9:04 pm
Preferred Pronouns: They/Them

Re: Cigarette Script Questions

Post by Doominer441 »

You're right, I understand it now. Thank you for the help.
User avatar
Doominer441
Posts: 213
Joined: Thu Oct 24, 2013 9:04 pm
Preferred Pronouns: They/Them

Re: (REOPENED) Cigarette Script Questions

Post by Doominer441 »

Unfortunately, I've run into a new problem. My smoke effect, CigaretteSmoker, doesn't function how I'd like. I'm trying to make a short but continuous stream of smoke coming out, but all four CigaretteSmoke actors are spawned at once, even when i add TNT1 A 250 between each A_FireCustomMissile call.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: (REOPENED) Cigarette Script Questions

Post by Jarewill »

That happens because all CustomInventory code triggers at the same time, it doesn't take tics into account at all.
You can however work around that by either making it trigger an ACS script, or using overlays, like so:

Code: Select all

Actor CigaretteSmoker : CustomInventory
{
	+ALWAYSPICKUP
	+AUTOACTIVATE //This flag ensures it gets activated on pickup
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	Pickup:
		TNT1 A 0 A_RailWait //The item needs to be picked up successfully first
		Stop
	Use:
		TNT1 A 0 A_Overlay(-10,"Smoke") //Then it sets an overlay
		Fail //And fails (IMPORTANT!)
	Smoke:
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 25 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 0 A_TakeInventory("CigaretteSmoker") //At the end of it, it removes itself from the inventory
		Stop
  }
}
User avatar
Doominer441
Posts: 213
Joined: Thu Oct 24, 2013 9:04 pm
Preferred Pronouns: They/Them

Re: (SOLVED) Cigarette Script Questions

Post by Doominer441 »

That seems to have done the trick. As a bonus, I even managed to get the cigarette butts spawning and bouncing like they're supposed to.

Code: Select all

ACTOR CigaretteCooldown : PowerupGiver
{
	Powerup.Type "PowerCigaretteCooldown"
	+AUTOACTIVATE
}

ACTOR PowerCigaretteCooldown : Powerup
{
	Powerup.Duration -30
}

ACTOR Cigarettes1 : CustomInventory
{
	//$Title Pack of Filtered Cigarettes
	//$Category Items
	//+INVENTORY.KEEPDEPLETED
	+INVENTORY.INVBAR
	Inventory.Icon CIG1A0
	Inventory.PickupSound "misc/inventorypickup"
	Inventory.UseSound "misc/invuse"
	Inventory.Pickupmessage "I found a pack of filtered cigarettes..."
	Inventory.Amount 1
	Inventory.MaxAmount 20
	States
	{
	Spawn:
		CIG1 A -1
		Stop
	Use:
		TNT1 A 0 A_JumpIfInventory("Sanity", 0, "SanFull")
		TNT1 A 0 A_JumpIfInventory("PowerCigaretteCooldown", 1, "DontSmoke")
		TNT1 A -1 ACS_NamedExecuteAlways("Filtered_Cigarettes")
		Stop
	SanFull:
		TNT1 A 0 A_Print("I don't feel like smoking right now...")
		Fail
	DontSmoke:
		TNT1 A 0 A_Print("I just smoked, I should wait...")
		Fail
	}
}

Actor Cigarettes2 : Cigarettes1
{
	//$Title Pack of Unfiltered Menthols
	Inventory.Icon CIG2A0
	Inventory.Pickupmessage "I found a pack of unfiltered menthols..."
	States
	{
	Spawn:
		CIG2 A -1
		Stop
	Use:
		TNT1 A 0 A_JumpIfInventory("Sanity", 0, "SanFull")
		TNT1 A 0 A_JumpIfInventory("PowerCigaretteCooldown", 1, "DontSmoke")
		TNT1 A -1 ACS_NamedExecuteAlways("Unfiltered_Cigarettes")
		Stop
	SanFull:
		TNT1 A 0 A_Print("I don't feel like smoking right now...")
		Fail
	DontSmoke:
		TNT1 A 0 A_Print("I just smoked, I should wait...")
		Fail
	}
}

Actor CigaretteSmoker : CustomInventory
{
	+ALWAYSPICKUP
	+AUTOACTIVATE //This flag ensures it gets activated on pickup
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	Pickup:
		TNT1 A 0 A_RailWait //The item needs to be picked up successfully first
		Stop
	Use:
		TNT1 A 0 A_Overlay(-10,"Smoke") //Then it sets an overlay
		Fail //And fails (IMPORTANT!)
	Smoke:
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 3 A_FireCustomMissile("CigaretteSmoke",random(10,-10),0,0,0)
		TNT1 A 0 A_TakeInventory("CigaretteSmoker") //At the end of it, it removes itself from the inventory
		Stop
  }
}

Actor CigaretteSmoke
{
   Radius 0
   Height 1
   Speed 3
   VSpeed 5
   +RANDOMIZE
   PROJECTILE
   RENDERSTYLE TRANSLUCENT
   ALPHA 0.15
   States
   {
   Spawn:
		SMKE ABCDEFGH 8
		Stop 
   }
}

Actor CigaretteButtSpawn : CustomInventory
{
	+ALWAYSPICKUP
	+AUTOACTIVATE //This flag ensures it gets activated on pickup
	States
	{
	Spawn:
		TNT1 A -1
		Stop
	Pickup:
		TNT1 A 0 A_SpawnProjectile("CigButt", 48, 0, random(10,-10), CMF_AIMDIRECTION, 12) //A_FireProjectile("CigaretteButtSpawner", 0, FALSE, 0, 0)
		TNT1 A 0 A_TakeInventory("CigaretteButtSpawn") //At the end of it, it removes itself from the inventory
		Stop
  }
}

ACTOR CigaretteButtSpawner
{
	States
	{
	Spawn:
		TNT1 AA 1 A_SpawnProjectile("CigButt", 0, 0, random(5,-5), CMF_AIMDIRECTION, -12) //A_SpawnItemEx("CigButt", 28, 0, 0, 8, random(5,-5), 0, random(5,-5))
		Stop
	}
}

ACTOR CigButt
{
	Radius 1
	Height 1
	Speed 15
	BounceFactor 0.4
	Mass 1
	ReactionTime 70
	PROJECTILE
	-NoGravity
	+DoomBounce
	States
	{
	Spawn:
	   CIGF ABCD 2 A_Countdown
	   Goto Spawn+1
	Death:
	   CIGF A 0 A_Jump(64,4)
	   CIGF A 0 A_Jump(85,4)
	   CIGF A 0 A_Jump(128,4)
	   CIGF A 350
	   Stop
	   CIGF B 350
	   Stop
	   CIGF C 350
	   Stop
	   CIGF D 350
	   Stop
	}
}

Actor CigPackSpawner 272
{
	//$Sprite CIGSA0
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(Args[0] == 1, "Filtered")
		TNT1 A 0 A_JumpIf(Args[0] == 2, "Unfiltered")
		Loop
	Filtered:
		TNT1 A 0 A_JumpIf(Args[1] == 1, "QuarterFiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 2, "HalfFiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 3, "ThirdFiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 4, "FullFiltered")
		Loop
	QuarterFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 5)
		Stop
	HalfFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 10)
		Stop
	ThirdFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 15)
		Stop
	FullFiltered:
		TNT1 A 0 A_DropItem("Cigarettes1", 20)
		Stop
	Unfiltered:
		TNT1 A 0 A_JumpIf(Args[1] == 1, "QuarterUnfiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 2, "HalfUnfiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 3, "ThirdUnfiltered")
		TNT1 A 0 A_JumpIf(Args[1] == 4, "FullUnfiltered")
		Loop
	QuarterUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 5)
		Stop
	HalfUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 10)
		Stop
	ThirdUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 15)
		Stop
	FullUnfiltered:
		TNT1 A 0 A_DropItem("Cigarettes2", 20)
		Stop
  }
}
Post Reply

Return to “Scripting”