Announcement

Collapse
No announcement yet.

Replication from the Mutator Class? How?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by KewlAzMe View Post
    ...Am I at least on the right track?
    That's the sort of arrangement I was talking about. I've changed my mind about using ClientGivenTo though, since I don't think you can be sure that iMaxNumJumps will have been replicated by the time it is executed. Instead, use ReplicatedEvent in the inventory to catch when it is actually replicated.

    Comment


      #17
      Hmmm lost again :P

      So instead of ClientGivenTo I'll change to

      Code:
      simulated function ReplicatedEvent(name VarName)
      {
      	if (VarName == 'MultiJumpMut.iMaxNumJumps')
      	{
      		UTPawn(Owner).MaxMultiJump = MultiJumpMut.iMaxNumJumps;
      	}
      
      	Super.ReplicatedEvent(VarName);
      }
      I made that from the UTJumpBoots code.. tho i dont really understand how it knows the reference to UTPawn(Owner).

      is OWNER always omnipresent as the owner of the client?

      Comment


        #18
        Almost, but for ReplicatedEvent to be called, the variable being replicated must be a member of that class, so:
        Code:
        var int iMaxNumJumps;
        
        simulated function ReplicatedEvent(name VarName)
        {
        	if (VarName == 'iMaxNumJumps')
        	{
        		UTPawn(Owner).MaxMultiJump = iMaxNumJumps;
        	}
        
        	Super.ReplicatedEvent(VarName);
        }
        You would set the inventory item's value of iMaxNumJumps in the mutator just after you spawn the inventory. You might have to set MultiJumpRemaining as well as MaxMultiJump, in case the pawn has already been initialized.

        I think Owner should always be replicated to the owning client when an actor is spawned, but you'd have to check.

        Comment


          #19
          Ok.. so using your new code, I would modify the Mutator class file to use:

          Code:
          function ModifyPlayer(Pawn Other)
          {
          	local UTPawn P;
          
              P = UTPawn(Other)
          	if (P != None)
          	{
          		P.CreateInventory(class'MultiJump.MultiJumpInv');
          		class'MultiJump.MultiJumpInv'.default.iMaxNumJumps = iMaxNumJumps;
          	}
          
          	Super.ModifyPlayer(Other);
          }
          and the inventory ReplicatedEvent:

          Code:
          var int iMaxNumJumps;
          
          simulated function ReplicatedEvent(name VarName)
          {
          	if (VarName == 'iMaxNumJumps')
          	{
          		UTPawn(Owner).MaxMultiJump = iMaxNumJumps;
                          UTPawn(Owner).MultiJumpRemaining = iMaxNumJumps;
          	}
          
          	Super.ReplicatedEvent(VarName);
          }

          Comment


            #20
            Is this working for you?

            When i was going through my testing these functions in the mutator were not being executed on the client. I am fairly certain that they are only executed on the server and as such their replication is not going to do anything for you. These functions are in effect only changing the servers version of the pawn, and leaving you back where you started.

            Comment


              #21
              Originally posted by Bob_Gneu View Post
              Is this working for you?

              When i was going through my testing these functions in the mutator were not being executed on the client. I am fairly certain that they are only executed on the server and as such their replication is not going to do anything for you. These functions are in effect only changing the servers version of the pawn, and leaving you back where you started.
              Will be testing it tonight, but I think the inventory class thing is replicated

              Comment


                #22
                Originally posted by KewlAzMe View Post
                Ok.. so using your new code, I would modify the Mutator class file to use:

                Code:
                class'MultiJump.MultiJumpInv'.default.iMaxNumJumps = iMaxNumJumps;
                Don't change the default value, but the instance value of the inventory item you just spawned. You could do it in a slightly different way by changing defaults, but then you have to either make it config or deal with archetypes.


                Originally posted by Bob_Gneu View Post
                Is this working for you?

                When i was going through my testing these functions in the mutator were not being executed on the client. I am fairly certain that they are only executed on the server and as such their replication is not going to do anything for you. These functions are in effect only changing the servers version of the pawn, and leaving you back where you started.
                Mutators don't exist on clients (unless you are naughty, like immortius), so no, their functions only work on the server. That's ok thought, since you can use a different class to do the replication.

                Which reminds me: In case it wasn't obvious, you need a replication statement in the inventory class too, specifying that iMaxNumJumps be replicated from server to the owning client.

                Comment


                  #23
                  I see, alright, ill be waiting with baited breath.

                  What is the significance of using an inventory class versus a player info class as i did? Are you just trying to find other options for networking? Did we rule out the mutator networking itself? What overhead does creating a new inventory entry have along with it?

                  I will probably be home around 6 (All my times are PST btw) or so and ill be able to possibly help you with this.

                  Comment


                    #24
                    Originally posted by Mr Evil View Post
                    Mutators don't exist on clients (unless you are naughty, like immortius), so no, their functions only work on the server. That's ok thought, since you can use a different class to do the replication.
                    Is there anything actually wrong with having a mutator replicated? I mean, using a tick to update a pawn is obviously naughty, but having the mutator itself replicated can be sensible for the right type of mutator.

                    Originally posted by Bob_Gneu
                    What is the significance of using an inventory class versus a player info class as i did? Are you just trying to find other options for networking? Did we rule out the mutator networking itself? What overhead does creating a new inventory entry have along with it?
                    Your previous method was basically the same as my mutator class, except you had the replication and tick function in a separate class. The tick is nasty though because it is run every frame (basically). The inventory method only allows the function to only be run once per pawn.

                    Also Kewlazme, no need to make the inventory class bAlwaysRelevent or change its RemoteRole, the existing settings for inventory should be fine.

                    Comment


                      #25
                      Originally posted by Bob_Gneu View Post
                      I see, alright, ill be waiting with baited breath.

                      What is the significance of using an inventory class versus a player info class as i did? Are you just trying to find other options for networking? Did we rule out the mutator networking itself? What overhead does creating a new inventory entry have along with it?
                      Im guessing the inventory class just has a function that replicates on the client so you are just sneaking your variable and code into a function that already does client stuff. I suppose the Info class could also have some client replicated functions in which to sneak in some code.

                      However, the use of the 'Tick' function, which is how your JumpMod is currently setting the replicated stuff, is considered overkill as you are constantly resetting that variable at every tick. That could be done from the single mutator class as Immortius shows above but is perhaps not the best choice. So I think by setting the variable during the time the client's inventory gets updated, you are essentially updating the players abilities to jump as well.

                      This is, however, still untested code. And still a bit confusing

                      I'm really just trying to learn what I can using this seemingly simple mutator as my example so that I can better understand the basics.

                      Originally posted by immortius View Post
                      Also Kewlazme, no need to make the inventory class bAlwaysRelevent or change its RemoteRole, the existing settings for inventory should be fine.
                      Ah ok, I need to take a look at the Inventory class itself to see what is what in there. Thanks

                      Comment


                        #26
                        Originally posted by Mr Evil View Post
                        Don't change the default value, but the instance value of the inventory item you just spawned. You could do it in a slightly different way by changing defaults, but then you have to either make it config or deal with archetypes.

                        Which reminds me: In case it wasn't obvious, you need a replication statement in the inventory class too, specifying that iMaxNumJumps be replicated from server to the owning client.
                        Mutator Class (MultiJumpMut.uc)
                        Code:
                        Class MultiJumpMut extends UTMutator Config(MultiJump);
                        
                        var() config int iMaxNumJumps;
                        
                        function ModifyPlayer(Pawn Other)
                        {
                        	local UTPawn P;
                        	local Inventory MJI;
                        
                                P = UTPawn(Other)
                        	if (P != None)
                        	{
                        		MJI = P.CreateInventory(class'MultiJump.MultiJumpInv');
                        		MJI.iMaxNumJumps = iMaxNumJumps;
                        	}
                        	Super.ModifyPlayer(Other);
                        }
                        
                        defaultproperties
                        {
                           iMaxNumJumps=4
                           Begin Object Name=Sprite ObjName=Sprite Archetype=SpriteComponent'UTGame.Default__UTMutator:Sprite'
                              ObjectArchetype=SpriteComponent'UTGame.Default__UTMutator:Sprite'
                           End Object
                           Components(0)=Sprite
                           Name="Default__UTMutator_MultiJump"
                           ObjectArchetype=UTMutator'UTGame.Default__UTMutator'
                        }
                        Inventory Class (MultiJumpInv.uc)
                        Code:
                        Class MultiJumpInv Extends UTInventory;
                        
                        var int iMaxNumJumps;
                        
                        replication
                        {
                        	if (Role == ROLE_Authority) {
                        		iMaxNumJumps;
                        	}
                        }
                        
                        simulated function ReplicatedEvent(name VarName)
                        {
                        	if (VarName == 'iMaxNumJumps')
                        	{
                        		UTPawn(Owner).MaxMultiJump = iMaxNumJumps;
                                        UTPawn(Owner).MultiJumpRemaining = iMaxNumJumps;
                        	}
                        
                        	Super.ReplicatedEvent(VarName);
                        }
                        
                        defaultproperties
                        {
                        }
                        That's what I got up to this point though I am not sure, should the replication block be if Role < ROLE_Authority to replicate it on client?

                        Comment


                          #27
                          No, Role == ROLE_Authority means it replicates from where it is ROLE_Authority - the server.

                          iMaxNumJumps on the inventory class needs to be declared as var repnotify int iMaxNumJumps, because only repnotify variables trigger ReplicatedEvent() when replicated.

                          You will also need to set the new MaxMultiJump somewhere outside the ReplicatedEvents() function, because that function isn't called on the server to my knowledge.

                          Comment


                            #28
                            Originally posted by immortius View Post
                            Is there anything actually wrong with having a mutator replicated?
                            The way I see it, the whole idea of a mutator is to interact with the GameInfo (where all the mutator's functions are called from). That never happens on clients, so by making it replicated you're shoehorning a second purpose into the mutator class, which isn't a very object-oriented way of doing things. It can work fine, but it makes the code harder to understand.


                            Originally posted by KewlAzMe View Post
                            That's what I got up to this point though I am not sure, should the replication block be if Role < ROLE_Authority to replicate it on client?
                            That looks good to me, except that you don't need any of those default properties below iMaxNumJumps (I assume you got those from some code exported from the editor).

                            Role == ROLE_Authority is correct. That's true on the server and tells it to replicate. You should put an && bNetOwner in there too though, otherwise it will be replicated to all clients, but they don't need it.

                            And what immortius just said.

                            Comment


                              #29
                              Originally posted by immortius View Post
                              You will also need to set the new MaxMultiJump somewhere outside the ReplicatedEvents() function, because that function isn't called on the server to my knowledge.
                              I thought i was setting that from my mutator class when i spawned it.

                              Comment


                                #30
                                MaxMultiJump on the Pawn.

                                Comment

                                Working...
                                X