Announcement

Collapse
No announcement yet.

Spawning an object rather than a class (modding properties 2)

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

  • replied
    Got it!

    Thanks everyone for all yer help. Here is what I ended up with:

    Code:
    class'XxxXESRv2b.XxxXSparks'.default.mColorRange[0] = NewColorRange;
    That's all it took. It defies all my OOP logic, but it works. You shouldn't be able to change a class property when it doesn't exist in memory! Oh well..

    Thanks again!

    ~DG

    Leave a comment:


  • replied
    Yea i mean otherwise you can always store a reference to the thing and change it and put a slight delay on the emitter.. you never know

    Leave a comment:


  • replied
    I don't think you can change the values of a class, since it doesn't exist in memory.

    However, I'm willing to try anything. I'll post again if it works.

    Leave a comment:


  • replied
    What happens if you try like

    Code:
    //pseudo code to the EXTREME :)
    class'xxxSparks'.default.Colorstuff = red;

    Leave a comment:


  • replied
    I see the logic that you are using, however, I'm still not getting it to work.

    First off, in case someone else reads this, the class is PreSpawned, not PreSpawn.

    I don't know what my next step will be. I've tried both methods. I just can't get it to work, lately I'm losing the sparks altogether isntead of the default red sparks.

    Leave a comment:


  • replied
    If I don't have an actual instance of the XxxXSparks class I can't change the color.
    when you spawn an actor, there is an instance. And exactly this instance will get his colors from a variable of his owner, before it creates sparks.

    XxxXSparks:
    Code:
    event PreSpawn()
    {
        Color clr1, clr2;
        clr1 = XxxXBeamEffect(Owner).DesiredSparksClr1;
        clr2 = XxxXBeamEffect(Owner).DesiredSparksClr2;
    
        SetSparksColor(clr1, clr2);
        Super.PreSpawn();
    }
    
    defaultproperties
    {
        bCallPreSpawn = true;
       //all the other stuff
    }
    XxxXBeamEffect
    Code:
    //the variables you access from the XxxXSparks instance
    var DesiredSparksClr1, DesiredSparksClr2;
    
    simulated function SpawnImpactEffects(rotator HitRot, vector EffectLoc)
    {
       Spawn(class'ShockImpactRing',,, EffectLoc, HitRot);
       Spawn(class'ShockImpactScorch',,, EffectLoc, Rotator(-HitNormal));
    
       //here you can set the desired color of the sparks
       DesiredSparksClr1 = WhatEverYouWant1;
       DesiredSparksClr1 = WhatEverYouWant2;
    
       //this creates an instance, which will get the variable from his owner (an object of XxxXBeamEffect)
       Spawn(class'XxxXSparks',,, EffectLoc, HitRot);
    
       spawn(class'ShockExplosionCore',,, EffectLoc + HitNormal, HitRot);
    }

    Leave a comment:


  • replied
    What do each of the variables you pass to Spawn do? Specifically the ones you omitted? Try making the edited instance the second parameter (Spawn(class'XxxXSparksClass', XxxXSparks,, EffectLoc, HitRot); )

    Leave a comment:


  • replied
    All good ideas, the simple problem still remains. If I don't have an actual instance of the XxxXSparks class I can't change the color. It will always take the defaults.

    I need to be able to do something like:

    Code:
    local XxxXSparks XxxXSparkCLass;
            local color clr;
    	clr.R = 0;
            clr.B = 240;
    	clr.G = 0;
    	clr.A = 240;
    	Spawn(class'ShockImpactRing',,, EffectLoc, HitRot);
            spawn(class'ShockExplosionCore',,, EffectLoc + HitNormal, HitRot);
    	Spawn(class'ShockImpactScorch',,, EffectLoc, Rotator(-HitNormal));
    	XxxXSparksClass = Spawn(class'XxxXSparks',,, EffectLoc, HitRot);
    	XxxXSparksClass.setSparkColor(clr,clr);
    //new line here:
    	XxxXSparksClass.SpawnNow();
    But I think the sparks show up immediately upon calling Spawn. Please someone tell me I'm wrong! :-)

    Leave a comment:


  • replied
    well, i'm not programming OOP since today... I know the difference between classes and objects. but in uscript the only method to create ACTORS is to spawn them.

    If you spawn an actor (xEmitter is an actor) it sets a variable (owner) that contains a reference to the actor that spawned this actor. then calls an event called SetInitialState().

    I'm not sure when exactly the defaultproperties are applied to the new actor, but you have a good chance that it's before SetInitialState() is called.

    so In setInitialState() you could set all properties like you want.

    --------
    only speculation
    ---------------------
    EDIT
    another "idea":
    If you set bCallPreSpawn = true, the engine calls the event PreSpawn() in xEmitter. Here's another place to set the properties (color) of your sparks BEFORE you see them.

    Leave a comment:


  • replied
    The problem is simply this. Since Spawn's first parameter is always a class instead of an object instance.

    For those who may find this post and need to know the difference:

    A class is the definition of an object.
    An object instance is one that exists in memory.

    To recap for this problem:

    for the beam I do:
    Code:
    local XxxXBeamEffect beam;
    beam = weapon.spawn(class'XxxXBeamEffect',,,Start,Dir)
    beam.setColor("Red")
    if ( ReflectNum != 0 )
          {
            Beam.Instigator = None;
          }
    Beam.AimAt(HitLocation,HitNormal);
    basically I create a beam instance, set it's color, and then fire it with the AimAt function.

    The problem with the sparks (and I believe the spiral) is that I can't create an instance and then fire it off. Once I spawn it, it uses what ever the default properties of the class are and it instantly creates it's own instance and displays it.

    :-(

    I want to make Sparks and Sprial a property of the BeamEffect and spawn those instances, but I'm at a loss on how to do that.

    Leave a comment:


  • replied
    yeah, makes sense....

    unfortunately now I have no clue how to do it

    ------

    i have no idea if this functions.... you could try to set a color variable in your beam effect class, which contains the desired spark color. Then set the color in PreBeginPlay() of the XxxXSparks class, like this:

    Code:
    simulated event PreBeginPlay()
    {
        setSparkColor(owner.DesiredSparksColor1, owner.DesiredSparksColor2);
        super.PreBeginPlay();
    }
    edit:
    maybe the event SetInitialState() is a better place for this...
    note that this probably won't function...:cry:

    Leave a comment:


  • replied
    We're going to be attempting to change the beam, the sparks, and the spiral.

    We got the beam color changed with this code:
    Code:
     Beam = Weapon.Spawn(Class'XxxXBeamEffect',,,Start,Dir);
    	if (Beam.IsA('XxxXBeamEffect'))
    	{
               BeamColor.R = 56;
    	   BeamColor.G = 255;
               BeamColor.B = 255;
    	   BeamColor.A = 200;
               
               //Beam.SetColorClr(BeamColor, BeamColor);
               Beam.mColorRange[0] = BeamColor;
    	}
    Sparks don't seem to be called to existance in the same fashion as the beam.

    Since the beam isn't fired until the .AimAt() function is called, I can set the beam color and then call AimAt(). The sparks however seem to appear as soon as the following code executes:

    Code:
    simulated function SpawnImpactEffects(rotator HitRot, vector EffectLoc)
    {
    
    	Spawn(class'ShockImpactRing',,, EffectLoc, HitRot);
    	Spawn(class'ShockImpactScorch',,, EffectLoc, Rotator(-HitNormal));
    //trouble line:
    	Spawn(class'XxxXSparks',,, EffectLoc, HitRot);
    	spawn(class'ShockExplosionCore',,, EffectLoc + HitNormal, HitRot);
    }
    So I can't change any properties of XxxXSparks, I have to use the defaults.

    Make sense?

    Leave a comment:


  • replied
    I or you didn't get the idea... Do you want to change the color of the sparks or the beam? or both?

    Leave a comment:


  • replied
    Unfortunately... due to my UScript noobness... I'm having trouble following.

    Here are the 2 classes as they stand now:
    Code:
    class XxxXBeamEffect extends SuperShockBeamEffect;
    
    
    simulated function SpawnImpactEffects(rotator HitRot, vector EffectLoc)
    {
    
    	Spawn(class'ShockImpactRing',,, EffectLoc, HitRot);
    	Spawn(class'ShockImpactScorch',,, EffectLoc, Rotator(-HitNormal));
    //trouble line:
    	Spawn(class'XxxXSparks',,, EffectLoc, HitRot);
    	spawn(class'ShockExplosionCore',,, EffectLoc + HitNormal, HitRot);
    }
    
    function SetColor(string SelectedColor)
    {
        local XxxXSparks newSparks;
        local Color NewColorRange;
        if (SelectedColor == "Red")
        {
    	NewColorRange.R = 240;
    	NewColorRange.G = 0;
    	NewcolorRange.B = 0;
    	NewColorRange.A = 240;
            mColorRange[0] = NewColorRange;
    	mColorRange[1] = NewColorRange;
        }
        else if (SelectedColor == "Blue")
        {
          	NewColorRange.R = 0;
    	NewColorRange.G = 0;
    	NewcolorRange.B = 240;
    	NewColorRange.A = 240;
            mColorRange[0] = NewColorRange;
    	mColorRange[1] = NewColorRange; 
    	
        }
        else if (SelectedColor == "Green")
        {
          	NewColorRange.R = 0;
    	NewColorRange.G = 240;
    	NewcolorRange.B = 0;
    	NewColorRange.A = 240;
            mColorRange[0] = NewColorRange;
    	mColorRange[1] = NewColorRange; 
    	
        }
        else if (SelectedColor == "Purple")
        {
          	NewColorRange.R = 240;
    	NewColorRange.G = 0;
    	NewcolorRange.B = 240;
    	NewColorRange.A = 240;
            mColorRange[0] = NewColorRange;
    	mColorRange[1] = NewColorRange; 
    	
        }
        else
        {
    	NewColorRange.R = 240;
    	NewColorRange.G = 240;
    	NewcolorRange.B = 240;
    	NewColorRange.A = 240;
            mColorRange[0] = NewColorRange;
    	mColorRange[1] = NewColorRange;  
    	
        }
       
    }
    
    function SetColorRGBA(int colorR, int colorG, int colorB, int colorA)
    {
        local Color NewColorRange;
       
        NewColorRange.R = colorR;
        NewColorRange.G = colorG;
        NewcolorRange.B = colorB;
        NewColorRange.A = colorA;
        mColorRange[0] = NewColorRange;    	
        mColorRange[1] = NewColorRange; 
            
    }
    
    function SetColorCLR(color NewColorRange1, color NewColorRange2)
    {
        mColorRange[0] = NewColorRange1;    	
        mColorRange[1] = NewColorRange2;
    }
    
    defaultproperties
    {
         CoilClass=Class'XEffects.ShockBeamCoil'
         MuzFlashClass=Class'XEffects.ShockMuzFlash'
         MuzFlash3Class=Class'XEffects.ShockMuzFlash3rd'
         mRegen=False
         mStartParticles=10
         mMaxParticles=1
         mLifeRange(0)=0.500000
         mLifeRange(1)=0.000000
         mSizeRange(0)=7.000000
         mSizeRange(1)=0.000000
         Skins(0)=Texture'XEffectMat.Ion.Ion_beam'
    }
    and
    Code:
    class XxxXSparks extends xEmitter;
    
    simulated function PostBeginPlay()
    {
      if ( PhysicsVolume.bWaterVolume )
      Super.destroy();
    }
    
    function setSparkColor(color clr1, color clr2)
    {
         mColorRange[0] = clr1;
         mColorRange[1] = clr2;
    }
    
    defaultproperties
    {
         mParticleType=PT_Line
         mRegen=False
         mStartParticles=20
         mMaxParticles=10
         mLifeRange(0)=0.800000
         mLifeRange(1)=1.200000
         mRegenRange(0)=0.000000
         mRegenRange(1)=0.000000
         mDirDev=(X=0.400000,Y=0.400000,Z=0.400000)
         mPosDev=(X=0.200000,Y=0.200000,Z=0.200000)
         mSpawnVecB=(X=2.000000,Z=0.060000)
         mSpeedRange(0)=250.000000
         mSpeedRange(1)=350.000000
         mMassRange(0)=1.500000
         mMassRange(1)=2.500000
         mAirResistance=0.200000
         mSizeRange(0)=1.000000
         mSizeRange(1)=2.000000
         mGrowthRate=-1.000000
         mColorRange(0)=(B=0,G=0,R=255)
         mColorRange(1)=(B=0,G=0,R=255)
         mAttenKa=0.100000
         DrawScale=10.000000
         Skins(0)=Texture'XEffects.Skins.TransTrailT'
         ScaleGlow=20.000000
         Style=STY_Additive
    }

    Since the Spawn() function is expecting a class and not an instance, we'd have to create a XxxXSparksRed, XxxXSparksBlue, etc.. instead of just changing the mColorRange() property. We would like to include RGB sliders so that they can really customize it and not be limited to the named colors we come up with.

    I would love to see your code where you do this, so I'd have a full example.

    Leave a comment:


  • replied
    you could override the function that spawns the particles with something like this:

    Code:
    var int xAmount;
    simulated event SpawnParticle( int Amount )
    {
        xAmount = Amount;
    }
    and do an own Spawn SpawnParticle function which you can call (whenever you want):
    Code:
    simulated function ReallySpawnParticles( )
    {
        //Do here what you want... (Set colors etc...)
    
        int i;
        for(int i = 0; i < Emitters.Length; i++)
        {
             Emitters[i].SpawnParticle(xAmount);
        }
    }
    at least I did it so with an explosionclass with "dynamic" sizes, which i can set.

    Leave a comment:

Working...
X