Muzzle Flash Replication

I’m currently trying to add in a muzzle flash effect to a weapon. My mod is for Chivalry: Medieval Warfare, so there’s no pre-existing muzzle flashes in the game. In my WeaponAttachment class I’ve set up the particle system:


class WarWeaponAttachment_Arquebus extends AOCWeaponAttachment_Crossbow ;

var ParticleSystemComponent MuzzleBlast;


simulated function PostBeginPlay()
{
    super.PostBeginPlay();
    OverlayMesh.AttachComponent(MuzzleBlast, 'ramrod_point');

} 

simulated function MuzzleFlash()
{
    MuzzleBlast.ActivateSystem();
    
}
      
DefaultProperties
{
    Begin Object Class=ParticleSystemComponent Name=ParticleSystemComponent0
        Template=ParticleSystem'cove.ParticleSystems.P_cannon-fire'
        Rotation=(Yaw=-16384, Pitch=-16384)
        Translation=(Y=2,X=-1)
        Scale=1.5
        bAutoActivate=false
        End Object
    MuzzleBlast=ParticleSystemComponent0



Then in my Weapon class:



class WarWeapon_Arquebus extends AOCWeapon_Crossbow;

var WarWeaponAttachment_Arquebus ArqAttachment;

simulated function PostBeginPlay()
{
    super.PostBeginPlay();
    
    ArqAttachment = WarWeaponAttachment_Arquebus(AOCWepAttachment);

} 



simulated function Fire()
{
    super.Fire();
        
    ArqAttachment.MuzzleFlash();
    
        Server_ReplicateMuzzleFlash();
        `logalways("Variable flipped...");

    
    MakeNoise(1.0);
}

reliable server function Server_ReplicateMuzzleFlash()
{
    WarPawn(Owner).bIsArqing = !WarPawn(Owner).bIsArqing;

}


Then this “bIsArqing” variable should be replicated to clients and the muzzle flash activated. In Pawn’s ReplicatedEvent:



var repnotify bool bIsArqing;

else if (VarName == 'bIsArquing')
    {
        WarWeaponAttachment_Arquebus(CurrentWeaponAttachment).MuzzleFlash();
        `logalways("Arquebus replicating...");
    }    


However, the bool is not being flipped at all based on my logs. Any ideas on where I’m going wrong with this?

else if (VarName == ‘bIsArquing’) but you have WarPawn(Owner).bIsArqing = !WarPawn(Owner).bIsArqing;

Typo, in the replicated event …?

Hi, fixed that typo. Still getting the same result.

Try adding below - also wouldn’t you need to reset the bool after displaying the flash, in which case you need a test to say only do flash if bool = true or something like that?



reliable server function Server_ReplicateMuzzleFlash()
{
    WarPawn(Owner).bIsArqing = !WarPawn(Owner).bIsArqing;
    
   ReplicatedEvent('bIsArqing');  // add this

}


I tried inserting the ReplicatedEvent code but no luck. I’ve tried rewriting some of the code to try and get it working. It seems to be sending the correct replication data, but it’s still not working.

I now have in my Pawn class:


   else if (VarName == 'bIsArqing')
    {
        ArquebusRep();
        `logalways("ReplicatedEvent");


simulated function ArquebusRep()
{
    local WarWeaponAttachment_Arquebus Arquebus;
    
    Arquebus = WarWeaponAttachment_Arquebus(CurrentWeaponAttachment);
    Arquebus.ActivateMuzzleFlash();
    `logalways("ArquebusRep");
}



In Weapon:



simulated function Fire()
{
    local WarWeaponAttachment_Arquebus ArqAttachment;
    local rotator Aim;
    local Vector RealStartLoc;
    
    `logalways("Fire!");

    //`log("ARE WE LOADED?"@bLoaded);
    if (bLoaded)
    {
        if (!AOCOwner.bIsBot)
        {
            AOCOwner.GetCameraSocketLocationAndRotation(true, RealStartLoc, Aim);
        }
        else
        {
            AOCOwner.GetCameraSocketLocationAndRotation(false, RealStartLoc, Aim);
            Aim = AOCAICombatController(AOCOwner.Controller).GetAim(RealStartLoc);
        }

        if (!AOCOwner.IsFirstPerson() && !AOCOwner.bIsBot)
        {
            Aim = CalcThirdPersonAim(RealStartLoc, Aim);
        }

        AddProjectileSpread(Aim);

        SpawnProjectile( RealStartLoc, Aim.Pitch, Aim.Yaw, Aim.Roll );
        if (WorldInfo.NetMode != NM_Standalone && !AOCOwner.bIsBot && Worldinfo.NetMode != NM_ListenServer)
        {
            Server_SpawnProjectile(RealStartLoc, Aim.Pitch, Aim.Yaw, Aim.Roll);
        }

        enableProjCam();
        //Aim = GetAdjustedAim( RealStartLoc );         // get fire aim direction

        AOCOwner.OnActionInitiated(EACT_RangedWeaponFired);
    }
    
    if(Role == ROLE_Authority)
    {
        ServerArquebusFired();
    }
    else
    {
        ArqAttachment = WarWeaponAttachment_Arquebus(AOCWepAttachment);
        ArqAttachment.ActivateMuzzleFlash();
    }
    
    MakeNoise(1.0);
}

reliable server function ServerArquebusFired()
{
    ForceNetRelevant();
     WarPawn(Owner).bIsArqing = !WarPawn(Owner).bIsArqing;
    ReplicatedEvent('bIsArqing');
    `logalways("ServerArquebusFired");
}


In WeaponAttachment:


 simulated function ActivateMuzzleFlash()
{
    

    `logalways("ActivateMuzzleFlash");

   Overlaymesh.AttachComponenttoSocket(MuzzleBlast, 'ramrod_point');
   MuzzleBlast.ActivateSystem();

}

So after some experimentation I realised the problem was that I was attaching the particlesystemcomponent to Overlaymeshes only - hence, it was replicating properly but just not showing up since other players’ overlaymesh (1p mesh) is hidden for me! I just added in an if statement checking if bFirstperson was true, then attach to OverlayMesh, otherwise just attach to Mesh.