Announcement

Collapse
No announcement yet.

replicating materials, help pls

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

    replicating materials, help pls

    Hi there, i have a problem that i've been trying to fix for a long time now and after reading everything i could on replication i still can't solve this problem.

    Basically i have a monster, and he has a function that makes him "cloak" (it sets a new skin on him) and another function that resets the original skin after a certain amount of time. Offline this all works perfectly, but online the "cloak" does not work.

    I used the log to check what was happening, and it is being logged on the server that the "cloak" effect is happening but there is nothing in the client logs.


    this is some of the code

    Code:
    var Material CloakMat0;
    var Material DeCloakMat0, DeCloakMat1, DeCloakMat2, DeCloakMat3;
    var config int DeCloakTime;
    
    replication
    {
        reliable if ( bNetDirty && (Role == ROLE_SimulatedProxy) )
            StartCloak, StartDeCloak;
    }
    
    simulated function Timer()
    {
    	GotoState('DeCloaking');
    }
    
    simulated State DeCloaking
    {
    
    simulated function BeginState()
    	{
    
    StartDeCloak();
    
    }
        simulated function Timer()
    	{
    		if ( !PlayerCanSeeMe() )
    StartDeCloak();
     		else
     			SetTimer(DeCloakTime, true);
    }
    }
    	
    simulated function Tick(float DeltaTime)
    {
    	super.Tick(DeltaTime);
    }
    
    simulated function StartCloak()
    {
    
    /*if(Role == Role_Authority)
      log("The server has done something cloak");
    else if(Role < Role_Authority)
      log("The client has done something cloak");
      */
        PlaySound(Sound'PredatorAddon2.cloak');
        Skins[0]=CloakMat0;
        Skins[1]=CloakMat0;
        Skins[2]=CloakMat0;
        Skins[3]=CloakMat0;
    }
    
    simulated function StartDeCloak()
    {
    
    /*if(Role == Role_Authority)
      log("The server has done something decloak");
    else if(Role < Role_Authority)
     log("The client has done something decloak");
      */
        PlaySound(Sound'PredatorAddon2.cloak');
        Skins[0]=DeCloakMat0;
        Skins[1]=DeCloakMat1;
        Skins[2]=DeCloakMat2;
        Skins[3]=DeCloakMat3;
    
    }
    at first the function "StartCloak" was being called from inside "ranged attack" and i tried chaning to being called from inside the "spawn rocket" function, which i believed replicated everything... and so i added this code, which again works fine offline but not online,

    Code:
    simulated function SpawnRocket()
    {
    	local vector RotX,RotY,RotZ,StartLoc;
    
    if (Role == ROLE_Authority)
    	    {
    	    log("Cloaked");
    StartCloak();
    }
    can anyone help me pls.

    #2
    I'm at work, so I can't help much, , ,but check the invisibility combo, and see how that does it. .. it surely works online. . ..

    Comment


      #3
      Code:
          reliable if (Role == ROLE_Authority)
              CloakMat0, DeCloakMat0, DeCloakMat1, DeCloakMat2, DeCloakMat3;
      Add that to your replication block and it should work.

      And ghouck the inviscombo actually calls a function in the pawn that calls another function that adds a overlay mat of the invis texture

      Comment


        #4
        thanks for the help B!G-A, i added that to the replication block and it all compiled fine but there was no change online. Its stil not telling the clients that the material has changed on this monsters.

        i already tried looking at the inviscombo for help with this and that is done a little differently, i even looked at AngelMappers Holocater code because that mutator messes with skins and the like but i couldnt find anything that helped much.

        Does anyone have any more ideas? :heart:

        Comment


          #5
          Remember that variables are only replicated if they change from their default values. Also, Object references will only replicate if the referenced objects (Materials in your case) are either contained in or hard-referenced from a ServerPackage or the map package. In any other case the replicated variable will be None on the client.
          I suggest replicating materials as strings and DynamicLoadObject() them clientsidely when they are required.

          Comment


            #6
            Thanks wormbo, unfortunately you lost me along the way. The var i am trying to replicate do change from their default values but as you pointed out, what i am trying to replicate is a Material.

            I kind of understand what you mean with your suggestion but i am confused.

            Would you be so kind as to maybe post some sample/example code of what you mean by "replicating materials as strings and DynamicLoadObject() them"
            :heart:

            Comment


              #7
              oh yes thats correct i forgot, you need to call dynamicloadobject in a simulated function so the texture is loaded on all clients. i dont have code on hand tho sry

              Comment


                #8
                Originally posted by iniquitous666
                "replicating materials as strings and DynamicLoadObject() them"
                Replicating as string: instead of replicating the material reference, replicate the package + material as a string. So if you're trying to replicate the material reference of MyPackage.CoolMaterial, you should replicate the string "MyPackage.CoolMaterial" instead.

                DynamicLoadObject() them: get the material reference from a string by using the DynamicLoadObject() function:
                Code:
                MyMaterial = Material(DynamicLoadObject("MyPackage.CoolMaterial", class'Material'));

                Comment


                  #9
                  Originally posted by Nov4
                  Code:
                  MyMaterial = Material(DynamicLoadObject("MyPackage.CoolMaterial", class'Material'));
                  Thanks, i already know how to dynamicload, but how do you replicate this function to clients? Also what function should this dynamicload be in in order for it to be replicated? PostBeginPlay?

                  like this?

                  Code:
                  function PreBeginPlay()
                  {
                          local material sometex;
                          
                          	sometex=material(DynamicLoadObject("predtexINI.All.shadeFB",class'material',False));
                  		sometex=material(DynamicLoadObject("HeavyPred.Legs",class'material',False));
                  		sometex=material(DynamicLoadObject("HeavyPred.Torso",class'material',False));
                  		sometex=material(DynamicLoadObject("HeavyPred.head",class'material',False));
                  	sometex=material(DynamicLoadObject("HeavyPred.Mask",class'material',False));
                  	}

                  Comment


                    #10
                    Well, this is how I did it with my TeamSpecificColorChangerReplicationInfo. Go figure it out yourself.

                    Code:
                    //=============================================================================
                    // TeamSpecificColorChangerReplicationInfo, v2.0 @ 31-7-2005 13:33:37
                    // Made by Robin 'Jrubzjeknf' van Olst <rrvanolst@hotmail.com>
                    //
                    // Contains the ColorModifier or Emitter that needs a color modification.
                    //
                    // Full documentation on TeamSpecificActors_v2.u can be downloaded from:
                    // http://unrealized-potential.com/forum/index.php?act=Attach&type=post&id=5135
                    //=============================================================================
                    class TeamSpecificColorChangerReplicationInfo extends ReplicationInfo;
                    
                    
                    //=============================================================================
                    // Variables
                    //=============================================================================
                    var string ObjectName; //looks like <Mapname>.<Object><index>, ie. ONS-TeamSpecificActors_v2.Emitter3
                    var string ObjectType; //ColorModifier or Emitter
                    var int ClientTriggerCount;
                    var int TriggerCount;
                    
                    
                    //=============================================================================
                    // Replication
                    //=============================================================================
                    replication
                    {
                      reliable if ( Role == ROLE_Authority )
                        TriggerCount, ObjectName, ObjectType;
                    }
                    
                    
                    //=============================================================================
                    // SetObjectToModify
                    //
                    // Saves Object and what it is, so it can be modified in the future.
                    //=============================================================================
                    function SetObjectToModify(string newObject, string newType)
                    {
                      ObjectName = newObject;
                      ObjectType = newType;
                    }
                    
                    
                    //=============================================================================
                    // ModifyObject
                    //
                    // Used to let the server call PostNetReceive() on the client.
                    //=============================================================================
                    function ModifyObject()
                    {
                      TriggerCount++;
                      
                      if ( Level.NetMode == NM_Standalone ||
                           Level.NetMode == NM_ListenServer )
                         PostNetReceive();
                    }
                    
                    
                    //=============================================================================
                    // PostNetReceive
                    //
                    // Modifies the color of ColorModifier and Emitter clientsidely.
                    //=============================================================================
                    simulated function PostNetReceive()
                    {
                       local ColorModifier ModifyColorModifier;
                       local Emitter       ModifyEmitter;
                       local int           ParticleEmitterCount; //needed for emitter
                       local int           ColorScaleCount; //needed for emitter
                       local Color         C;
                       local int           i; //needed for loop
                       local int           j; //needed for secundary loop
                       
                       if ( ClientTriggerCount == TriggerCount ||
                            ObjectName == "" ||
                            ObjectName == "None" ||
                            ObjectType == "" )
                          return;
                       
                       ClientTriggerCount = TriggerCount;
                    
                       if ( ObjectType == "ColorModifier" )
                       {
                          ModifyColorModifier = ColorModifier(DynamicLoadObject(ObjectName, class'ColorModifier'));
                          
                          if ( ModifyColorModifier == None )
                            return;
                          
                          C = ModifyColorModifier.Color;
                          C = class'Canvas'.static.MakeColor(C.B, C.G, C.R);
                          ModifyColorModifier.Color = C;
                       }
                    
                    
                       if ( ObjectType == "Emitter" )
                       {
                          ModifyEmitter = Emitter(DynamicLoadObject(ObjectName, class'Emitter'));
                          
                          if ( ModifyEmitter == None )
                            return;
                          
                          ParticleEmitterCount = ModifyEmitter.Emitters.Length;
                    
                          for ( i = 0; i < ParticleEmitterCount; i++ ) //an emitter can have multiple particleemitters...
                          {
                             ColorScaleCount = ModifyEmitter.Emitters[i].ColorScale.Length;
                    
                             for ( j = 0; j < ColorScaleCount; j++ ) //...with multiple colorscales
                             {
                                C = ModifyEmitter.Emitters[i].ColorScale[j].Color;
                                C = class'Canvas'.static.MakeColor(C.B, C.G, C.R); //switches red and blue around
                                ModifyEmitter.Emitters[i].ColorScale[j].Color = C;
                             }
                          }
                       }
                    }
                    
                    // ============================================================================
                    // Default properties
                    // ============================================================================
                    defaultproperties
                    {
                       bNetNotify=true
                    }
                    Do paste this in ConTEXT or WOTgreal or something, because it's unreadable here.

                    Comment


                      #11
                      Thanks for the help. I have got this far now:
                      Code:
                            DeCloakMat0="HeavyPred.Legs";
                            DeCloakMat1="HeavyPred.Torso";
                            DeCloakMat2="HeavyPred.head";
                            DeCloakMat3="HeavyPred.Mask";
                            CloakMat0="predtexINI.All.shadeFB";
                      
                      
                       
                           Material(DynamicLoadObject(DeCloakMat0, class'Texture'));
                                  Material(DynamicLoadObject(DeCloakMat1, class'Texture'));
                                        Material(DynamicLoadObject(DeCloakMat2, class'Texture'));
                                              Material(DynamicLoadObject(DeCloakMat3, class'Texture'));
                                                    Material(DynamicLoadObject(CloakMat0, class'Texture'));
                                                    }
                      But the problem now is that the materials (textures) are strings, and now i cant use them as skins. So i need to find out how i can make these strings textures.

                      I'm stumped on this one aswel, any ideas?

                      Comment


                        #12
                        Try this:
                        Code:
                        // Your Materials ready for use.
                        var Material CloakMat0;
                        var Material DeCloakMat0;
                        var Material DeCloakMat1;
                        var Material DeCloakMat2;
                        var Material DeCloakMat3;
                        var String   CloakingMats[5];
                        
                        // Right after the actor is spawned
                        simulated function PostBeginPlay()
                        {
                            Super.PostBeginPlay();
                            CloakMat0 = Material(DynamicLoadObject(CloakingMats[0],class'Material'));
                            DeCloakMat0 = Material(DynamicLoadObject(CloakingMats[1],class'Material'));
                            DeCloakMat1 = Material(DynamicLoadObject(CloakingMats[2],class'Material'));
                            DeCloakMat2 = Material(DynamicLoadObject(CloakingMats[3],class'Material'));
                            DeCloakMat3 = Material(DynamicLoadObject(CloakingMats[4],class'Material'));
                        }
                          
                        defaultproperties
                        {
                            // Add these to your defaults\
                            CloakingMats(0)="HeavyPred.Legs"
                            CloakingMats(1)="HeavyPred.Torso"
                            CloakingMats(2)="HeavyPred.head"
                            CloakingMats(3)="HeavyPred.Mask"
                            CloakingMats(4)="predtexINI.All.shadeFB"
                        }
                        


                        Then you can access them

                        Comment


                          #13
                          Hi,thanks for the help, that code you posted got around the problem perfectly! :heart:

                          However i'm back to problem number 1, the "cloaking" skin/function isn't being replicated clientside.Heres the necessary code i have so far, maybe someone can spot why it isnt being replicated.

                          Code:
                          var config float fHealth;
                          var config int DeCloakTime;
                          var string ObjectName; 
                          var string ObjectType; 
                          var Material CloakMat0;
                          var Material DeCloakMat0;
                          var Material DeCloakMat1;
                          var Material DeCloakMat2;
                          var Material DeCloakMat3;
                          var String   CloakingMats[5];
                          
                          replication
                          {
                          reliable if ( bNetDirty && (Role == ROLE_SimulatedProxy) )
                                  StartCloak, StartDeCloak;
                                  reliable if (Role == ROLE_Authority)
                                  CloakMat0, DeCloakMat0, DeCloakMat1, DeCloakMat2, DeCloakMat3, ObjectName, ObjectType;  
                          }
                          
                          function PreBeginPlay()
                          {
                          	Health = fHealth;
                          	Super.PreBeginPlay();
                          }
                          
                          simulated function PostBeginPlay()
                          {
                              Super.PostBeginPlay();
                              CloakMat0 = Material(DynamicLoadObject(CloakingMats[4],class'Material'));
                              DeCloakMat0 = Material(DynamicLoadObject(CloakingMats[0],class'Material'));
                              DeCloakMat1 = Material(DynamicLoadObject(CloakingMats[1],class'Material'));
                              DeCloakMat2 = Material(DynamicLoadObject(CloakingMats[2],class'Material'));
                              DeCloakMat3 = Material(DynamicLoadObject(CloakingMats[3],class'Material'));
                              
                                  RocketAmmo=spawn(RocketAmmoClass);
                                  PlaySound(Sound'Predator3.Pred_Spearhead4');
                          }                               
                          
                          simulated function Timer()
                          {
                          	GotoState('DeCloaking');
                          }
                          
                          simulated State DeCloaking
                          {
                          
                          simulated function BeginState()
                          	{
                          
                          StartDeCloak();
                          
                          }
                              simulated function Timer()
                          	{
                          		if ( !PlayerCanSeeMe() )
                          StartDeCloak();
                           		else
                           			SetTimer(DeCloakTime, true);
                          }
                          }
                          	
                          simulated function Tick(float DeltaTime)
                          {
                          	super.Tick(DeltaTime);/* need this*/
                          }
                          
                          simulated function StartCloak()
                          {
                          
                          if(Role == Role_Authority)
                            log("The server has done something cloak");
                          else if(Role < Role_Authority)
                            log("The client has done something cloak");
                            
                              PlaySound(Sound'PredatorAddon2.cloak');
                              
                              Skins[0]=CloakMat0;          //FinalBlend'predtexINI.All.shadeFB'
                              Skins[1]=CloakMat0;          
                              Skins[2]=CloakMat0;         
                              Skins[3]=CloakMat0;          
                              
                          }
                          
                          simulated function StartDeCloak()
                          {
                          
                          if(Role == Role_Authority)
                            log("The server has done something decloak");
                          else if(Role < Role_Authority)
                           log("The client has done something decloak");
                            
                              PlaySound(Sound'PredatorAddon2.cloak');
                              Skins[0]=DeCloakMat0;      //Texture'HeavyPred.Legs';
                              Skins[1]=DeCloakMat1;      //Texture'HeavyPred.Torso';
                              Skins[2]=DeCloakMat2;      //Texture'HeavyPred.head';
                              Skins[3]=DeCloakMat3;      //Texture'HeavyPred.Mask';
                              
                          }
                          
                          
                          defaultproperties
                          {
                               fHealth=100.000000
                               CloakMat0=FinalBlend'predtexINI.All.shadeFB' 
                               DeCloakMat0=Texture'HeavyPred.Legs'
                               DeCloakMat1=Texture'HeavyPred.Torso'
                               DeCloakMat2=Texture'HeavyPred.head'
                               DeCloakMat3=Texture'HeavyPred.Mask'
                               DeCloakTime=3
                               CloakingMats(0)="HeavyPred.Legs"
                               CloakingMats(1)="HeavyPred.Torso"
                               CloakingMats(2)="HeavyPred.head"
                               CloakingMats(3)="HeavyPred.Mask"
                               CloakingMats(4)="predtexINI.All.shadeFB"
                          }
                          So somewhere i've got the replication wrong, i hope someone can help me. I am very greatful for all the help everyone has given me so far. :heart:

                          Comment


                            #14
                            hey, solved my problem!

                            with still no luck i decided to approach my problem from a different angle, all i wanted basically was to change the monsters skin for a certain amount of time and then have it reset. And the way i was trying to do it just wasn't being replicated online.

                            i fixed it byt using this simple code, that i am guessing the invis combo uses, and it works online too

                            Code:
                            var Material    CloakHitMat;
                            var float       CloakHitMatTime;
                            
                            replication //Not actually sure if this replication is needed now
                            {
                            reliable if ( bNetDirty && (Role == ROLE_SimulatedProxy) )
                                    StartCloak, StartDeCloak;
                                    reliable if (Role == ROLE_Authority)
                                     CloakHitMat; 
                            }
                            
                            simulated function StartCloak()
                            {    
                                SetOverlayMaterial(CloakHitMat,CloakHitMatTime,true);
                            }
                            
                            defaultproperties
                            {
                                 CloakHitMat=FinalBlend'predtexINI.All.shadeFB'
                                 CloakHitMatTime=10
                            }
                            There's probably an even simpler way of doing this, but its always great to solve a problem on your own and in your own way. i've learnt alot, thanks everyone. Looks like ghouck was onto something (and he was the first reply aswel! ) :heart:

                            Comment


                              #15
                              O **** i didnt think of that, sry! =X

                              Comment

                              Working...
                              X