Melee attack troubles

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Melee attack troubles

Post by Nash »

A) How do I make the melee attack play an impact sound when hitting a monster? I have my puff a SeeSound but it seems that the impact sound is only played when the puff actor has +PUFFONACTORS... but I don't want that flag on my puffs.

B) How do I make it so the impact sound actually only plays on live, bleeding monsters? I don't want the same sound to be played when the player punches other punchable things (trees, cars, trash cans, etc).

Here's the relevant code tidbit

Code: Select all

Actor Z_FistPuff : Z_BulletPuff
{
    Decal ""
    VSpeed 0
    SeeSound "weapons/fisthitflesh" // hit flesh
    AttackSound "weapons/fisthitother" // hit wall
    +PUFFONACTORS // i prefer not to have this
    States
    {
        Spawn:
            PUFF A 0 A_FadeOut(0.05)
            PUFF A 0 A_SetScale(scalex + 0.05, scaley + 0.05)
            PUFF A 1
            Loop
    }
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Melee attack troubles

Post by Graf Zahl »

A) If you remove PUFFONACTORS, the puff won't even get spawned on bleeding actors (Blood will be spawned instead!) and thus play no sound, so sorry, you will have to use the flag.
B) You cannot do this with the sound properties. But you can use the various state labels (CRASH for hitting non-things, XDEATH for hitting bleeding things) to have different actions for different situations, including calling A_PlaySound.
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Melee attack troubles

Post by Nash »

Regarding A) I suspected as much, but I'm just curious how the Doom fist works? There's no puff when I punch a monster in Doom but it does play an impact sound when hitting things.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Melee attack troubles

Post by Graf Zahl »

Code: Select all

DEFINE_ACTION_FUNCTION(AActor, A_Punch)
{
	angle_t 	angle;
	int 		damage;
	int 		pitch;
	AActor		*linetarget;

	if (self->player != NULL)
	{
		AWeapon *weapon = self->player->ReadyWeapon;
		if (weapon != NULL && !(weapon->WeaponFlags & WIF_DEHAMMO))
		{
			if (!weapon->DepleteAmmo (weapon->bAltFire))
				return;
		}
	}

	damage = (pr_punch()%10+1)<<1;

	if (self->FindInventory<APowerStrength>())	
		damage *= 10;

	angle = self->angle;

	angle += pr_punch.Random2() << 18;
	pitch = P_AimLineAttack (self, angle, MELEERANGE, &linetarget);

	P_LineAttack (self, angle, MELEERANGE, pitch, damage, NAME_Melee, NAME_BulletPuff, true, &linetarget);

	// turn to face target
	if (linetarget)
	{
----->		S_Sound (self, CHAN_WEAPON, "*fist", 1, ATTN_NORM);
		self->angle = R_PointToAngle2 (self->x,
										self->y,
										linetarget->x,
										linetarget->y);
	}
}
See the arrowed line.
User avatar
::Bloodfury::
Posts: 332
Joined: Mon Aug 01, 2011 7:39 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland

Re: Melee attack troubles

Post by ::Bloodfury:: »

This was part of one of my abandoned projects. But it works like a dual fists.
And I had no problems with sounds. It played a punching sound while hitting enemies etc.
and metal screech while hitting wall. But I used A_Custompunch. So maybe this helps you out. :)

Code: Select all


actor HandBlades : Weapon 10100
{
//$Category BTV_Weapons
  Game Doom
  Weapon.SelectionOrder 3700
  Weapon.Kickback 100
  Weapon.SlotNumber 1
  Inventory.PickupMessage "You acquired Damned Handblades!"
  Inventory.PickupSound "pickup/armor"
  +WEAPON.NOALERT
  +WEAPON.MELEEWEAPON
  +FLOATBOB
  Obituary "%o Was Taught a lesson by %k And His Handblades"
  States
  {
  Spawn:
    FIST P -1
    Loop
  Ready:
    PUCH A 1 a_weaponready
    loop
    PUCH A 1 a_weaponready	
  Deselect:
    PUCH A 1 A_Lower
    loop
  Select: 
    PUCH A 1 A_Raise
    loop
  Fire:
    PUCH A 0 A_JumpIfInventory("FistToken", 1, "LeftPunch")
    PUCH A 3 A_Playsound ("FIST/SWING")
    PUCH B 2
    PUCH L 0 A_CustomPunch (0,0,0,"HandBladeDeflectPuff",0,0)
    PUCH L 2 A_CustomPunch (55,1,0,"HandBladePuff",0,0)
    PUCH C 2
    PUCH M 2
    PUCH D 2
    PUCH N 2
    PUCH E 2
    PUCH R 2
    PUCH K 0 A_GiveInventory("FistToken",1)
    PUCH K 3 A_ReFire  	
    goto Ready
    LeftPunch:
    PUCH F 3 A_Playsound ("FIST/SWING")
    PUCH G 2
    PUCH O 0 A_CustomPunch (0,0,0,"HandBladeDeflectPuff",0,0)
    PUCH O 2 A_CustomPunch (55,1,0,"HandBladePuff",0,0)
    PUCH H 2
    PUCH P 2
    PUCH I 2
    PUCH Q 2
    PUCH J 2
    PUCH K 0 A_TakeInventory("FistToken",1) 
    PUCH K 3 A_ReFire  	
    goto Ready 
	}
}

User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Melee attack troubles

Post by Nash »

Ah so the Doom fist sound was hardcoded. I was looking all over zdoom.pk3 which was why I didn't understand how it worked. Thanks for the clarification.

BloodFury: thanks but I've already figured it out. Also, just for your information, your example doesn't actually have any of the puff actors in there so even if Graf Zahl didn't answer, your code wouldn't have helped me. :P
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: Melee attack troubles

Post by NeuralStunner »

What's the issue with using TNT1 where you don't want a visible puff? I do it all the time. (PUFFONACTORS is a great flag, really.)
Locked

Return to “Editing (Archive)”