Team effects in Monsterhunt
Posted: Thu Feb 04, 2016 12:34 am
I messed around with this for weeks but I didn't find a working solution yet: For my Monsterhunt server I would like if the players can use the visual and acoustical effects like in team games - different colors for skin, HUD, the Glow of TranslocatorTarget (and everything else that have not come to my mind in this moment). The matching voice effects ("Red leader, I'm in position", "Blue leader...", ...) would be nice also. Furthermore the client should store this team assignment persistently and restores it at login.
I tried different approaches:
1) Just use the "real" team (0-3) instead of the team 0 that is usually used in MH. But there I have to hack the damage code including teleport fragging, "repair" enemy seeking rockets and probably some more stuff. Because I guess there are lots of maps outside that rely on players team=0 (eg TeamMonsters.u) this would break compatibility also. Bad approach.
2) Introducing a new storage ("VirtualTeam") for the team the player has chosen. Setting player's skin to that virtual team color is no problem in function AddToTeam() of a subclassed GameInfo. In the beginning I've put this variable "VirtualTeam" into a sub class of PlayerReplicationInfo and this has worked so far - with the disadvantage that this information is lost after logout (what happens with every map change). Because I need code to store the content of that variable at the client - preferably in USER.INI -, I decided to create a sub class of ReplicationInfo ("PlayerClientInfoSB") and have my stuff there instead of in PlayerReplicationInfoSB directly. PlayerReplicationInfoSB then only holds a reference to that class. But I didn't get it managed to store the VirtualTeam number in client's USER.INI nor having a manual set value replicated to server.
I followed these instructions: https://wiki.beyondunreal.com/Legacy:Ne ... _Variables and studied https://wiki.beyondunreal.com/Legacy:Re ... d_Function and nearly all stuff that is referenced by https://wiki.beyondunreal.com/Legacy:Replication.
Does anyone have a complete different idea to gain this? Or hints what is wrong with my code? (The code might be a bit messy because I tried many different variations.)
I tried different approaches:
1) Just use the "real" team (0-3) instead of the team 0 that is usually used in MH. But there I have to hack the damage code including teleport fragging, "repair" enemy seeking rockets and probably some more stuff. Because I guess there are lots of maps outside that rely on players team=0 (eg TeamMonsters.u) this would break compatibility also. Bad approach.
2) Introducing a new storage ("VirtualTeam") for the team the player has chosen. Setting player's skin to that virtual team color is no problem in function AddToTeam() of a subclassed GameInfo. In the beginning I've put this variable "VirtualTeam" into a sub class of PlayerReplicationInfo and this has worked so far - with the disadvantage that this information is lost after logout (what happens with every map change). Because I need code to store the content of that variable at the client - preferably in USER.INI -, I decided to create a sub class of ReplicationInfo ("PlayerClientInfoSB") and have my stuff there instead of in PlayerReplicationInfoSB directly. PlayerReplicationInfoSB then only holds a reference to that class. But I didn't get it managed to store the VirtualTeam number in client's USER.INI nor having a manual set value replicated to server.
I followed these instructions: https://wiki.beyondunreal.com/Legacy:Ne ... _Variables and studied https://wiki.beyondunreal.com/Legacy:Re ... d_Function and nearly all stuff that is referenced by https://wiki.beyondunreal.com/Legacy:Replication.
Does anyone have a complete different idea to gain this? Or hints what is wrong with my code? (The code might be a bit messy because I tried many different variations.)
PlayerClientInfoSB
Code: Select all
class PlayerClientInfoSB expands ReplicationInfo config(User);
var byte VirtualTeam; // if Player switches team he will stay in Team=0 but *VirtualTeam* is set to new team number. This can be used for visual/acustical effects.
var config byte LastVirtualTeam; // local store for *VirtualTeam*
var bool bVirtualTeamChangeAllowed; // used by MonsterHuntSB.ChangeTeam(): if not allowed, team is not changed. MonsterHuntSB.PostLogin() sets this to TRUE and changes team then.
replication {
reliable if ( Role == ROLE_Authority )
VirtualTeam;
reliable if (Role < ROLE_Authority)
TeamChanged;
}
simulated function TeamChanged() { // this is executed on server but was never executed on client
if ( ! bVirtualTeamChangeAllowed)
return;
LastVirtualTeam = VirtualTeam;
//if (Role < ROLE_Authority)
if (Level.NetMode != NM_DedicatedServer) // only client should save it
SaveConfig();
}
static function bool PlayerClientInfoHave(Pawn Other, out PlayerClientInfoSB PCISB) {
/******************************************************************************
Just a shortcut for the wall of text for type casting.
Returns TRUE if *Other* has a *PlayerClientInfoSB* and sets *PCISB* to it.
******************************************************************************/
if (Other.PlayerReplicationInfo != None)
if (PlayerReplicationInfoSB(Other.PlayerReplicationInfo) != None)
if (PlayerReplicationInfoSB(Other.PlayerReplicationInfo).PCISB != None)
{
PCISB = PlayerReplicationInfoSB(Other.PlayerReplicationInfo).PCISB;
return true;
}
return false;
}
simulated function PostBeginPlay() { // by logging I found this is executed on server and client
if (Role == ROLE_Authority)
VirtualTeam = LastVirtualTeam;
Super.PostBeginPlay();
}
defaultproperties {
bVirtualTeamChangeAllowed=false
}
PlayerReplicationInfoSB
Code: Select all
class PlayerReplicationInfoSB expands PlayerReplicationInfo;
var PlayerClientInfoSB PCISB;
MonsterHuntSB
Code: Select all
class MonsterHuntSB expands TeamGamePlus config(BarbiesWorld);
function AddToTeam(int num, Pawn Other) {
const CMHTeamNum = 0;
local Pawn P;
local bool bSuccess;
local string SkinName, FaceName;
local PlayerClientInfoSB PCISB;
if (Other == None)
{
warn("Added NONE to team" @ num);
return;
}
if (Class'PlayerClientInfoSB'.static.PlayerClientInfoHave(Other, PCISB))
{
if (PCISB.bVirtualTeamChangeAllowed)
{
if (PCISB.VirtualTeam != num)
{
PCISB.VirtualTeam = num;
PCISB.TeamChanged();
}
}
else
return;
}
else
warn("PlayerReplicationInfoSB(Other.PlayerReplicationInfo).PCISB == None");
...
}
event PostLogin(playerpawn NewPlayer) {
local PlayerClientInfoSB PCISB;
Super.PostLogin(NewPlayer);
if (NewPlayer == None)
Return;
// if PCISB does not exist, create it
if ( ! Class'PlayerClientInfoSB'.static.PlayerClientInfoHave(NewPlayer, PCISB))
PlayerReplicationInfoSB(NewPlayer.PlayerReplicationInfo).PCISB = Spawn(Class'PlayerClientInfoSB', NewPlayer);
// check again if PCISB exists now:
if (Class'PlayerClientInfoSB'.static.PlayerClientInfoHave(NewPlayer, PCISB))
{
PCISB.bVirtualTeamChangeAllowed = true;
ChangeTeam(NewPlayer, PCISB.VirtualTeam);
}
}