Pawn Damage

Ive currently got this code from another thread tried to look over to see if ive missed anything but ill be honest ive only studied unreal script for 5 weeks (this is needed for my assessment at collage) just trying to figure out why my npc isn’t causing any damage.

Pawn:


class Badguy1 extends UTPawn
    placeable;

// members for the custom mesh
var SkeletalMesh defaultMesh;
//var MaterialInterface defaultMaterial0;
var AnimTree defaultAnimTree;
var array<AnimSet> defaultAnimSet;
var AnimNodeSequence defaultAnimSeq;
var PhysicsAsset defaultPhysicsAsset;

var Badguy1Controller MyController;

var float Speed;

var SkeletalMeshComponent MyMesh;
var bool bplayed;
var Name AnimSetName;
var AnimNodeSequence MyAnimPlayControl;

var bool AttAcking;

var () array<NavigationPoint> MyNavigationPoints;

var () float PerceptionDistance<DisplayName=Perception Distance>;   
var () float AttackDistance<DisplayName=Attack Distance>;       
var () int AttackDamage<DisplayName=Attack Damage>;     

var MeleeComponent myHandCollisionL;
var vector SocketLocL;
var rotator SocketRotL;     

defaultproperties
{
    Speed=80
    AnimSetName="ATTACK"
    AttAcking=false

    defaultMesh=SkeletalMesh'My_AnimatedMeshes.ske_Badguy1'
    defaultAnimTree=AnimTree'My_AnimatedMeshes.aTree_Badguy1'
    defaultAnimSet(0)=AnimSet'My_animatedMeshes.ani_Badguy1'
    defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'


    Begin Object Name=WPawnSkeletalMeshComponent
        bOwnerNoSee=false
        CastShadow=true

        //CollideActors=TRUE
        BlockRigidBody=true
        BlockActors=true
        BlockZeroExtent=true
        //BlockNonZeroExtent=true

        bAllowApproximateOcclusion=true
        bForceDirectLightMap=true
        bUsePrecomputedShadows=false
        LightEnvironment=MyLightEnvironment
        //Scale=0.5
        SkeletalMesh=SkeletalMesh'My_AnimatedMeshes.ske_Badguy1'        
            AnimSets(0)=AnimSet'My_animatedMeshes.ani_Badguy1'
        AnimTreeTemplate=AnimTree'My_AnimatedMeshes.aTree_Badguy1'
    End Object

    mesh = WPawnSkeletalMeshComponent

//  Begin Object Name=CollisionCylinder
//      CollisionRadius=+0041.000000
//      CollisionHeight=+0044.000000
//      BlockZeroExtent=false
//  End Object
//  CylinderComponent=CollisionCylinder
//  CollisionComponent=CollisionCylinder

    bCollideActors=true
    bPushesRigidBodies=true
    bStatic=False
    bMovable=True

    bAvoidLedges=true
    bStopAtLedges=true

    LedgeCheckThreshold=0.5f
    
}

simulated function PostBeginPlay()
{
    super.PostBeginPlay();
    //if (Controller == none)
    //  SpawnDefaultController();
    SetPhysics(PHYS_Walking);
    if (MyController == none)
    {
        MyController = Spawn(class'Badguy1Controller', self);
        MyController.SetPawn(self);     
    }

    Mesh.GetSocketWorldLocationAndRotation('LeftHand', SocketLocL, SocketRotL);//'LeftHand' is the name of the socket that you created and named.

    myHandCollisionL=Spawn(class'MeleeComponent',self,,SocketLocL,SocketRotL);

    Attach(myHandCollisionL);

}

function SetAttacking(bool atacar)
{
    AttAcking = atacar;
}



simulated event Tick(float DeltaTime)
{
    local UTPawn gv;

    super.Tick(DeltaTime);
    //MyController.Tick(DeltaTime);

    Mesh.GetSocketWorldLocationAndRotation('LeftHand', SocketLocL, SocketRotL);
    myHandCollisionL.SetLocation(SocketLocL);

    
    //foreach CollidingActors(class'UTPawn', gv, 200) 
    foreach VisibleCollidingActors(class'UTPawn', gv, 100)
    {
        if(AttAcking && gv != none)
        {
            if(gv.Name == 'MyPawn_0' && gv.Health > 0)
            {
                //Worldinfo.Game.Broadcast(self, "Colliding with player : " @ gv.Name);
                gv.Health -= 1;
                gv.IsInPain();
            }
        }
    }
}

simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
{
    Mesh.SetSkeletalMesh(defaultMesh);
    //Mesh.SetMaterial(0,defaultMaterial0);
    Mesh.SetPhysicsAsset(defaultPhysicsAsset);
    Mesh.AnimSets=defaultAnimSet;
    Mesh.SetAnimTreeTemplate(defaultAnimTree);

}

Controller Class


class Badguy1Controller extends AIController;

var Badguy1 MyBadguy1Pawn;
var Pawn thePlayer;
var Actor theNoiseMaker;
var Vector noisePos;

var () array<NavigationPoint> MyNavigationPoints;
var NavigationPoint MyNextNavigationPoint;

var int actual_node;
var int last_node;
var int SightRadius;

var float perceptionDistance;
var float hearingDistance;
var float attackDistance;
var int attackDamage;

var float distanceToPlayer;
var float distanceToTargetNodeNearPlayer;

var Name AnimSetName;

var bool AttAcking;
var bool followingPath;
var bool noiseHeard;
var Float IdleInterval;

defaultproperties
{
        attackDistance = 50
        attackDamage = 1
        hearingDistance = 1000
        perceptionDistance = 1000
    AttAcking = false
    AnimSetName ="ATTACK"
    actual_node = 0
    last_node = 0
    followingPath = true
    noiseHeard =false
    IdleInterval = 2.5f
    SightRadius = 360
}

function SetPawn(Badguy1 NewPawn)
{
        MyBadguy1Pawn = NewPawn;
    Possess(MyBadguy1Pawn, false);
    MyNavigationPoints = MyBadguy1Pawn.MyNavigationPoints;
    AttackDamage = MyBadguy1Pawn.AttackDamage;
    AttackDistance = MyBadguy1Pawn.AttackDistance;
    PerceptionDistance = MyBadguy1Pawn.PerceptionDistance;
}

