New Variable to xPawn? PRI?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

time

New Member
Dec 12, 2005
25
0
0
Hi all,

This is my first post. Been playing unreal and mapping for many years. However I am fairly new to scripting. What I want to know is how I can add additional variables to a player. I want to make a mod where players gain experience for kills and advance in levels. I need some variables to hold values for experience and level, and need to be able to update those values throughout the game. I have tried subclassing Pawn, xPawn, and xPRI but haven't had much luck. I'm not sure where I should be placing these variables and how to make them accessible. When compiling I am usually getting errors about the variable not being a member of xPawn, or something similar. I'm guessing after I subclass and declare those variables, that there's something else I need to do to tie it all together. But I'm lost at this point. I've googled for 2 days with no luck. So if anyone can help I would be very thankful. Also, if and when I figure out where to add these new variables, do I need to be adding a REPLICATION statement for them somewhere. Being new to this replication is still a bit of a mystery to me. Thanks in advance to anyone who can help.

-Time
 

SoundFX

New Member
May 26, 2005
30
0
0
Just by looking at it, I would think this is a fairly complex task to tackle. I am quite new but I would think it takes a custom PRI, for your variables, a PlayerController, to interact with the PRI and your pawn, and of course your pawn.
 

_Lynx

Strategic Military Services
Staff member
Dec 5, 2003
1,965
8
38
40
Moscow, Russia
beyondunreal.com
I suggest you subclassing a Actor -> Info -> ReplicationInfo -> LinkedReplicationInfo class and ading it to the PlayerReplicationInfo.CustomReplicationInfo chained list. In this class you can store all the variables you need. You can also subclass pawn, controller and/or PRI class, but this will make the mode impossible to use with any other mod, replcaing the same class, for example UTComp.
 

time

New Member
Dec 12, 2005
25
0
0
Thanks for the info _Lynx. I didn't know about the LinkedReplicationInfo class. I found some info on wiki about the class but it thoroughly confused me. What type of script do I put in a subclass of LinkedReplicationInfo? Do I just declare my variables in there? Also, where is PlayerReplicationInfo.CustomReplicationInfo located? Once I get all this set up can I access the variables the same way you access normal variables. i.e. x.health =100. This is started to be more work than I imagined, but I'm not giving up yet.
 

time

New Member
Dec 12, 2005
25
0
0
Scratch that.....the code for that mod looks to be for the original unreal tournament. Doesn't work for 2004.
 

time

New Member
Dec 12, 2005
25
0
0
True. But I am still a beginner as far as scripting goes. I attempted to convert the UT Koth code to ut2004 code but failed miserably. Maybe I'll take another crack at it later after I've learned more. But basically I think I'm more confused than when I started this post. sigh. Oh well, I'll get it eventually.
 

time

New Member
Dec 12, 2005
25
0
0
I GOT IT FIGURED OUT!

I eventually got this all worked out I think. I thought I'd post it here in case some other noob ever has the same questions. This is probably easy for the experienced coders out there, but it took me a while. I went with _Lynx's suggestion (see above) about the LinkedReplication info. The hard part was figuring out how to set it up.

I subclassed LinkedReplicationInfo with my own class, something like this:

Code:
class MyNewReplicationInfo extends LinkedReplicationInfo;

var int MyNewVariable;  
var int AnotherNewVariable;  

replication
{
   reliable if (bNetDirty && Role == Role_Authority)
      MyNewVariable, AnotherNewVariable;
}

defaultproperties
{
   MyNewVariable=1   
   AnotherNewVariable=0
}


That was the easy part. Setting up an instance of the new class for each player was what took me a while to figure out. In my Mutator subclass, under the ModifyPlayer section I added the following:


Code:
function ModifyPlayer(Pawn Other)
{
   local LinkedReplicationInfo LRI, Last;
   local MyNewReplicationInfo MyRI;
   local bool bFound;

   Super.ModifyPlayer(Other);

   if ((Other.Controller == None) || (Other.Controller.PlayerReplicationInfo == None))
      return;

   LRI = Other.Controller.PlayerReplicationInfo.CustomReplicationInfo;
   if ( LRI == None )
   {
      MyRI = Spawn(class'MyNewReplicationInfo', Other.Controller);
      if (MyRI != None)
      {
         Other.Controller.PlayerReplicationInfo.CustomReplicationInfo = MyRI;
      }
      return;
   }

   bFound = false;

   while (LRI != None)
   {
      Last = LRI;

      if ( LRI.IsA( 'MyNewReplicationInfo'))
      {
         bFound = true;
         break;
      }

      LRI = LRI.NextReplicationInfo;
   }

   if (!bFound)
   {
      MyRI = Spawn( class'MyNewReplicationInfo', Other.Controller );

      if (MyRI != None)
      {
         Last.NextReplicationInfo = MyRI;
      }
   }
   
}

Yes that does all make sense if you read through it 3 or 4 times and really think about what it's doing. Then if you need to access the new replication info from other classes, you can call a function like this:
MyRI = GetMyRepInfo(<insert controller here>)

Here's the code for the GetMyRepInfo function:

Code:
function MyNewReplicationInfo GetMyRepInfo(Controller C)
{
   local bool bFound;
   local LinkedReplicationInfo LRI;

   bFound = false;

   if ((C != None) && (C.PlayerReplicationInfo != None))
   {
      LRI = C.PlayerReplicationInfo.CustomReplicationInfo;

      for (LRI = LRI; LRI != None; LRI = LRI.NextReplicationInfo)
      {
         if (LRI.IsA('MyNewReplicationInfo'))
         {
            bFound = true;
            break;
         }
      }
   }

   if (bFound)
   {
      return MyNewReplicationInfo(LRI);
   }
   return None;
}


After calling that function you can access the variables in the new replication info like this

MyRI.MyNewVariable = 23;
MyRI.AnotherNewVariable = MyRI.MyNewVariable + 5;

You get the idea. Hopefully this will help someone out in the future and save them some time. I would have never figured it all out if other's had not posted info out there. Just remember, Google is your friend, LOL. As well as these forums.

~Time :D
 
Last edited by a moderator: