PDA

View Full Version : PRI subclassing or not


The_Pixie
6th Sep 2001, 05:27 PM
I've seen different ways of handling the PRI of a player/bot.

One is to subclass PlayerReplicationInfo and set the PlayerReplicationInfoClass (as in the Character Classes tutorial) to your own PRI class. This seems to be the way it was ment to be done.

A second way is to create a PRI class and "attach" it to the player in the login() event. This is seen in some mods like unrealfortress and I've also seen it in a tutorial written by Mungo of JailBreak mod. Mungo writes:

"You do not want to directly subclass PlayerReplicationInfo for a variety of reasons.

1) There already is a BotReplicationInfo. and Bots REQUIRE that, so you'd have to have everything subclass BotReplicationInfo and waste bandwith.
2) Changing it 'after the fact' is a BIG mess, although possibly SpawnNotifys could handle that.
3) It's not the right thing to do."

I don't fully understand that... Can someone explain to me why it's so bad to subclass PlayerReplicationInfo?

TaoPaiPai
6th Sep 2001, 06:16 PM
Originally posted by The_Pixie
I've seen different ways of handling the PRI of a player/bot.

"You do not want to directly subclass PlayerReplicationInfo for a variety of reasons.

1) There already is a BotReplicationInfo. and Bots REQUIRE that, so you'd have to have everything subclass BotReplicationInfo and waste bandwith.

"waste bandwith" this is greatly exagerated IMHO.
You don't waste that much bandwith(if any at all).
There is no harm in subclassing the PRI.
You can either make 2 child classes (1 from PRI & 1 from BotRI) and assign them to players depending if they're humans or bots or make only one class ,child of botRI and assign it to everybody.


2) Changing it 'after the fact' is a BIG mess, although possibly SpawnNotifys could handle that.

I don't understand what he is talking about.The mutator and gametype functions are there especially to let you change things on the player depending on your specifical needs.

ca
6th Sep 2001, 06:33 PM
In my experience, there isn't anything wrong with subclassing PRI, outside of having to copy code for your bot PRI subclass as well, assuming you want to add bot support to your modification.

If you check out the SniperMod tutorial I posted last night you can see how I modified the PRI class to be spawned by players and bots in my new gameinfo subclass as well, or you can use the SpawnNotify() functions and handle the data copy yourself.

usaar33
7th Sep 2001, 11:58 PM
Mongo is mostly wrong in both 1 and 2.
He forgot that you can change a pawn's playerreplicationinfoclass using checkreplacement() (note that this is the ONLY way to change the class before spawning).

I've used these type of hacks for some of my mods, like Valhalla Avatar (note that it doesn't need a bot PRI)/

As for 3, you should note that subclassing the PRI may break other mods. I wouldn't recommend it, unless you have a custom playerpawn (in which case you are breaking anything with a custom PRI anyway).

ChimpyNutz
7th Mar 2002, 08:35 AM
I found this post while searching to figure out my PRI problem.
Below I have the basic code that I am trying to implement, but when I reference the new PRI variable to display on the hud it is always 0. I don't think I'm referencing it correctly by coercing, but other approach gives me a compile error with mypri not being a member of pawn, or pri.
OK.. Here is specifically the code I have written,.... with extraneous code deleted. I don't have OO experience, but understand the concepts and have been programming unix,cobol,assem,other for 10+ years..

Here is the main mutator:
class scpHudScore extends Mutator;

var bool gbInitDone;

function PreBeginPlay()
{
if (gbInitDone) return;
gbInitDone = True;
Level.Game.RegisterDamageMutator(self);
spawn(class'scpHudScore.scpHudScoreNotify');
spawn(class'scpHudScore.scpHudScoreNotifyPRI');
}
function MutatorTakeDamage(out int liActualDamage, pawn loVictim, pawn loInstigatedBy,
out vector loHitLoc, out vector loMomentum, name lnDamageType)
{
if (loVictim.bIsPlayer) {
scpHudScorePRI(loVictim.PlayerReplicationInfo).giTotDmgTaken
= scpHudScorePRI(loVictim.PlayerReplicationInfo).giTotDmgTaken
+ liActualDamage;
}
}

Here is my notify to replace the hud:
class scpHudScoreNotify extends SpawnNotify;

simulated event Actor SpawnNotification( Actor loActor )
{

if ( HUD(loActor).HUDMutator == none)
{
HUD(loActor).HUDMutator = spawn(class'scpHudScore.scpHudScoreHud',loActor);
}
else
{
HUD(loActor).HUDMutator.AddMutator(spawn(class'scpHudScore.scpHudScoreHud',loActor));
}
return loActor;

}
defaultproperties
{
ActorClass=class'Engine.HUD';
}

Here is my notify to replace the PlayerReplicationInfo with my Player Replication Info:
class scpHudScoreNotifyPRI extends SpawnNotify;

