[Feature Suggestion] A_LifeDrainPunch

Moderator: Graf Zahl

Inuyasha_989
Posts: 60
Joined: Sun Sep 04, 2005 3:05

[Feature Suggestion] A_LifeDrainPunch

Post by Inuyasha_989 »

I already developed this using the GZdoom Source, and based it on the Serpent Staff Check attack. Here's the code (I realize it may be crude/or whatever, but I have no C++ skill what-so-ever)

The codes arguments are: Damage, Life Given, dontrandomise

[spoiler]

Code: Select all

//============================================================================
//
// A_LifeDrainPunch
//
//============================================================================

void A_LifeDrainPunch (AActor *self)
{
	AActor *pmo;

	int index=CheckIndex(2);
	if (index<0) return;
	int damage=EvalExpressionI (StateParameters[index], self);
	int newLife=EvalExpressionI (StateParameters[index+1], self);
	bool norandom=!!EvalExpressionI (StateParameters[index+2], self);
	if (!norandom) damage *= (pr_punch()%8+1);
	angle_t angle;
	int slope;
	int i;
	player_t *player;

	if (NULL == (player = self->player))
	{
		return;
	}
	AWeapon *weapon = self->player->ReadyWeapon;

	pmo = player->mo;
	for (i = 0; i < 3; i++)
	{
		angle = pmo->angle+i*(ANG45/16);
		slope = P_AimLineAttack (pmo, angle, fixed_t(1.5*MELEERANGE));
		if (linetarget)
		{
			P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, MOD_HIT, RUNTIME_CLASS(ABulletPuff));
			pmo->angle = R_PointToAngle2 (pmo->x, pmo->y, 
				linetarget->x, linetarget->y);
			S_SoundID (self, CHAN_WEAPON, weapon->AttackSound, 1, ATTN_NORM);
			if ((linetarget->player || linetarget->flags3&MF3_ISMONSTER)
				&& (!(linetarget->flags2&(MF2_DORMANT+MF2_INVULNERABLE))))
			{
				newLife = player->health+(damage>>3);
				newLife = newLife > 100 ? 100 : newLife;
				if (newLife > player->health)
				{
					pmo->health = player->health = newLife;
				}
			}
			if (weapon != NULL)
			{
				weapon->DepleteAmmo (weapon->bAltFire, false);
			}
			break;
		}
		angle = pmo->angle-i*(ANG45/16);
		slope = P_AimLineAttack (player->mo, angle, fixed_t(1.5*MELEERANGE));

		if (linetarget)
		{
			P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, MOD_HIT, RUNTIME_CLASS(ABulletPuff));
			pmo->angle = R_PointToAngle2 (pmo->x, pmo->y, 
				linetarget->x, linetarget->y);

			if (linetarget->player || linetarget->flags3&MF3_ISMONSTER)
			{
				newLife = player->health+(damage>>4);
				newLife = newLife > 100 ? 100 : newLife;
				pmo->health = player->health = newLife;
			}
			weapon->DepleteAmmo (weapon->bAltFire, false);
			break;
		}
	}
}
[/spoiler]

EDIT: Forgot a description, its a custom punch that when on contact, transfers the set amount of health to you. Simple, eh? :P
User avatar
Soultaker
Posts: 219
Joined: Fri Sep 02, 2005 8:26
Location: Capping some zombies Gangsta Style.

Post by Soultaker »

Would be great for the converted Moljnir Crowbar I use in my GZDooM mods.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany

Post by Graf Zahl »

What's the point of a 'newlife' parameter if you don't ever use it?
User avatar
BlazingPhoenix
Posts: 488
Joined: Sun Aug 28, 2005 5:11

Post by BlazingPhoenix »

hey, it's good for people that wanna make magic life sucking-like weapons right?
User avatar
TheDarkArchon
Posts: 1000
Joined: Wed Jul 06, 2005 11:58
Location: What's that fucking smell

Post by TheDarkArchon »

I would have the life gained as a multiplier

Something remotely like this. Most likely wrong (Though I have re-added the range parameter which was missing for some strange reason)
[spoiler]

Code: Select all

//============================================================================
//
// A_LifeDrainPunch
//
//============================================================================

