For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Can't get weapon change replicated on client.

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
Post Reply
StrikerTheHedgefox
Posts: 4
Joined: Fri May 20, 2022 12:32 am

Can't get weapon change replicated on client.

Post by StrikerTheHedgefox »

Hey, I have this bit of UnrealScript here, and for some reason, this weapon change isn't replicating on clients.

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);
	}
}
This is the function that is supposed to be replicated.

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.
}
ChangeToWeapon does seem to run for the client when the server calls for it, but NewWeapon parameter seems to be "None". This isn't the case on a listen server, just when you're a client or dedicated.

I know I'm doing something wrong, but what?
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Can't get weapon change replicated on client.

Post by []KAOS[]Casey »

are you trying to use a weapon class that is in a separate package or a stock unreal weapon?
StrikerTheHedgefox
Posts: 4
Joined: Fri May 20, 2022 12:32 am

Re: Can't get weapon change replicated on client.

Post by StrikerTheHedgefox »

Custom weapon class.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Can't get weapon change replicated on client.

Post by []KAOS[]Casey »

Is the custom weapon's package in ServerPackages in unreal.ini for the server? If you summon it in game and you can't see it except in listen/offline that would also indicate that it's not in server packages.
StrikerTheHedgefox
Posts: 4
Joined: Fri May 20, 2022 12:32 am

Re: Can't get weapon change replicated on client.

Post by StrikerTheHedgefox »

Yes, it is.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Can't get weapon change replicated on client.

Post by []KAOS[]Casey »

what are your replication statements?

It looks like you're directly editing Pawn.uc from what I see in your functions, or maybe its a game i'm not familiar with
StrikerTheHedgefox
Posts: 4
Joined: Fri May 20, 2022 12:32 am

Re: Can't get weapon change replicated on client.

Post by StrikerTheHedgefox »

Turns out it was something stupid. Needed to add:

Code: Select all

newWeapon.ClientSelectWeapon();
in GiveWeaponTo

Thanks for responding, appreciate it.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Can't get weapon change replicated on client.

Post by []KAOS[]Casey »

Aha, good. I was about to suggest to look at how the best weapon change code works in U1/UT if it continued to not work for you.
Post Reply

Return to “UScript Board”