simulated event Actor SpawnNotification( Actor loActor )
{

if ( loActor.IsA('scpHudScorePRI'))
{
return loActor;
}
else
{
loActor.Destroy();
return spawn(class'scpHudScorePRI');
}

}
defaultproperties
{
ActorClass=class'PlayerReplicationInfo';
}

Here is my HUD:
class scpHudScoreHud extends Mutator;
simulated function PostRender (canvas loCanvas)
{

loCanvas.SetPos(30,50);
loCanvas.DrawText("DT:"$scpHudScorePRI(PlayerPawn(Owner).PlayerReplicationInfo).giTotDmgTaken);
}

and here is my player replication sub-class:.
class scpHudScorePRI extends PlayerReplicationInfo;

var int giTotDmgGiven;
var int giTotDmgTaken;
var int giTotGibGiven;
var int giTotGibTaken;
replication
{
// Things the server should send to the client.
reliable if ( Role == ROLE_Authority )
giTotDmgGiven,giTotDmgTaken,giTotGibGiven,giTotGibTaken;
}


Thanks in advance to anyone who can help me out or guide me in this

Captain Kewl
7th Mar 2002, 08:58 AM
RE: 1.

It's not so much a waste of bandwidth as it is a waste of time. BotReplicationInfo is a subclass of PlayerReplicationInfo, thus it's redundant to subclass PRI for players and BRI for bots, since BRI already contains everything in PRI. What you can do is just subclass BRI and apply it to both bots and playerpawns.

(edit)

And I just realized that I just reiterated what was already mentioned at least twice in this thread. Heheh. Nevermind. :rolleyes:

2COOL4-U
7th Mar 2002, 10:31 AM
There is nothing wrong with subclassing PRI in my opinion, I actually prefer it

RegularX
7th Mar 2002, 02:34 PM
hmmm, well I'm still the process of testing everything, so shoot me if there's a serious error with this - but in working with Freehold I've found a great reason to subclass the PRI.

The same reason you subclass say Weapon, it gives you a starting point to base other PRI's with. For instance, all 3 current Freehold gametypes use money, so they all in fact use the BW PRI, but Containment, for instance, also tracks lives ... so it subclasses the BW PRI and adds in those properties.

And all 3 gametypes use a specific item which uses the BW PRI, so it can remain unchanged unless I need to add functionality to it (in which case I just subclass that...)

If every gametype had it's own unique PRI/BRI, all of the above would have been a nightmare, and I'd have 3 seperate clones of a huge item class rather than 3 small classes for RI stuff ... so I guess I've saved "bandwidth" ... although I still don't know what he means by that exactly.

I've had problems in the past with BRI of BountyWar dropping it's properties, but I don't think that was due to the subclassing, and seems to have been resolved.

Worst problems I've had with RI stuff is keeping proper track of what's config'ed and replicated correctly, but that's my own fault :)


rgx

Captain Kewl
7th Mar 2002, 03:31 PM
I think you might be miscontextualizing the quote a bit...


You do not want to directly subclass PlayerReplicationInfo for a variety of reasons.


I'm pretty sure the "directly" part is the operative term, not the "not". Which is to say that something like, "You want to subclass BotReplicationInfo if you're using a custom PRI" probably preceeded it. Custom PRI's are only bad if you don't do them right. :)

RegularX
7th Mar 2002, 03:44 PM
Good point, can anyone track down this tutorial? I can't seem to find it...and since Mongo is the author of "Replication De-Obfuscation", it's probably worth the read...


rgx

ChimpyNutz
7th Mar 2002, 04:15 PM
um... help... about 6-7 posts up .. if anyone can help such a lowley sole.

RegularX
7th Mar 2002, 04:36 PM
Originally posted by ChimpyNutz
um... help... about 6-7 posts up .. if anyone can help such a lowley sole.

DOH! There was a real question in there...

OK, I use the login/default method to replace the PRI, so I'm not sure if I can compare what's working in mine vs the sample, blah blah.

Can you prove that your PRI class is being read correctly? Give it a value (like 11 or something weird ... not 0 ) in the default properties and try to display it without modifying it.

rgx

|FAST|_Chimp
7th Mar 2002, 07:37 PM
I will give it a try. Figured I'd be stuck with doing a lot of the old logging-debug fun. Thought someone might see something obvious in what I did.

ChimpyNutz
8th Mar 2002, 09:55 AM
simulated event Actor SpawnNotification( Actor loActor )
{
local Actor OldOwner;
if ( loActor.IsA('scpHudScorePRI'))
{
return loActor;
}
else
{
OldOwner = loActor.Owner;
loActor.Destroy();
return spawn(class'scpHudScorePRI', OldOwner);
}
}

Thanks to "'Jeroen "2COOL4-U" de Haas'" <2cool4-u@planetunreal.com> for the fix... basically it was as if he asked me if I actually had the refridegerato plugged in. :) Duuuhhh....