The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

Difference between revisions of "Unreal Wiki:Scratchpad"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
 
(34 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 +
__NOTOC__
 
This page is for pasting code you want to show someone as an example or to get assistance with.  This allows you to easily collaborate with someone to solve a problem, and allows easy comparisons of the edits.
 
This page is for pasting code you want to show someone as an example or to get assistance with.  This allows you to easily collaborate with someone to solve a problem, and allows easy comparisons of the edits.
  
Line 7: Line 8:
  
 
<uscript>
 
<uscript>
//See Timer function for relevant code. Entire class is provided for context purposes.
+
// paste your code here
 +
</uscript>
  
class EONSScorpionEnergyProjectileRed extends Projectile;
+
====Full Key====
 
+
* <sup>1</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 1]].
#exec AUDIO IMPORT FILE="Sounds\DP_Explode.wav" NAME="DP_Explode" GROUP="Scorpion"
+
* <sup>2</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 2]].
 
+
* <sup>2+</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 2]], from this version onwards.
var vector initialDir;
+
* <sup>2x</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 2]], starting with [[UT2004]].
var float FlyingDamageRadius;
+
* <sup>3</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 3]].
var class<Emitter> ProjectileEffectClass;
+
* <sup>3+</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 3]], starting with [[UT3]] patch 2.0.
var Emitter        ProjectileEffect;
+
* <sup>3*</sup> &ndash; {'''$Topic''' is relevant/available to/in} [[Unreal Engine 3]], starting with [[UDK]].
var class<xEmitter> HitEmitterClass;
+
* (no number) &ndash; {'''$Topic''' is relevant/available to/in} all Unreal Engine generations.
var class<Emitter> ExplosionEmitterClass;
+
<br>
var bool bZap, bEffects;
+
====Enum Key====
var byte Team;
+
{{classgames|Vector}}<sup>--|</sup><br>
 
+
{{classgames|Range}}<sup>--|'''2'''</sup><br>
 
+
{{classgames|Vector2D}}<sup>--|'''3'''</sup><br>
replication
+
{{classgames|Color}}<br>
{
+
{{classgames|LinearColor}}<br>
  reliable if(bNetDirty && Role==ROLE_Authority)
+
<br>
    bZap, Team;
+
====Class Key====
}
+
{{classgames|Actor}}<br>
 
+
{{classgames|Rook}}<br> - TribesV?
 
+
{{classgames|SoundCue}}<br>
simulated function PostBeginPlay()
+
{{classgames|UTGreedGame}}<br>
{
+
{{classgames|LegendObjectComponent}}<br>
    local Rotator R;
+
{{classgames|FluidSurfaceOscillator}}<br>
 
+
{{classgames|Ammunition}}<br>
    if (Level.NetMode != NM_DedicatedServer)
+
{{classgames|Util}}<br>
    {
+
{{classgames|xUtil}} -UE2??<br>
        ProjectileEffect = spawn(ProjectileEffectClass, self,, Location, Rotation);
+
{{classgames|UnrealPlayer}}<br>
        ProjectileEffect.SetBase(self);
+
{{classgames|xPlayer}} -UE2??<br>
    }
+
{{classgames|UTPlayerController}}<br>
 
+
{{classgames|WeaponFire}}
    Super.PostBeginPlay();
+
<br>
 
+
====Keyword Key====
    Velocity = Speed * Vector(Rotation);
+
{{classgames|Expands}}<br>
    R = Rotation;
+
{{classgames|Extends}}<br>
    R.Roll = 32768;
+
{{classgames|server}}<br>
    SetRotation(R);
+
{{classgames|replicated}}<br>
    Velocity.z += TossZ;
+
{{classgames|intrinsic}}<br>
    initialDir = Velocity;
+
   
+
    Team = Instigator.GetTeamNum();
+
 
+
    //Use the timer for electromagnetic shocks while travelling
+
    SetTimer(0.05, True);     //Was 0.05, upping to 0.20 to see if it reduces lag
+
    bEffects = false;
+
}
+
 
