# Server Function Containing Timers

**URL:** <https://forums.unrealengine.com/t/server-function-containing-timers/305620>\
**Category:** Character & Animation\
**Tags:** timer, unreal-engine, CPP, question\
**Created:** [February 1, 2015, 6:15am UTC](https://forums.unrealengine.com/t/server-function-containing-timers/305620 "2015-02-01T06:15:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Janyx](https://forums.unrealengine.com/u/Janyx)\
**Post date:** [February 1, 2015, 6:15am UTC](https://forums.unrealengine.com/t/server-function-containing-timers/305620/1 "2015-02-01T06:15:29Z")

</div>

I am running into a interesting situation and was wondering if anyone else has figured a better way to do this. I have a function, “EquipWeapons()”, and if Role \< ROLE\_Authority then I call

```
	UFUNCTION(reliable, server, WithValidation)
	void ServerEquipWeapon(class AArenaRangedWeapon* ToEquip, class AArenaRangedWeapon* ToUnEquip, bool IsEnteringCombat);

```

ServerEquipWeapon() has two GetWorldTimerManager().SetTimer(…) in the function call. What I have noticed is that the client won’t perform the function until the server is done running it. So oh the servers side, they see the character immediately equip the weapon but on the client side, the character stands around and as soon as the server is done, he equips the weapon.

Any found a way to avoid this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Duncan\_Dam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duncan\_Dam](https://forums.unrealengine.com/u/Duncan_Dam)\
**Post date:** [February 1, 2015, 6:49am UTC](https://forums.unrealengine.com/t/server-function-containing-timers/305620/2 "2015-02-01T06:49:56Z")

</div>

can you put the code where u call function here ? your description kind of confused. ServerEquipWeapon is called on client and the ServerEquipWeapon\_Implemenation will run on server, so i don’t know where u put your timer

---

<div class="post-metadata">

**Author:** ![Janyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Janyx](https://forums.unrealengine.com/u/Janyx)\
**Post date:** [February 2, 2015, 8:59am UTC](https://forums.unrealengine.com/t/server-function-containing-timers/305620/3 "2015-02-02T08:59:11Z")

</div>

Of course sorry about the confusion, here are the functions in call order. Basically what I am doing is I first check if the player is entering combat, if so I just equip the main weapon. If the player is already in combat (meaning they have a weapons equipped) I first unequip the main weapons and once that action/animation is over I equip the off weapon.

```
void AArenaCharacter::EquipWeapon(AArenaRangedWeapon* ToEquip, AArenaRangedWeapon* ToUnEquip, bool IsEnteringCombat)
{
	if (ToEquip)
	{
		if (Role == ROLE_Authority)
		{
			if (IsEnteringCombat == true)
			{
				SetCurrentWeapon(ToEquip, ToUnEquip);
				FinishEquipWeapon();
			}
			else
			{
				SetCurrentWeapon(ToEquip, ToUnEquip);
				StartEquipWeapon();
				GetWorldTimerManager().SetTimer(this, &AArenaCharacter::FinishEquipWeapon, 1.5f, false);
			}
		}	
		else
		{
			ServerEquipWeapon(ToEquip, ToUnEquip, IsEnteringCombat);
		}
		IsEnteringCombat = false;
	}
}

```

So if this was initiated by the client, the logic is passed off for the server:

```
bool AArenaCharacter::ServerEquipWeapon_Validate(AArenaRangedWeapon* ToEquip, AArenaRangedWeapon* ToUnEquip, bool IsEnteringCombat)
{
	return true;
}

void AArenaCharacter::ServerEquipWeapon_Implementation(AArenaRangedWeapon* ToEquip, AArenaRangedWeapon* ToUnEquip, bool IsEnteringCombat)
{
	EquipWeapon(ToEquip, ToUnEquip, IsEnteringCombat);
}

```

The above basically just calls the same function but on the server. The last call happens inside “StartEquipWeapon()” which calls the following function in the weapon calss:

```
void AArenaRangedWeapon::OnHolster(bool IsPrimary)
{
	if (MyPawn)
	{
		// For locally controller players we attach both weapons and let the bOnlyOwnerSee, bOwnerNoSee flags deal with visibility.
		FName AttachPoint;
		if (IsPrimary == true)
		{
			bPendingHolster = true;

			float Duration = PlayWeaponAnimation(HolsterAnim);
			if (Duration <= 0.0f)
			{
				Duration = 0.5f;
			}
			GetWorldTimerManager().SetTimer(this, &AArenaRangedWeapon::OnHolsterPrimary, FMath::Max(0.1f, Duration - 0.70f), false);
		}
		if (IsPrimary == false)
		{
			bPendingHolster = true;

			float Duration = PlayWeaponAnimation(HolsterAnim);
			if (Duration <= 0.0f)
			{
				Duration = 0.5f;
			}
			GetWorldTimerManager().SetTimer(this, &AArenaRangedWeapon::OnHolsterSecondary, FMath::Max(0.1f, Duration - 0.70f), false);
		}
	}
}
```

---

<div class="post-metadata">

**Author:** ![Janyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Janyx](https://forums.unrealengine.com/u/Janyx)\
**Post date:** [February 2, 2015, 8:59am UTC](https://forums.unrealengine.com/t/server-function-containing-timers/305620/4 "2015-02-02T08:59:56Z")

</div>

Sorry I had to post my reply as an answer to the question since it was too long to be submitted as a comment.