void A_LifeDrainPunch (AActor *self)
{
   AActor *pmo;

   int index=CheckIndex(4); //Why was this set to two then there were originally 3 indicies?
   if (index<0) return;
   int damage=EvalExpressionI (StateParameters[index], self);
   int LifeMulti=EvalExpressionI (StateParameters[index+1], self);
   bool norandom=!!EvalExpressionI (StateParameters[index+2], self);
   fixed_t Range=EvalExpressionF (StateParameters[index+3], self) * FRACUNIT; 

   int newlife;
   if (!norandom) damage *= (pr_punch()%8+1);
   angle_t angle;
   int slope;
   int i;
   player_t *player;

   If(LifeMulti == 0) LifeMulti = 100; 

   if (NULL == (player = self->player))
   {
      return;
   }
   AWeapon *weapon = self->player->ReadyWeapon;

  if(range == 0) range = MELEERANGE;

   pmo = player->mo;
   for (i = 0; i < 3; i++)
   {
      angle = pmo->angle+i*(ANG45/16);
      slope = P_AimLineAttack (pmo, angle, range);
      if (linetarget)
      {
         P_LineAttack (pmo, angle, range, slope, damage, MOD_HIT, RUNTIME_CLASS(ABulletPuff)); //why was the range fixed at 96?
         pmo->angle = R_PointToAngle2 (pmo->x, pmo->y,
            linetarget->x, linetarget->y);
         S_SoundID (self, CHAN_WEAPON, weapon->AttackSound, 1, ATTN_NORM);
         if ((linetarget->player || linetarget->flags3&MF3_ISMONSTER)
            && (!(linetarget->flags2&(MF2_DORMANT+MF2_INVULNERABLE))))
         {
            newLife = player->health+(damage*(LifeMulti/100));
            newLife = newLife > 100 ? 100 : newLife;
            if (newLife > player->health)
            {
               pmo->health = player->health = newLife;
            }
         }
         if (weapon != NULL)
         {
            weapon->DepleteAmmo (weapon->bAltFire, false);
         }
         break;
      }
      angle = pmo->angle-i*(ANG45/16);
      slope = P_AimLineAttack (player->mo, angle, range);

      if (linetarget)
      {
         P_LineAttack (pmo, angle, range, slope, damage, MOD_HIT, RUNTIME_CLASS(ABulletPuff));
         pmo->angle = R_PointToAngle2 (pmo->x, pmo->y,
            linetarget->x, linetarget->y);

         if (linetarget->player || linetarget->flags3&MF3_ISMONSTER)
         {
            newLife = player->health+(damage*(LifeMulti/100));
            newLife = newLife > 100 ? 100 : newLife;
            pmo->health = player->health = newLife;
         }
         weapon->DepleteAmmo (weapon->bAltFire, false);
         break;
      }
   }
}
[/spoiler]

Edit: Instead of risking a breakage with a float, I'm using a percentage. Crude but it should work
Last edited by TheDarkArchon on Sun Nov 06, 2005 12:46, edited 4 times in total.
User avatar
justin023
Posts: 165
Joined: Wed Sep 21, 2005 10:51
Location: Illinois

Post by justin023 »

Why not add A_CStaffCheck to decorate instead? That is what I would do.
Inuyasha_989
Posts: 60
Joined: Sun Sep 04, 2005 3:05

Post by Inuyasha_989 »

@Graf: I had little idea what I was doing, so I couldnt see a problem, seeing as the codepointer worked all together in a demo wad. And I thought the newlife code was used here: [spoiler]

Code: Select all

if (linetarget->player || linetarget->flags3&MF3_ISMONSTER)
         {
            newLife = player->health+(damage>>4);
            newLife = newLife > 100 ? 100 : newLife;
            pmo->health = player->health = newLife;
         } 
[/spoiler]

Since you're the one who can program, i trust any changes/critcism to the code you may have.

@justin023: I tried that at first, there's some code in there that binds it exclusively to the Serpent Staff. It would at least need to be replicated and tweaked to remove the frame-changing code.
User avatar
TheDarkArchon
Posts: 1000
Joined: Wed Jul 06, 2005 11:58
Location: What's that fucking smell

Post by TheDarkArchon »

The problem is that newlife is overwritten. Which reminds me I forgot do redefine it in the CP in my (already borked) version.
User avatar
justin023
Posts: 165
Joined: Wed Sep 21, 2005 10:51
Location: Illinois

Post by justin023 »

I didn't notice that, but there are only 2 lines that need to be dealt with. Something I think would be cool is an extened a_freezedeathchunks which allows any actor to be spawned insted of IceChunk only. I don't have any certain use for this and don't want to spend a lot of time implementing something I wouldn't use.
Inuyasha_989 wrote:Since you're the one who can program
You're saying I can't?
Inuyasha_989
Posts: 60
Joined: Sun Sep 04, 2005 3:05

Post by Inuyasha_989 »

@justin023: No, since im suggesting it to Graf for GZdoom, he'd be the one i'd ask about first. I'm not saying anything else about anyone :P

EDIT: Nice Avatar btw :lol:

@TDA: I'll compile the code with your changes, and see how it works. And how was it overwritten? I dont know C++ so it wouldnt be apparent to me.
User avatar
TheDarkArchon
Posts: 1000
Joined: Wed Jul 06, 2005 11:58
Location: What's that fucking smell

Post by TheDarkArchon »

Inu: I've made it run as a percentage (Crude but it'll work: I don't know how to define fractional values in C++ so I made an integer which gets divided by 100)
Inuyasha_989
Posts: 60
Joined: Sun Sep 04, 2005 3:05

Post by Inuyasha_989 »

@TDA: There's one problem with your code, it doesnt give you any health when you strike an enemy -_-

With parts of your code, you had Range defined with a capitol R, and newLife with a capitol L, and none of them were cap'd in the rest of the code.

I'll look into it farther and find out why.
Inuyasha_989
Posts: 60
Joined: Sun Sep 04, 2005 3:05

Post by Inuyasha_989 »

*Bump*

So how about it? My code may not be the best, so I suppose you can clean/improve it however.

Return to “Closed Feature Suggestions”