function Possess(Pawn aPawn, bool bVehicleTransition)
{
    if (aPawn.bDeleteMe)
    {
        `Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
         ScriptTrace();
         GotoState('Dead');
    }
    else
    {
        Super.Possess(aPawn, bVehicleTransition);
        Pawn.SetMovementPhysics();
        
        if (Pawn.Physics == PHYS_Walking)
        {
            Pawn.SetPhysics(PHYS_Falling);
        }
    }
}

function Tick(Float Delta)
{
    //if(IsInState('Attack'))
    //{ 

    //}
    
}

state Idle
{

    event SeePlayer(Pawn SeenPlayer)
    {
        thePlayer = SeenPlayer;
        distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer &lt; perceptionDistance)
        { 
            //Worldinfo.Game.Broadcast(self, "I can see you!!");
            GotoState('Chaseplayer');
        }
    }

Begin:
    Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");

    Pawn.Acceleration = vect(0,0,0);
    MyBadguy1Pawn.SetAttacking(false);

    Sleep(IdleInterval);

    //Worldinfo.Game.Broadcast(self, "!!!!!!!  Going to FollowPath  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    followingPath = true;
    actual_node = last_node;
    GotoState('FollowPath');

}

state Chaseplayer
{
  Begin:
    
    MyBadguy1Pawn.SetAttacking(false);
    Pawn.Acceleration = vect(0,0,1);
    
    while (Pawn != none && thePlayer.Health &gt; 0)
    {
        Worldinfo.Game.Broadcast(self, "I can see you!!");
        
        if (ActorReachable(thePlayer))
        {
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer &lt; attackDistance)
            {
                GotoState('Attack');
                break;
            }
            else //if(distanceToPlayer &lt; 300)
            {
                MoveToward(thePlayer, thePlayer, 20.0f);
                if(Pawn.ReachedDestination(thePlayer))
                {
                    GotoState('Attack');
                    break;
                }
            }
        }
        else
        {
            MoveTarget = FindPathToward(thePlayer,,perceptionDistance + (perceptionDistance/2));
            if (MoveTarget != none)
            {
                //Worldinfo.Game.Broadcast(self, "Moving toward Player");

                distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
                if (distanceToPlayer &lt; 100)
                    MoveToward(MoveTarget, thePlayer, 20.0f);
                else
                    MoveToward(MoveTarget, MoveTarget, 20.0f);  
        
                //MoveToward(MoveTarget, MoveTarget);
            }
            else
            {
                GotoState('Idle');
                break;
            }       
        }

        Sleep(1);
    }
}

state Attack
{
 Begin:
    Pawn.Acceleration = vect(0,0,0);
    MyBadguy1Pawn.SetAttacking(true);
    while(true && thePlayer.Health &gt; 0)
    {   
        Worldinfo.Game.Broadcast(self, "Attacking Player");

        distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer &gt; attackDistance * 2)
        { 
            MyBadguy1Pawn.SetAttacking(false);
            GotoState('Chaseplayer');
            break;
        }
        Sleep(1);
    }
    MyBadguy1Pawn.SetAttacking(false);
    GotoState('Idle');
}


auto state FollowPath
{
    event SeePlayer(Pawn SeenPlayer)
    {
        thePlayer = SeenPlayer;
        distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer &lt; perceptionDistance)
        { 
            //Worldinfo.Game.Broadcast(self, "I can see you!!");
            noiseHeard = true;
            followingPath = false;
            GotoState('Chaseplayer');
        }
    }

 Begin:

    while(followingPath)
    {
        MoveTarget = MyNavigationPoints[actual_node];
        
        if(Pawn.ReachedDestination(MoveTarget))
        {
            //WorldInfo.Game.Broadcast(self, "Encontrei o node");
            actual_node++;
            
            if (actual_node &gt;= MyNavigationPoints.Length)
            {
                actual_node = 0;
            }
            last_node = actual_node;
            
            MoveTarget = MyNavigationPoints[actual_node];
        }   

        if (ActorReachable(MoveTarget))
        {
            //distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
            //if (distanceToPlayer &lt; perceptionDistance / 3)
            //  MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);    
            //else
                MoveToward(MoveTarget, MoveTarget); 
        }
        else
        {
            MoveTarget = FindPathToward(MyNavigationPoints[actual_node]);
            if (MoveTarget != none)
            {
                
                //SetRotation(RInterpTo(Rotation,Rotator(MoveTarget.Location),Delta,90000,true));
                
                MoveToward(MoveTarget, MoveTarget);
            }
        }

        Sleep(1);
    }
}

defaultproperties usually goes at the end of all the code. A ‘College Assessment’ so what did they teach you I wonder… but they make you a scavenger. I’m cynical about Colleges.

nvm, my attack code isn’t in a State like yours, but you could incorporate it into a State.

Previous code in below’s monster directs the monster to a player, finally the monsters touches (bumps) a player.



based on 'The Agent's' code, which enlightened me to the bump thing.

the monster's Pawn code:

var KFZPawn HitPawn;  <--the inital var referring the monster's code to the player's pawn code.

simulated event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal ) //Bump event is only called for KActorFromStatic if Other is a Pawn
{
   if(Other.IsA('KFZPawn'))
   {
      HitPawn = KFZPawn(Other);
      PlaySound(SpidAttackSound);   <-- make an evil attack noise
      FullBodyAnimSlot.PlayCustomAnim('SpidAttack1', 1.0, 0.2, 0.2, false, TRUE);  <- FullBodyAnimSlot in my PostInitAnimTree(SkeletalMeshComponent SkelComp) in the same code (this Spid monster Pawn) in accordance with the setup in my Animtree.   'SpidAttack1' is an anim of the monster
      SetTimer(0.3, false, 'SwingArms'); <- wait .3 and go to SwingArms Function
   }
}

function SwingArms()
{
   FullBodyAnimSlot.PlayCustomAnim('SpidAttack1', 1.0, 0.2, 0.2, false, TRUE);
   HitPawn.TakeDamage(10, KFZzyborgController(Controller), Location, vect(0,0,0), class'DmgType_Crushed');  <-HitPawn, the Player TakeDamage 10.  Take it in your centre 0.0.0. And use damage type crushed.
}

----- also from the monster's code, which refers to my monster's animTree

simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
{
	super.PostInitAnimTree(SkelComp);

	if (SkelComp == Mesh)
	{
		FullBodyAnimSlot = AnimNodeSlot(Mesh.FindAnimNode('FullBodySlot'));
		TopHalfAnimSlot = AnimNodeSlot(Mesh.FindAnimNode('TopHalfSlot'));
	}
}


yeah my collage sadly doesn’t have a unreal script programmer there it has a kismet programmer none the less but so far hasn’t been much help hence why im asking on here, ill try and incorporate your code and get back to you on it i have a feeling it might not work for what im looking for as the player of my game is likely to stand still and fight rather then moving around nether the less ill test it and get back to you thanks =3