Bomb detonation with 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
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Bomb detonation with zscript

Post by nekostuffing »

I want to create a custom function that allows the player to detonate a grenade type projectile using the alt fire of the weapon, i've seen this done with decorate before using Thing_Destroy but this isn't a viable method for multiplayer, so i was hoping to use zscript with decorate, and create a function that does just this but with multiplayer compatibility, im still very new to zscript so any help would be much appreciated.
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Bomb detonation with zscript

Post by Virathas »

You could try something like this (Based on doom rocket launcher)

Code: Select all


class AltExplodingRocketLauncher : RocketLauncher 
{
	Actor LastMissile; // This is important, we'll grab

	States
	{
	Fire:
		MISG B 8 A_GunFlash;
		MISG B 12 A_FireProjectileNew (); // There is bound to be a better way, but the gist is you want to have a pointer for the missile.
		MISG B 0 A_ReFire;
		Goto Ready;
	AltFire:
		MISG B 8 A_DetonateMissile();
		Goto Ready;

	}
Action Void A_FireProjectileNew ()
{
	LastMissile = A_FireProjectile ("Rocket");
}
Action Void A_DetonateMissile ()
{
	If (LastMissile)
	{
		LastMissile.SetStateLabel("Explode");
		LastMissile = null;
	}
}


}
Code untested, but hopefully will get you closer to where you want to go.
Note that you also need to handle the case that the grenade already exploded earlier, or is in some other state you wouldn't want it to explode.
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Bomb detonation with zscript

Post by nekostuffing »

So if i take this class and make my decorate weapon inherit form it would i be able to use the A_DetonateMissile function in my decorate weapon?.
Or would i have to define a new custom function that works like A_DetonateMissile.
Im asking this because i was able to use a custom zscript function with decorate before, by doing this.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Bomb detonation with zscript

Post by Player701 »

LastMissile needs to be prefixed with "invoker." in A_FireProjectileNew and A_DetonateMissile method bodies for the above code to compile.
nekostuffing wrote: Thu Oct 13, 2022 2:14 am So if i take this class and make my decorate weapon inherit form it would i be able to use the A_DetonateMissile function in my decorate weapon?.
Yes, but the class can already be used as-is, there shouldn't be a need to inherit from it. But it is possible, of course.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Bomb detonation with zscript

Post by Dan_The_Noob »

there is a mine launcher that gives and takes a token called "detonatemine" when you altfire or something and the mine checks for that inventory item to skip to death state and explode.

---edit--
this is a decorate mine launcher, if you wanted compat for multiplayer.
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Bomb detonation with zscript

Post by nekostuffing »

Dan_The_Noob wrote: Fri Oct 14, 2022 12:28 am there is a mine launcher that gives and takes a token called "detonatemine" when you altfire or something and the mine checks for that inventory item to skip to death state and explode.

---edit--
this is a decorate mine launcher, if you wanted compat for multiplayer.
Do you know were i could find this mine launcher's code, like what mod its from so i can examine the code, ill try the zscript+decorate method first but if it doesn't work ill give the mine launcher method a try as well.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Bomb detonation with zscript

Post by Dan_The_Noob »

here is the decorate for it.
No idea where it's from, it was in a realm667 mashup thing.

Code: Select all

Actor ProxLauncher : Weapon
{
  Inventory.PickupSound "misc/w_pkup"
  Inventory.PickupMessage "You got the Prox Launcher!"
  Obituary "%o got too close to %k's proximity mine."
  Weapon.AmmoType "HandGrenadeAmmo"
  Weapon.AmmoGive 5
  Weapon.AmmoUse 1
  Weapon.KickBack 200
  weapon.slotnumber 8
  States
  {
  Spawn:
    PRXP A -1
    Loop
  Ready:
    PRXL A 1 A_GiveInventory ("IsAlive", 1)
    PRXL A 1 A_WeaponReady
    Goto Ready +1
  Select:
    PRXL A 1 A_Raise
    Loop
  Deselect:
    PRXL A 1 A_Lower
    Loop
  Fire:
    PRXL A 0 bright A_PlaySound("Weapons/ProxFire")
    PRXL B 4 bright A_FireCustomMissile("ProxProj", 0, 1, 0, 0)
    PRXL CD 5
    PRXL E 4
    PRXL A 24
    PRXL A 1 A_ReFire
    Goto Ready+1
  AltFire:
    PRXL A 0 A_PlaySound("Weapons/ProxBeep")
    PRXL D 5 A_GiveInventory("DetonateProx", 1)
    PRXL E 5 A_TakeInventory("DetonateProx", 99)
    PRXL A 5
    Goto Ready+1
  }
}

