Home› Unreal Engine

Custom Weapon Healing Help

Alright so I don't know how many of you here are very familiar with Unreal Script but I figured I'd ask anyway. I'm trying to figure out a way to get a weapon to heal people when shot. Negative health doesn't work and I think there's some built in functionality for this already (the link gun can heal vehicles) but I don't know where the code is or how to make use of it.

If any of you can help out that would be great.

Replies

  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    is this going to be some sort of projectile? or just when you'r aiming at them and fire it starts healing
  • Shmaba
    Options
    Offline / Send Message
    Was planning for a projectile but if it's easier to get it to start healing when simply aiming then that would be great too.
  • Slainean
    Options
    Offline / Send Message
    Slainean polycounter lvl 18
    I'm learning UnrealScript, too, and it looks like there are a number of ways to do this.

    If you want to use projectiles, you'll have to create a custom projectile class and then override the ProcessTouch function. If you want to use an instant hit weapon, you can override the ProcessInstantHit function in the weapon class itself.

    I just tested this on an instant hit weapon, and it seems to work:
    simulated function ProcessInstantHit(byte FiringMode, ImpactInfo Impact, optional int NumHits)
    {
    	local Pawn P;
    	
    	if (Impact.HitActor != None && (Impact.HitActor).IsA('Pawn'))
    	{
    	P = Pawn(Impact.HitActor);
    	P.Health += 10;	
    	`Log("***Pawn Health:" @P.Health);
    	}
    }
    

    Every time you shoot the pawn, its health increases by 10. If you only wanted certain classes or subclasses to be healed, you just replace "Pawn" with whichever parent class.

    If you want to use the projectile class instead, you'd write something similar, but replace "Impact.HitActor" with "Other" in the ProcessTouch function. I don't have a projectile weapon setup at the moment, though.
  • Slainean
    Options
    Offline / Send Message
    Slainean polycounter lvl 18
    I looked around some more, and it looks like the LinkGun function you mentioned is called HealDamage in Pawn.uc and Actor.uc.

    So the updated code would look like this:
    simulated function ProcessInstantHit(byte FiringMode, ImpactInfo Impact, optional int NumHits)
    {
    	local Pawn P;
    	
    	if (Impact.HitActor != None && (Impact.HitActor).IsA('Pawn'))
    	{
    	P = Pawn(Impact.HitActor);
    	[b]P.HealDamage(10, Instigator.Controller, InstantHitDamageTypes[1]);[/b]
    	`Log("***Pawn Health:" @P.Health);
    	}
    }
    
    DefaultProperties
    {
    InstantHitDamageTypes(1)=None
    }
    
    The difference is that the function I posted earlier doesn't check if the pawn's health is > 0, and it can heal over the pawn's max health.
  • Shmaba
    Options
    Offline / Send Message
    Cool, that script is working pretty well for my purposes. Thanks a lot Slainean!
Sign In or Register to comment.