+
 
+
simulated function Destroyed()
+
{
+
    //If we didn't zap someone, and destroy got called before we hit something (our lifetime probably expired), then explode
+
    if (!bZap)
+
    {
+
      if ( Role == ROLE_Authority )
+
      {
+
          HurtRadius(Damage, DamageRadius, MyDamageType, MomentumTransfer, Location);
+
      }
+
    }
+
 
+
    //If the explosion effects weren't previously called, we can call them now so our projectile always explodes a the end of its life
+
    if (!bEffects)
+
      SpawnEffects(vect(0,0,0),vect(0,0,0));
+
 
+
    if (ProjectileEffect != None)
+
        ProjectileEffect.Destroy();
+
 
+
    Super.Destroyed();
+
}
+
 
+
 
+
simulated function ProcessTouch(Actor Other, Vector HitLocation)
+
{
+
    if ( Other != Instigator )
+
    {
+
        SpawnEffects(HitLocation, -1 * Normal(Velocity) );
+
        bEffects = true;
+
        Explode(HitLocation,Normal(HitLocation-Other.Location));
+
    }
+
}
+
 
+
 
+
simulated function SpawnEffects( vector HitLocation, vector HitNormal )
+
{
+
    if ( EffectIsRelevant(Location,false) )
+
    {
+
        if (bZap)
+
        {
+
          spawn(class'xEffects.GoopSparks',,,Location);
+
          PlaySound(sound'WeaponSounds.BioRifle.BioRifleGoo1',,8*TransientSoundVolume);
+
        }
+
        else
+
        {
+
          PlaySound(ImpactSound,,8*TransientSoundVolume);
+
        }
+
 
+
        spawn(ExplosionEmitterClass,,,Location);
+
        spawn(class'ONSPlasmaHitGreen',,,Location);
+
 
+
        if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
+
            Spawn(ExplosionDecal,self,,HitLocation, rotator(-HitNormal));
+
    }
+
}
+
 
+
 
+
simulated function Landed( vector HitNormal )
+
{
+
    SpawnEffects( Location, HitNormal );
+
    bEffects = true;
+
    Explode(Location,HitNormal);
+
}
+
 
+
 
+
simulated function HitWall (vector HitNormal, actor Wall)
+
{
+
    Landed(HitNormal);
+
}
+
 
+
 
+
simulated function Explode(vector HitLocation, vector HitNormal)
+
{
+
    Destroy();
+
}
+
 
+
 
