This is called from the server, from an event called "AcceptInventory":
Code: Select all
function GiveWeaponTo( pawn InventoryPawn, class<Weapon> WeapClass, optional bool bForceSwitch )
{
local Weapon newWeapon;
local Inventory Inv;
Log("GameInfo.uc (GiveWeaponTo) - Attempting to add weapon: " $ WeapClass.name);
// Check to see if we already have that weapon.
Inv = InventoryPawn.FindInventoryType( WeapClass );
if ( Inv != None )
return;
// Add the weapon to the player's inventory list.
newWeapon = Spawn( WeapClass );
if( newWeapon != None )
{
newWeapon.GiveTo( InventoryPawn );
if ( bForceSwitch )
InventoryPawn.ChangeToWeapon( newWeapon );
Log("GameInfo.uc (GiveWeaponTo) - Added weapon: " $ newWeapon.class.name);
}
}
Code: Select all
simulated function ChangeToWeapon( Weapon NewWeapon )
{
Log("Pawn.uc (ChangeToWeapon) - Attempting to change to: " $ NewWeapon.class.name);
// Can't switch if we are in stasis.
if ( GetControlState() == CS_Stasis )
return;
// Can't switch if weapons are inactive.
if ( !bWeaponsActive && (NewWeapon != None) && !NewWeapon.bUseAnytime )
return;
// We can't switch to the current weapon.
if ( NewWeapon == Weapon )
return;
// We can't change to the weapon if ammotype or owner replication hasn't arrived.
if ( (NewWeapon != None) && ((NewWeapon.Instigator == None) || (NewWeapon.AmmoType == None)) )
{
// Wait for the replication data to arrive. This usually is the next frame.
NewWeapon.GotoState('WaitingForReplication');
return;
}
// Keep track of the weapon we are switching to.
// This is the only place PendingWeapon should ever be set on client.
PendingWeapon = NewWeapon;
if ( (Weapon == None) || (Weapon.GetStateName() == 'DownWeapon') || (Weapon.GetStateName() == 'Waiting') )
{
// In this case, just switch.
if ( Level.NetMode == NM_Client )
FinishWeaponChange();
// Tell the server.
if ( Level.NetMode != NM_Client )
ServerChangeToWeapon( NewWeapon );
}
else if ( Level.NetMode == NM_Client )
{
// Put down the current weapon.
Weapon.PutDown();
}
else
{
// Do a server side or singleplayer change.
ServerChangeToWeapon( NewWeapon );
}
// If we are a client, delay telling server until change is finished.
// Otherwise, the weapon variable might be repliated before the animation and state change is finished.
}
I know I'm doing something wrong, but what?