コード例 #1
0
void ASWeaponPickup::OnUsed(APawn* InstigatorPawn)
{
	ASCharacter* MyPawn = Cast<ASCharacter>(InstigatorPawn);
	if (MyPawn)
	{
		/* Fetch the default variables of the class we are about to pick up and check if the storage slot is available on the pawn. */
		if (MyPawn->WeaponSlotAvailable(WeaponClass->GetDefaultObject<ASWeapon>()->GetStorageSlot()))
		{
			FActorSpawnParameters SpawnInfo;
			SpawnInfo.bNoCollisionFail = true;
			ASWeapon* NewWeapon = GetWorld()->SpawnActor<ASWeapon>(WeaponClass, SpawnInfo);

			MyPawn->AddWeapon(NewWeapon);

			Super::OnUsed(InstigatorPawn);
		}
		else
		{
			// TODO - FIXME: Send message request to client.

			ASPlayerController* MyController = Cast<ASPlayerController>(MyPawn->GetController());
			if (MyController)
			{
				ASHUD* MyHUD = Cast<ASHUD>(MyController->GetHUD());
				if (MyHUD)
				{
					MyHUD->MessageReceived("Weapon slot already taken.");
				}
			}
		}
	}
}
コード例 #2
0
/* As with Server side functions, NetMulticast functions have a _Implementation body */
void ASGameState::BroadcastGameMessage_Implementation(const FString& NewMessage)
{
	for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; It++)
	{
		ASPlayerController* MyController = Cast<ASPlayerController>(*It);
		if (MyController && MyController->IsLocalController())
		{
			ASHUD* MyHUD = Cast<ASHUD>(MyController->GetHUD());
			if (MyHUD)
			{
				MyHUD->MessageReceived(NewMessage);
			}
		}
	}
}