+
simulated function Timer()
+
{
+
    local Vehicle Other;
+
    local Controller C, NextC;
+
    local xEmitter HitEmitter;
+
    local int TempDamage;
+
 
+
    bZap = false;
+
 
+
    C = Level.ControllerList;
+
+
    //Instead of using ForEach VisibleCollidingActors, lets traverse the Controller List, it may be faster    //ForEach VisibleCollidingActors(class'Vehicle',Other,FlyingDamageRadius)
+
    while (C != None)
+
    {
+
      NextC = C.NextController;
+
 
+
      if (C.Pawn != None && Vehicle(C.Pawn) != None)
+
          log("C.Pawn != None && Vehicle(C.Pawn) != None is true. C.Pawn is a "$C.Pawn.class);
+
      else log("C.Pawn != None && Vehicle(C.Pawn) != None is false. C.Pawn is a "$C.Pawn.class);
+
 
+
      //if (Vehicle(C.Pawn) != None)
+
      //  log("Vehicle(C.Pawn) != None is true");
+
      //else log("Vehicle(C.Pawn) != None is false");
+
 
+
      //if (C.Pawn != Instigator)
+
      //  log("C.Pawn != Instigator is true");
+
      //else log("C.Pawn != Instigator is false");
+
 
+
      //if (C.Pawn.Health > 0)
+
      //  log("C.Pawn.Health > 0 is true");
+
      //else log("C.Pawn.Health > 0 is false");
+
 
+
      if (!C.SameTeamAs(Instigator.Controller))
+
          log("This target is on the opposite team");
+
      else log("This target is on the same team.");
+
 
+
      if (VSize(C.Pawn.Location - Instigator.Location) < FlyingDamageRadius)
+
          log("This target is within the zap distance.");
+
      else log("This target is outside the zap distance.");
+
 
+
      if (FastTrace(C.Pawn.Location, Instigator.Location))
+
          log("There is a clear shot to this target.");
+
      else log("There is not a clear shot to this target.");
+
     
+
      if ((Vehicle(C.Pawn).IsA('ONSHoverBike') || Vehicle(C.Pawn).IsA('ONSAttackCraft') || Vehicle(C.Pawn).IsA('ONSDualAttackCraft') || Vehicle(C.Pawn).IsA('ONSHoverCraft') ))
+
          log("This is one of our target vehicles.");
+
      else log("This is not one of our target vehicles.");
+
 
+
 
+
      //If the vehicle is not on our team, is being driven, has a clear trace between the projectile and the vehicle, and is of a specified type, then we proceed
+
      if ( C.Pawn != None && Vehicle(C.Pawn) != None && C.Pawn != Instigator && C.Pawn.Health > 0 && !C.SameTeamAs(Instigator.Controller) && VSize(C.Pawn.Location - Instigator.Location) < FlyingDamageRadius && FastTrace(C.Pawn.Location, Instigator.Location) && (Vehicle(C.Pawn).IsA('ONSHoverBike') || Vehicle(C.Pawn).IsA('ONSAttackCraft') || Vehicle(C.Pawn).IsA('ONSDualAttackCraft') || Vehicle(C.Pawn).IsA('ONSHoverCraft') ) )
+
      {
+
 
+
          //
+
          log("Success!!!");
+
 
+
          if ( Role == ROLE_Authority )
+
    {
+
      if (Other.Health < 100 && Other.Health > 25)
+
      {
+
                TempDamage = Max(1,(Other.Health - 25));
+
                Other.TakeDamage( TempDamage, Instigator, Other.Location, Normal(Location-Other.Location), MyDamageType);
+
                Other.DriverRadiusDamage( (TempDamage/3)+Rand(10), DamageRadius, Instigator.Controller, MyDamageType, MomentumTransfer, (Other.Location + VRand()*30) ); //We may need to change Hitlocation to Other.Location
+
                Other.EjectDriver();
+
                bZap = true;
+
            }
+
            else
+
            {
+
        Other.TakeDamage(Damage, Instigator, Other.Location, Normal(Location-Other.Location), MyDamageType);
+
                Other.DriverRadiusDamage( (Damage/3)+Rand(10), DamageRadius, Instigator.Controller, MyDamageType, MomentumTransfer, Other.Location );
+
                bZap = true;
+
            }
+
 
+
            //Log("Applying damage to nearby vehicle: "$(FlyingDamageRadius-(VSize(Location-Other.Location))) * Default.FlyingDamage/FlyingDamageRadius);
+
          }
+
         
+
          //Once this projectile has zapped something, draw the zap and then the projectile goes away.
+
          if (bZap)
+
          {
+
            HitEmitter = spawn(HitEmitterClass,,, Self.Location, rotator(Other.Location - Self.Location));
+
    if (HitEmitter != None)
+
      HitEmitter.mSpawnVecA = Other.Location;
+
  Other.PlaySound(ImpactSound,,8*TransientSoundVolume);
+
            Self.Destroy();
+
          }
+
      }
+
 
+
      C = NextC;
+
  }
+
 
+
  if (Velocity.Z > -1000)
+
  {
+
      Velocity.Z -= 30;
+
  }
+
}
+
 
+
 