Actor ProxMines : Ammo
{
  Scale 0.9
  Radius 16
  Height 8
  Inventory.PickupMessage "Picked up some Prox Mines"
  Inventory.Icon "PROXA0"
  Inventory.Amount 5
  Inventory.MaxAmount 20
  Ammo.BackPackAmount 3
  Ammo.BackPackMaxAmount 40
  States
  {
  Spawn:
    PROA A -1
    Stop
  }
}

Actor ProxProj
{
  Radius 15
  Height 10
  Damage (0)
  Speed 40
  Scale 0.9
  Obituary "%o got too close to %k's proximity mine."
  Projectile
  +CanBounceWater
  +BounceOnActors
  -NoGravity
  +HexenBounce
  +ThruGhost
  +NoTarget
  -SlidesOnWalls
  BounceFactor 0.0
  States
  {
  Spawn:
    PROX A 1 A_CheckFloor("Planted")
    Loop
  Planted:
    PROX A 1 A_PlaySound("Weapons/ProxHit")
    PROX A 0 A_CustomMissile("PlantedProx", 0, 0, 0, 4)
    Stop
  Death:
    PROX C 0 Bright A_Stop
    PROX C 0 Bright A_PlaySound("Weapons/RockLX")
    PROX C 0 Bright A_NoGravity
    PROX C 0 Bright A_SetTranslucent(0.5, 1)
    PRXD A 2 Bright A_Explode(500, 500, 1)
    PRXD BCDEFGHIJKLMNOPQRSTU 2 Bright
    Stop
  }
}

Actor PlantedProx
{
  Radius 15
  Height 10
  Damage (0)
  Speed 0
  Scale 0.9
  Obituary "%o got too close to %k's proximity mine."
  Projectile
  +CanBounceWater
  +MoveWithSector
  -NoGravity
  +HexenBounce
  +ThruGhost
  +NoTarget
  -SlidesOnWalls
  States
  {
  Spawn:
    PROX A 0
    PROX A 0 A_Stop
    PROX A 1 A_JumpIfInTargetInventory("DetonateProx", 1, "Death") //Destroys the mine if the player uses Altfire.
    PROX A 0 A_JumpIfInTargetInventory("IsAlive", 1, 1) //Destroys if the player is dead,
    Goto Death				//this is used to avoid ownership issues on respawn.
    PROX A 0
    Goto Spawn+2
  Death:
    PROX A 2 A_PlaySound("Weapons/ProxBeep")
    PROX BC 4
    PROX C 0 Bright A_Stop
    PROX C 0 Bright A_PlaySound("Weapons/RockLX")
    PROX C 0 Bright A_NoGravity
    PROX C 0 Bright A_SetTranslucent(0.5, 1)
    PRXD A 2 Bright A_Explode(176, 176, 1)
    PRXD BCDEFGHIJKLMNOPQRSTU 2 Bright
    Stop
  }
}

Actor Planted : Inventory { }

Actor DetonateProx : Inventory { }

Actor IsAlive : Inventory 
{
Inventory.MaxAmount 1 
}
User avatar
nekostuffing
Posts: 60
Joined: Sat Aug 31, 2019 8:08 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Bomb detonation with zscript

Post by nekostuffing »

Dan_The_Noob wrote: Fri Oct 14, 2022 2:58 am here is the decorate for it.
This is very useful, thanks!.
Post Reply

Return to “Scripting”