Wizzie/HUDRadar
The radar I use for my mod. The function RestartPlayer() in pGameInfo shows how to add an actor to be shown in the radar area. Any kind of actor can be added, not just playerpawns. Hope someone finds it usefull. Enjoy.
pGameInfo.uc
class pGameInfo extends GameInfo; function RestartPlayer( Controller aPlayer ) { super.RestartPlayer( aPlayer ); if( aPlayer != none && aPlayer.Pawn != none ) pGameReplicationInfo(GameReplicationInfo).CreateRadarActor( aPlayer.Pawn, TYPE_PlayerPawn ); } defaultproperties { PlayerControllerClassName = "myMod.pPlayerController" GameReplicationInfoClass = class'pGameReplicationInfo' HUDType = "myMod.pHUDBase" }
pGameReplicationInfo.uc
class pGameReplicationInfo extends GameReplicationInfo; enum EItemType { TYPE_PlayerPawn, TYPE_DeadPawn, }; struct RadarActor { var int PosX; var int PosY; var float Distance; var EItemType ItemType; }; var array<pRadarActor> RadarActorsArray; simulated function PostNetBeginPlay() { local pRadarActor actor; super.PostNetBeginPlay(); ForEach DynamicActors(class'pRadarActor', actor) AddRadarItem( actor ); } function CreateRadarActor( Actor aActor, EItemType ItemType ) { local int i; local pRadarActor RRI; if( !aActor.bDeleteMe ) { for( i=0; i<RadarActorsArray.Length; i++ ) { if( RadarActorsArray[i].Owner == aActor ) return; } RRI = Spawn(class'pRadarActor', aActor,,vect(0,0,0),rot(0,0,0)); if( RRI != none ) RRI.ItemType = ItemType; } } simulated function AddRadarItem( pRadarActor RRI ) { RadarActorsArray[RadarActorsArray.Length] = RRI; } simulated function RemoveRadarItem( pRadarActor RRI ) { local int i; for( i=0 ; i<RadarActorsArray.Length ; i++ ) if( RadarActorsArray[i] == RRI ) break; if( i == RadarActorsArray.Length ) { log("GameReplicationInfo::RemoveRadarItem() RRI="$RRI$" not found.", 'Error'); return; } RadarActorsArray.Remove( i, 1 ); } simulated function Array<RadarActor> GetVisibleRadarActors( Pawn PawnOwner ) { local Array<RadarActor> RadarActors; local RadarActor rActor; local vector OriginLoc, TargetLoc; local rotator OriginRot, TargetRot; local float Distance; local int i, TeamIndex; TeamIndex = PawnOwner.PlayerReplicationInfo.Team.TeamIndex; OriginLoc = PawnOwner.Location * vect(1,1,0); OriginRot = PawnOwner.Rotation; OriginRot.Yaw += 16384; for( i=0; i < RadarActorsArray.length ; i++ ) { if( RadarActorsArray[i].PlayerOwner == PlayerController(PawnOwner.Controller) ) continue; if( TeamIndex == RadarActorsArray[i].TeamIndex || RadarActorsArray[i].TeamIndex == 255 ) { TargetLoc.X = RadarActorsArray[i].RadarLocationX; TargetLoc.Y = RadarActorsArray[i].RadarLocationY; TargetLoc.Z = 0.0; Distance = VSize( OriginLoc - TargetLoc ) * 0.03125; // 2048 units radius viewrange (64/2048=0.03125) if( Distance < 64 ) { TargetRot = rotator( TargetLoc - OriginLoc ); TargetRot.Yaw -= OriginRot.Yaw; TargetLoc = vector( TargetRot ) * Distance; rActor.PosX = TargetLoc.X+64; rActor.PosY = TargetLoc.Y+64; rActor.ItemType = RadarActorsArray[i].ItemType; rActor.Distance = Distance; RadarActors[RadarActors.Length] = rActor; } } } return RadarActors; }
pRadarActor.uc
class pRadarActor extends ReplicationInfo; var float RadarLocationX, RadarLocationY; var byte TeamIndex; var PlayerController PlayerOwner; var pGameReplicationInfo.EItemType ItemType; replication { reliable if( bNetInitial && (Role == ROLE_Authority) ) TeamIndex, PlayerOwner; reliable if( bNetDirty && (Role == ROLE_Authority) ) ItemType; unreliable if( bNetDirty && (Role == ROLE_Authority) ) RadarLocationX, RadarLocationY; } event PostBeginPlay() { local Pawn P; if ( Role < ROLE_Authority ) return; P = Pawn(Owner); if( P != none ) { if( P.Controller != none ) PlayerOwner = PlayerController(P.Controller); if( (P.PlayerReplicationInfo != none) && (P.PlayerReplicationInfo.Team != none) ) TeamIndex = P.PlayerReplicationInfo.Team.TeamIndex; } SetTimer( 1.0/NetUpdateFrequency, true ); } simulated event PostNetBeginPlay() { local pGameReplicationInfo GRI; foreach DynamicActors(class'pGameReplicationInfo',GRI) GRI.AddRadarItem(self); } simulated function Destroyed() { local pGameReplicationInfo GRI; ForEach DynamicActors(class'pGameReplicationInfo',GRI) GRI.RemoveRadarItem(self); Super.Destroyed(); } event Timer() { if( Owner == none ) { Destroy(); return; } RadarLocationX = Owner.Location.X; RadarLocationY = Owner.Location.Y; if( (Pawn(Owner) != none) && (ItemType != TYPE_DeadPawn) && (Pawn(Owner).Health <= 0) ) ItemType = TYPE_DeadPawn; } DefaultProperties { TeamIndex = 255 NetUpdateFrequency = 10.00 }
pHUDBase.uc
class pHUDBase extends HudBase config(User); var Material HUDMaterial1; var Material RadarBase; var globalconfig bool bShowRadar; var globalconfig float RadarPosX; var globalconfig float RadarPosY; simulated function UpdatePrecacheMaterials() { Level.AddPrecacheMaterial(Material'InterfaceContent.HUD.SkinA'); Level.AddPrecacheMaterial(Material'Radar.RadarFinal'); } simulated function DrawHudPassC (Canvas C) { if( bShowRadar ) DrawRadar(C); } simulated function DrawRadar( Canvas C ) { local float DotSize; local int i, Alpha; local pGameReplicationInfo GRI; local Array<pGameReplicationInfo.RadarActor> RadarActors; if( PlayerOwner == none || PawnOwner == none || PawnOwner.PlayerReplicationInfo == none || PawnOwner.PlayerReplicationInfo.Team == none ) return; GRI = pGameReplicationInfo(PlayerOwner.GameReplicationInfo); if( GRI == none ) return; C.SetPos( RadarPosX * C.ClipX, RadarPosY * C.ClipY ); C.DrawTile( RadarBase, 128, 128, 0, 0, RadarBase.MaterialUSize(), RadarBase.MaterialVSize() ); DotSize = 6; RadarActors = GRI.GetVisibleRadarActors( PawnOwner ); for( i=0 ; i<RadarActors.Length ; i++ ) { if( RadarActors[i].Distance < (64-8) ) Alpha = 160; else Alpha = 160*((8-(RadarActors[i].Distance-(64-8)))/8)+1; if( RadarActors[i].ItemType == TYPE_PlayerPawn ) C.DrawColor = C.MakeColor( 255, 255, 255 ); else if( RadarActors[i].ItemType == TYPE_DeadPawn ) C.DrawColor = C.MakeColor( 255, 0, 0 ); C.DrawColor.A = Alpha; C.SetPos( RadarPosX*C.ClipX+RadarActors[i].PosX-0.5*DotSize , RadarPosY*C.ClipY+RadarActors[i].PosY-0.5*DotSize ); C.DrawTile( HUDMaterial1, DotSize, DotSize, 838, 238, 144, 144 ); } } defaultproperties { HUDMaterial1 = Material'InterfaceContent.Hud.SkinA' RadarBase = Material'Radar.RadarFinal' RadarPosX = 0.87 RadarPosY = 0.03 }