+
defaultproperties
+
{
+
    Speed=4500.000000              //4500/5000/4000
+
    Damage=80.000000
+
    DamageRadius=275.000000        //275/220
+
    FlyingDamageRadius=1000.000000  //Because we reduced the frequency of the checks from .05 to .20, we increase the range here simply to increase the odds of it triggering successfully. Was 575/500/525/440
+
    MomentumTransfer=50000.000000
+
    LifeSpan=2.000000              //1.6
+
 
+
    ProjectileEffectClass=class'EONSScorpionEnergyProjectileEffectRed'
+
    HitEmitterClass=class'EONSScorpionEnergyProjectileZapEmitter'
+
    ExplosionEmitterClass=class'ONSPlasmaHitRed'
+
    ExplosionDecal=class'LinkBoltScorch'
+
    DrawScale=0.3
+
    AmbientGlow=100
+
    CullDistance=+8000.0
+
 
+
    TossZ=+0.0                  //225.0
+
    bFixedRotationDir=True
+
    DesiredRotation=(Pitch=12000,Yaw=5666,Roll=2334)
+
 
+
    bProjTarget=True
+
    bNetTemporary=True
+
 
+
    ImpactSound=Sound'DP_Explode'
+
    AmbientSound=Sound'WeaponSounds.BTranslocatorHoverModule'
+
    SoundRadius=100
+
    SoundVolume=255
+
 
+
    ForceType=FT_Constant
+
    ForceScale=5.0
+
    ForceRadius=60.0
+
 
+
    MyDamageType=class'DamTypeEONSScorpionEnergyProjectile'
+
}
+
</uscript>
+

Latest revision as of 07:41, 6 October 2011

This page is for pasting code you want to show someone as an example or to get assistance with. This allows you to easily collaborate with someone to solve a problem, and allows easy comparisons of the edits.

You are free to remove any existing code from below, and paste your code between the <uscript> </uscript> tags. If the page hasn't been edited in the last few hours (the last edit timestamp is 2011-10-06 07:41:16), you can assume it isn't needed anymore and can be removed. A full edit history will be available, so don't worry about losing anything you removed.

Clean up after you're done!


// paste your code here

Full Key[edit]

  • 1 – {$Topic is relevant/available to/in} Unreal Engine 1.
  • 2 – {$Topic is relevant/available to/in} Unreal Engine 2.
  • 2+ – {$Topic is relevant/available to/in} Unreal Engine 2, from this version onwards.
  • 2x – {$Topic is relevant/available to/in} Unreal Engine 2, starting with UT2004.
  • 3 – {$Topic is relevant/available to/in} Unreal Engine 3.
  • 3+ – {$Topic is relevant/available to/in} Unreal Engine 3, starting with UT3 patch 2.0.
  • 3* – {$Topic is relevant/available to/in} Unreal Engine 3, starting with UDK.
  • (no number) – {$Topic is relevant/available to/in} all Unreal Engine generations.


Enum Key[edit]

Vector(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3)--|
Range(U2, U2XMP, UE2Runtime, UT2003, UT2004)--|2
Vector2D(UDK, UT3)--|3
Color(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3)
LinearColor(UDK, UT3)

Class Key[edit]

Actor(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3)
Rook(no matching games found)
- TribesV? SoundCue(UDK, UT3)
UTGreedGame(UT3)
LegendObjectComponent(U2XMP)
FluidSurfaceOscillator(U2, U2XMP, UE2Runtime, UT2003, UT2004)
Ammunition(U2XMP, UE2Runtime, UT2003, UT2004)
Util(U2, U2XMP)
xUtil(no matching games found) -UE2??
UnrealPlayer(UT2003, UT2004)
xPlayer(no matching games found) -UE2??
UTPlayerController(UDK, UT3)
WeaponFire(UT2003, UT2004)

Keyword Key[edit]

Expands(no matching games found)
Extends(no matching games found)
server(no matching games found)
replicated(no matching games found)
intrinsic(no matching games found)