Message displays on wrong HUDMutator

Discussions about Coding and Scripting
Bloeb
Experienced
Posts: 95
Joined: Tue Apr 06, 2010 11:07 am

Message displays on wrong HUDMutator

Post by Bloeb »

I'm workin on an objective-system for my BunnyTtrack-map. I would like to add an extended HUD. The HUD should provide additional information about the objectives. At first it seems to work. The BTME_Mutator spawns a SpawnNotifier. The SpawnNotifier spawns a HUDMutator for every player. I've created a BTME_MessageEvent-actor. When this actor is triggered it should display a message on the correct HUD. However, when I loop over all BTME_HUDMutators it can only find the first registered HUD. Therefor it displays the message on the wrong HUD (or not at all If I check the HUD-PlayerOwner against the EventInstigator). Hope someone can shed some light this exact problem.

BTME_Mutator:

Code: Select all

simulated function PreBeginPlay()
{
	...

	if (bMutatorInit) return;

	bMutatorInit = True;

	Spawn(Class'BTME_SpawnNotify');

	...
}
BTME_SpawnNotify:

Code: Select all

class BTME_SpawnNotify extends SpawnNotify;

simulated event Actor SpawnNotification(actor Actor)
{
	local BTME_HUDMutator tempHUD;

	if (Actor!=None && Actor.IsA('HUD') && (HUD(Actor).HUDMutator == None || !HUD(Actor).HUDMutator.IsA('BTME_HUDMutator')))
	{
		tempHUD = Spawn(class'BTME_HUDMutator', Actor);

		if (tempHUD != None)
		{
			tempHUD.PlayerOwner = PlayerPawn(Actor.Owner);

			if (HUD(Actor).HUDMutator == None)
			{
				HUD(Actor).HUDMutator = tempHUD;
			}
			else
			{
				tempHUD.NextHUDMutator = HUD(Actor).HUDMutator;
				HUD(Actor).HUDMutator = tempHUD;
			}
		}
	}

	return Actor;
}
BTME_HUDMutator:

Code: Select all

class BTME_HUDMutator extends Mutator;

var PlayerPawn PlayerOwner;
var HUD MyHUD;

var bool bNewMessage;
var BTME_MessageEvent MessageEvent;


simulated function PostRender(Canvas C)
{

	PlayerOwner = C.Viewport.Actor;

	if ( PlayerOwner != None ) MyHUD = PlayerOwner.myHUD;
 
	if ( NextHUDMutator != None ) NextHUDMutator.PostRender(C);


	if(bNewMessage)
	{
		MessageEvent.DrawMessage(C);
	}

}
BTME_MessageEvent:

Code: Select all


class BTME_MessageEvent extends Trigger;


function Trigger(Actor Other, Pawn EventInstigator)
{
	local int Index;

	foreach AllActors(Class'BTME_HUDMutator',HUDMutator)
	{
		//if(HUDMutator.PlayerOwner==EventInstigator)
		//{
			HUDMutator.bNewMessage = true;
			HUDMutator.MessageEvent = Self;
		//}
		Pawn(Other).ClientMessage(HUDMutator.PlayerOwner.PlayerReplicationInfo.PlayerName);
	}
}

function UnTrigger(Actor Other, Pawn EventInstigator)
{
	foreach AllActors(Class'BTME_HUDMutator',HUDMutator)
	{
		if(HUDMutator.PlayerOwner==EventInstigator)
		{
			HUDMutator.bNewMessage = false;
			HUDMutator.MessageEvent = None;
		}
	}
}

simulated function DrawMessage(Canvas C)
{
	local int Index;

	... draw stuff on the canvas
}
... and happy christmass to everyone :tongue:
Bloeb
Experienced
Posts: 95
Joined: Tue Apr 06, 2010 11:07 am

Re: Message displays on wrong HUDMutator

Post by Bloeb »

I've tried it a different way, but that doesn't work either. I think I'm not registering the HUDMutator correctly, but when I draw something directly using PostRender it shows up on every client.

Code: Select all

function Trigger(Actor Other, Pawn EventInstigator)
{
	local int Index;
	local Mutator HM;

	if(EventInstigator.IsA('PlayerPawn'))
	{
		for (HM = PlayerPawn(EventInstigator).myHUD.HUDMutator; HM != None; HM = HM.NextHUDMutator)
		{
			if(HM.IsA('BTME_HUDMutator'))
			{
				BTME_HUDMutator(HM).bNewMessage = true;
				BTME_HUDMutator(HM).MessageEvent = Self;
			}
		}
	}
}
edit:
After some more testing it seems that PlayerPawn(EventInstigator).myHUD==None for all clients but the server-starter.

edit2:
I've found two ways to hack around this issues:
1. Use Pickups as messages and loop over all ChildActors from the PostRender-function in the HUDMutator
2. When I subclass a LocalMessage I can overload the ClientReceive-function and luckily PlayerPawn.myHUD!=None for all clients.

Offcourse I still like to know why the other method doesn't work and why myHUD==None for all clients but the server-starter.