Creating a Pain Causing Volume...

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Silver5123

New Member
Sep 14, 2003
12
0
0
Creating a Custom Damage Causing Volume...

Hi,

I wanted to create a new damage causing volume, because the PhysicsVolume with bPainCausing set to true wasn't exactly what I needed. I needed something that would deal a set amount of damage with an optional set time of "safety" to be in the volume, and that could be optionally repeated on a set interval. So this is what I created:

Code:
class HurtVolume extends PhysicsVolume;

var() int iDamage;
var() int iStun;
var() bool bDelayedDamage;
var() bool bRepeatDamage;
var() float fDelayTime;
var() float fDamageIntervalTime;
var array<Pawn> TouchingPawns;
var array<float> TimeLeft;

event PawnEnteredVolume(Pawn Other)
{
    Log("Entered!");

    if (bDelayedDamage)
    {
        TimeLeft.Insert(TimeLeft.Length, 1);
        TouchingPawns.Insert(TouchingPawns.Length, 1);
        TimeLeft[TimeLeft.Length - 1] = fDelayTime;
        TouchingPawns[TouchingPawns.Length - 1] = Other;
    }
    else
    {
        Other.TakeDamage(iDamage, iStun, Other, Other.Location, ((Other.Location - Location) * 0.25), 0);
        if (bRepeatDamage)
        {
            TimeLeft.Insert(TimeLeft.Length, 1);
            TouchingPawns.Insert(TouchingPawns.Length, 1);
            TimeLeft[TimeLeft.Length - 1] = fDamageIntervalTime;
            TouchingPawns[TouchingPawns.Length - 1] = Other;
        }
    }
}

function Tick(float DeltaTime)
{
   local int i;

    for(i = 0; i < TouchingPawns.Length; i++)
    {
        TimeLeft[i] -= DeltaTime;
        Log("Time Left Til Damage: " @ string(TimeLeft[i]));

        if (TimeLeft[i] < 0)
        {
            CauseDamage(i);

            Log("Causing Damage!");
        }
    }
}

function CauseDamage(int PawnIndex)
{
   Causes Damage to the Pawn TouchingPawns[PawnIndex]
   If bRepeatDamage is true, it adds fDamageIntervalTime to TimeLeft[PawnIndex]
}

defaultproperties
{
    iDamage = 100
    iStun = 100
    fDelayTime = 0
    fDamageIntervalTime = 0
    bCollideActors = true
    bDelayedDamage = false
    bRepeatDamage = false
}

It works if bDelayedDamage is false (it logs "Entered" and it does deal the damage), but when its true, it never deals damage. I have tested it in both Single Player and Multiplayer, but either way, it doesn't work if bDelayedDamage is true.

I added in the Logs to check which parts are not working.

When I enter it, it does log "Entered!", but past that, it will not Log anything else or do anything else, most specifically, the things in the Tick() function. No matter how much I stay still, move around, or anything, all it does is log "Entered!". It never logs how much time is left, deals damage, or logs that damage is going to be taken.

I think it might be either something in the Tick() function, or I am using the Array's wrong, since I haven't ever used them before.

Thanks in advance.
 
Last edited: