UE3 - UT3 Making more than 2 firemodes for a weapon

  • 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.

daniellleon

New Member
Oct 31, 2009
5
0
0
I am trying to make my own custom weapon, which will need up to 6 firemodes.

I been told that I have to modify the Inventory Manager class, and the PlayerController class to succefully implement the weapon with 6 firemodes.

The inventory manager will be needed to properly trigger the the Start Fire function.

The player controller will be needed so I can properly bind 4 additional keys to select the last 4 fire modes

The first two fire modes I am keeping them standard and using Fire, and Alt Fire

This is the code I have so far....

------------------------------------Pawn---------------------------------------
Code:
class premPawn extends UTPawn;
var bool bOwnGun;

function Reward()
{
	local premPawn G;
	local Inventory I;
	bOwnGun = true;
	G = premPawn(Instigator);
 I = spawn(class'Sword');			// makes the sword part of the inventory
	if (G != none)
	{
		I.GiveTo(G);				// assigns the weapon to pawn G
		I.AnnouncePickup(G);        // announces that pawn G has pick up the weapon
	}
}

DefaultProperties
{
	bOwnGun = false;
}
------------------------------------Weapon------------------------------------
Code:
class Sword extends UTWeap_ImpactHammer;

//local premInventory I;
//I = premInventory(Instigator.InvManager);
//local PlayerControlExt PC;
//PC = PlayerControlExt(Instigator.Controller);

function CustomFire0()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntA', -1);
}

function CustomFire1()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntB', -1);
}

function CustomFire2()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntC', -1);
}

function CustomFire3()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntD', -1);
}

function CustomFire4()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntE', -1);
}

function CustomFire5()
{
    local premPawn P;
    P = premPawn(owner);
    P.PlayEmote('TauntF', -1);
}

simulated function CustomFire()
{
    switch(CurrentFireMode)
    {
        case 0:
            CustomFire0();
            break;
        case 1:
            CustomFire1();
            break;
        case 2:
            CustomFire2();
            break;
        case 3:
            CustomFire3();
            break;
        case 4:
            CustomFire4();
            break;
        case 5:
            CustomFire5();
            break;
        default:
            CustomFire0();
            break;
    }
    Super.CustomFire();
}

simulated function DrawSphere()             // this function is not currently in use
{                                           		// this function will be used to calculate the range damage of each attack
    local premPawn P;
	local premPawn SpecialPawn;
	ForEach DynamicActors(class 'premPawn', P)
	{
	   if (P.PlayerReplicationInfo != none)
	   {
		  SpecialPawn = P;
	   }
	}
    SpecialPawn.DrawDebugSphere(SpecialPawn.Location,60.0f,10,0,255,1);
    //SpecialPawn.DrawDebugSphere(RealImpact.HitLocation,20.0f,10,0,255,1);
}

simulated function Tick(float DeltaTime)
{
    //DrawSphere();
    Super.Tick(DeltaTime);
}

DefaultProperties
{
WeaponFireTypes(0)= EWFT_Custom
	WeaponFireTypes(1)= EWFT_Custom
    	WeaponFireTypes(2)= EWFT_Custom
    	WeaponFireTypes(3)= EWFT_Custom
    	WeaponFireTypes(4)= EWFT_Custom
    	WeaponFireTypes(5)= EWFT_Custom
	InventoryGroup = 4		// assigns the sword to the 4 slot in the player's inventory.
}
----------------------------Inventory Manager-------------------------
Code:
class premInventory extends InventoryManager;

function StartFire2(byte FireModeNum)
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StartFire(2);
	}
}

function StopFire2( byte FireModeNum )
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StopFire(2);
	}
}

function StartFire3(byte FireModeNum)
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StartFire(3);
	}
}

function StopFire3( byte FireModeNum )
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StopFire(3);
	}
}

function StartFire4(byte FireModeNum)
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StartFire(4);
	}
}

function StopFire4( byte FireModeNum )
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StopFire(4);
	}
}

function StartFire5(byte FireModeNum)
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StartFire(5);
	}
}

function StopFire5( byte FireModeNum )
{
    if( Instigator.Weapon != None )
	{
		Instigator.Weapon.StopFire(5);
	}
}

DefaultProperties
{
}
-------------------------------Player Controller-------------------------
Code:
class PlayerControlExt extends PlayerController;

//Declarations
var bool bStartFire0;
var bool bStartFire1;
var bool bStartFire2;
var bool bStartFire3;
var bool bStartFire4;
var bool bStartFire5;

exec function StartFire( optional byte FireModeNum )
{
     `log("Start Attack Mode 1");
     bStartFire0 = true;
     super.StartFire(FireModeNum);
}

exec function StopFire( optional byte FireModeNum )
{
	bStartFire0 = false;
	super.StopFire(FireModeNum);
}

exec function StartAltFire( optional Byte FireModeNum )
{
     `log("Start Attack Mode 2");
     bStartFire1 = true;
     super.StartFire(FireModeNum);
}

exec function StopAltFire( optional byte FireModeNum )
{
	bStartFire1 = false;
	super.StopAltFire(FireModeNum);
}

//Attack Mode 3
exec function StartFire2( optional byte FireModeNum )
{
     `log("Start Attack Mode 3");
     bStartFire2 = true;
     StartFire( 2 );
}

exec function StopFire2( optional byte FireModeNum )
{
     bStartFire2 = false;
     StopFire( 2 );
}

//Defensive Mode 1
exec function StartFire3( optional byte FireModeNum )
{
     `log("Start Attack Mode 4");
     StartFire( 3 );
     bStartFire3 = true;
}

exec function StopFire3( optional byte FireModeNum )
{
     bStartFire3 = false;
     StopFire( 3 );
}

//Defensive Mode 2
exec function StartFire4( optional byte FireModeNum )
{
      `log("Start Attack Mode 5");
     StartFire( 4 );
     bStartFire4 = true;
}

exec function StopFire4( optional byte FireModeNum )
{
     bStartFire4 = false;
     StopFire( 4 );
}

//Defensive Mode 3
exec function StartFire5( optional byte FireModeNum )
{
      `log("Start Attack Mode 6");
     StartFire( 5 );
     bStartFire5 = true;
}

exec function StopFire5( optional byte FireModeNum )
{
     bStartFire5 = false;
     StopFire( 5 );
}

DefaultProperties
{
}

I think the way I have modify each class should work, but I do not know how to use my modify Inventory Manager and Player Controller class correctly.

var premInventory Invent;
Invent = premInventory(Instigator.InvManager);

var PlayerControlExt PC;
PC = PlayerControlExt(Instigator.Controller);

I am using those line to establish an instance of each class, but then I do not know how to use them or in which file to use them.

For example, I will need to use the "Invent" variable, and call what?

Invent."no clue what to type here"();

and where would I call such command.

Thank you very much for whatever help anybody can offer.
 
Last edited by a moderator:

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Dumb question, but why do you declare multiple exec functions for starting and stopping fire, with each of them taking a parameter for specifying a fire mode number? Isn't that fire mode number exactly what you want to pass to the weapon so it knows which fire mode to use?
 

daniellleon

New Member
Oct 31, 2009
5
0
0
As far as the player controller modifications

The only thing i am adding are these variables

var bool bStartFire0;
var bool bStartFire1;
var bool bStartFire2;
var bool bStartFire3;
var bool bStartFire4;
var bool bStartFire5;

seems useless on its own, but I will need these variables later on to tell the enemy AI, what type of attack the player is doing and be able to react to them correctly.

To further explain what I am doing. I am creating a melee combat system. The weapon will be a sword, and each fire mode will perform a different attack or defense.

the first 3 fire modes are attacks and the last 3 are defenses. Therefore I need some type of variable to keep track of what attack the player is doing so the the AI bot can know which defense to counter attack with.

By the way thank you for organizing the display of my code into different windows, and thank you for any help you can provide.
 
Last edited:

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
InventoryManager has the variable "PendingFire", which is a dynamic int array. There's one entry for every fire mode, value 0 means "not firing", other values mean "currently firing".
 

daniellleon

New Member
Oct 31, 2009
5
0
0
Finally manage to figure it out.

For anybody out there that tries to do something similar.

Dont pay attention to whatever I did with the Inventory Manager, and the Player Controller classes. None of it was necesary.

Inventory Manager does need to be modify a bit though, but the only modification is the following... extend the inventory manager class and in the default property section type:

PendingFire(0)=0
PendingFire(1)=0
PendingFire(2)=0
PendingFire(3)=0
PendingFire(4)=0
ect

depending how many firemodes your weapon will have

Then to use your own version of Inventory Manager, go to your Pawn class and on the default property section type:

InventoryManagerClass=class'YourInventoryManageryName'

Then the major coding change comes to your weapon class you are modifying

On your weapon class default properties type:

Code:
    ShotCost(2)=1
    ShotCost(3)=1
    ShotCost(4)=1
    ShotCost(5)=1
    MinReloadPct(2)=0.600000
    MinReloadPct(3)=0.600000
    MinReloadPct(4)=0.600000
    MinReloadPct(5)=0.600000
    EffectSockets(2)="MuzzleFlashSocket"
    EffectSockets(3)="MuzzleFlashSocket"
    EffectSockets(4)="MuzzleFlashSocket"
    EffectSockets(5)="MuzzleFlashSocket"

    WeaponFireAnim(2)="WeaponFire"
    WeaponFireAnim(3)="WeaponFire"
    WeaponFireAnim(4)="WeaponFire"
    WeaponFireAnim(5)="WeaponFire"
    ArmFireAnim(2)="WeaponFire"
    ArmFireAnim(3)="WeaponFire"
    ArmFireAnim(4)="WeaponFire"
    ArmFireAnim(5)="WeaponFire"

    WeaponIdleAnims(2)="WeaponIdle"
    ArmIdleAnims(2)="WeaponIdle"
    WeaponIdleAnims(3)="WeaponIdle"
    ArmIdleAnims(3)="WeaponIdle"
    WeaponIdleAnims(4)="WeaponIdle"
    ArmIdleAnims(4)="WeaponIdle"
    WeaponIdleAnims(5)="WeaponIdle"
    ArmIdleAnims(5)="WeaponIdle"

    WeaponFireSnd(2)=None
    WeaponFireSnd(3)=None
    WeaponFireSnd(4)=None
    WeaponFireSnd(5)=None

    ShouldFireOnRelease(2)=0
    ShouldFireOnRelease(3)=0
    ShouldFireOnRelease(4)=0
    ShouldFireOnRelease(5)=0
    FiringStatesArray(2)="WeaponFiring"
    FiringStatesArray(3)="WeaponFiring"
    FiringStatesArray(4)="WeaponFiring"
    FiringStatesArray(5)="WeaponFiring"
    WeaponProjectiles(2)=None
    WeaponProjectiles(3)=None
    WeaponProjectiles(4)=None
    WeaponProjectiles(5)=None
    FireInterval(2)=1.000000
    FireInterval(3)=1.000000
    FireInterval(4)=1.000000
    FireInterval(5)=1.000000
    Spread(2)=0.000000
    Spread(3)=0.000000
    Spread(4)=0.000000
    Spread(5)=0.000000
    InstantHitDamage(2)=0.000000
    InstantHitDamage(3)=0.000000
    InstantHitDamage(4)=0.000000
    InstantHitDamage(5)=0.000000
    InstantHitMomentum(2)=0.000000
    InstantHitMomentum(3)=0.000000
    InstantHitMomentum(4)=0.000000
    InstantHitMomentum(5)=0.000000
    InstantHitDamageTypes(2)=Class'Engine.DamageType'
    InstantHitDamageTypes(3)=Class'Engine.DamageType'
    InstantHitDamageTypes(4)=Class'Engine.DamageType'
    InstantHitDamageTypes(5)=Class'Engine.DamageType'

    WeaponFireTypes(0)= EWFT_Custom
    WeaponFireTypes(1)= EWFT_Custom
    WeaponFireTypes(2)= EWFT_Custom
    WeaponFireTypes(3)= EWFT_Custom
    WeaponFireTypes(4)= EWFT_Custom
    WeaponFireTypes(5)= EWFT_Custom

You will need one for every additional firemode you have

Last, but not least remember to modify your .ini files if you wish to assign a different key for each firemode you have create.
 

BSPdom

New Member
Dec 5, 2009
1
0
0
Input.ini key binds

Thanks daniellleon for posting your finds, I've found it really useful! One question though, by what name do you call the extra fire modes in the input ini file? The default fire modes are called by "StartFire" and "StartAltFire", do I have to define my own, because I've tried a variety of combinations and have come up with nothing so far! I appreciate whatever help anyone can offer, thank you.
 

ShadowsWar

New Member
Nov 30, 2008
76
0
0
good deal man, thanks for the help, I was thinking in doing something like that to XD, just didn't know how =P

And I think that another way of doing the different attacks maybe be by doing something like if the player shot and is moving forward then it would give a attack, if he is moving backwards then would give another(i thing ou do that by using ragdoll or something like that)

A different ideia would be combos, so if the player use Fire, then it make a +1 combo, so if he keeps using Fire and doing +1 combos after then he can use altFire and the altfire would see how many combos the player has and call a different attack based on the numbers of combo ^^
But again, just some ideas ^^

Also, I remember the....Unreal Forever Tournament(and the 2k4 version), they had a weapon that used the 2 firemodes, like, if you press Fire and press altFire, then you would do another firemode....just don't know how they coded that, but was a interesting stuff, and in my opinion it would be nice to put something like that in a melee would be nice.
 

chathura

New Member
Sep 5, 2010
6
0
0
hey this is great...
i also want to create a sword.. but i am so stuck.. i got the source code for impact hammer from a website. bt its not working. i think its because i dont have those Skeletal Meshes and all those stuff included in the code.. :(
can u please tell me where to learn about the unreal classes or can u help me to understand and extend the UTWeapon by my self.. i am very new to UDK.
i dont know what some keywords mean(Instigater, Pawn, KillStatName...etc.)
please someone help me.....