Making a working fragmentation grenade (DECORATE only)

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!)
User avatar
AtomicLugia
Posts: 36
Joined: Thu Oct 06, 2016 7:58 am
Location: Germany

Making a working fragmentation grenade (DECORATE only)

Post by AtomicLugia »

Like the title describes, I would like to make a hand grenade that also fires hitscan things around the explosion. Yes, I know that the A_Explode does have these "nails", but they're only horizontal and their range is infinite, so no thanks. I managed to do so, but the bullets doesn't count for me. When a monster dies by these hitscan attacks, it counts as killed by the world, not by me (because I threw the grenade). This also happens on Deathmatch, when I kill a bot with the grenade, if the bot dies by the hitscan attack, I don't earn a frag, only when the bot is killed by the explosion. Did I do something wrong? I'm using Zandronum 3.0.

Here's my script of the grenade:

Code: Select all

Actor ALDM-Grenade : CustomInventory 31010
{
	Tag "Hand Grenade"
	Inventory.Icon "ARTIGREN"
	Inventory.PickupMessage "Picked up a grenade."
	Inventory.PickupSound "Pickups/Inventory"
	Inventory.Amount 1
	Inventory.Maxamount 25
	Inventory.InterHubAmount 25
	Inventory.UseSound "Grenade/Throw"
	-COUNTITEM
	+INVBAR
	States
	{
	Spawn:
		GREN A -1
		Stop
	Use:
		TNT1 A 0 A_ThrowGrenade("ThrownGrenade",0,10,4)
		Stop
	}
}

Actor ThrownGrenade
{
	Radius 8
	Height 8
	Speed 20
	Mass 1250
	+MISSILE
	-NOGRAVITY
	+HEXENBOUNCE
	+EXPLODEONDEATH
	+DEHEXPLOSION
	+RANDOMIZE
	+BOUNCEONACTORS
	Decal SmallBulletChip
	Obituary "%o was blown up by %k's grenade."
	SeeSound "Grenade/Ping"
	States
	{
	Spawn:
		GREN B 0
		GREN B 0 A_StopSound
		GREN BCDEFGHIBCDEFGHIBCDEFGHIBCDEFGHI 2
		Goto Death
	Death:
		MISL B 0 Bright A_Stop
		MISL B 0 Bright A_ChangeFlag("NOGRAVITY",TRUE)
		MISL B 0 Bright A_PlaySound("BigFuckingGun/Bang")
		MISL B 0 Bright A_JumpIf(WaterLevel==0,6)
		MISL BBBBB 0 Bright A_SpawnItemEx("ALDM-Bubble",Random(-16,16),Random(-16,16),Random(-16,16),0,0,Random(3,5),0,0,0)
		MISL B 8 Bright A_Explode(128,64,XF_HURTSOURCE,1)
		MISL C 6 Bright A_CustomBulletAttack(180,180,20,5,"ALDM-ShotgunPuff",512)
		MISL D 4 Bright
		Stop
	}
}
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Making a working fragmentation grenade (DECORATE only)

Post by Arctangent »

The issue isn't that the world is considered the killer, it's that the grenade is. Unfortunately, there doesn't seem to be a function that Decorate has access to that can attribute the bullets to the grenade's source - you're stuck using projectiles instead - [wiki]A_CustomMissile[/wiki] has the CMF_TRACKOWNER flag for the exact purpose of projectiles spawned by projectiles.

If you really need to use hitscans instead, then you'll have to drop Zandronum support so that you can use ZScript.
User avatar
AtomicLugia
Posts: 36
Joined: Thu Oct 06, 2016 7:58 am
Location: Germany

Re: Making a working fragmentation grenade (DECORATE only)

Post by AtomicLugia »

Is it possible to do this with A_SpawnItemEx or A_RearrangePointers?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Making a working fragmentation grenade (DECORATE only)

Post by Matt »

The way I recall I used to do it, the hitscan attack would do no damage, but the puff (which would have +PUFFGETSOWNER) would call A_TransferPointers to set its target to its target's target and explode.

I do not recommend having it explode, but rather the puff should become a missile that then calls (before the A_TransferPointers call!) A_FaceTarget and A_ChangeVelocity (making the puff go backwards away from the grenade it's just faced) to launch itself into the victim as though it were a regular projectile.

This should all be done in the same tic using an anon function or some zero-length frames.


So something like:

A_FaceTarget(0,0)
A_TransferPointers(AAPTR_TARGET,AAPTR_DEFAULT,AAPTR_TARGET,AAPTR_TARGET,PTROP_UNSAFETARGET)
A_ChangeFlag(missile,true)
A_ChangeVelocity(-10,0,0,CVF_RELATIVE) //vertical doesn't matter, you just need it to collide with the victim's hitbox


(I haven't tested this, so as a last resort you might want to try the exploding but it's really taxing on the computer)
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Making a working fragmentation grenade (DECORATE only)

Post by Arctangent »

AtomicLugia wrote:Is it possible to do this with A_SpawnItemEx or A_RearrangePointers?
A_SpawnItemEx can only spawn actors, which hitscans aren't. A_RearrangePointers does exactly nothing in this scenario, as the grenade already has its source in its proper pointer - the issue is that A_CustomBulletAttack doesn't have the ability to source its damage to anything but the calling actor, and even requesting something along those lines would be moot because you'd have to wait for like five years for Zandronum to catch up to that change anyway.

Really, the best you've got is using projectiles instead, which will probably look better anyway. Matt's ideas will work too, but it's honestly kinda overkill and might not play all that nicely with Zandronum's netcode anyway.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Making a working fragmentation grenade (DECORATE only)

Post by Matt »

A_SpawnItemEx with SXF_TRANSFERPOINTERS and using fastprojectiles for the fragments can also work, since we're dealing with a pre-ZScript engine and we don't need to worry about the huge performance hit of a zillion really small, really fast fastprojectiles quite as much.

Once ZScript is in Zandronum you could go back to hitscans and take advantage of LineTrace and DamageMobj.
User avatar
AtomicLugia
Posts: 36
Joined: Thu Oct 06, 2016 7:58 am
Location: Germany

Re: Making a working fragmentation grenade (DECORATE only)

Post by AtomicLugia »

Thanks for the tips but I better use shrapnels for now. (it's more fitting for this kind of grenade, right?)

Return to “Scripting”