Announcement

Collapse
No announcement yet.

I need UnrealScript help

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

  • replied
    Basically the above code deals with the fact that projectiles must first travel the path between your weapon (where it is spawned using the fire class) and where ever it collides with something. There is a lot of stuff that can happen and especially in the case of the flak shell, it has to take into account how gravity affects it (as well as various zone effects)
    so lets look at the code:
    Code:
    simulated function PostBeginPlay()
    {
    	local Rotator R;
    	local PlayerController PC;
    	
    	if ( !PhysicsVolume.bWaterVolume && (Level.NetMode != NM_DedicatedServer) )
    	{
    		PC = Level.GetLocalPlayerController();
    		if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 6000 )
    			Trail = Spawn(class'FlakShellTrail',self);
    		Glow = Spawn(class'FlakGlow', self);
    	}
    
    	Super.PostBeginPlay();
    	Velocity = Vector(Rotation) * Speed;  
    	R = Rotation;
    	R.Roll = 32768;
    	SetRotation(R);
    	Velocity.z += TossZ; 
    	initialDir = Velocity;
    }
    This part is what happens when the projectile is spawned, every actor out there has a couple of things that are done to it. PostBeginPlay is one those steps.

    In this particular case, right after the object is finsihed spawning, it spawns a trail emmiter, a glow effect, and gives itself a intiial direction and velocity (since the object had PHYS_Falling as is determined by the defualt proprties, UT will automaitically apply gravity to it in the effect of negative z velocity....)

    Next:
    Code:
    simulated function destroyed()
    {
    	if ( Trail != None ) 
    		Trail.mRegen=False;
    	if ( glow != None )
    		Glow.Destroy();
    	Super.Destroyed();
    }
    This is called when the object is destroyed. Since it spawned the Trail and glow effects, you want to make sure it destroys them before it destroys itself.

    Code:
    simulated function ProcessTouch(Actor Other, Vector HitLocation)
    {
    	if ( Other != Instigator )
    	{
    		SpawnEffects(HitLocation, -1 * Normal(Velocity) );
    		Explode(HitLocation,Normal(HitLocation-Other.Location));
    	}
    }
    
    simulated function Landed( vector HitNormal )
    {
    	SpawnEffects( Location, HitNormal );
    	Explode(Location,HitNormal);
    }
    
    simulated function HitWall (vector HitNormal, actor Wall)
    {
    	Landed(HitNormal);
    }
    Ok I grouped the above functions (event hough they are not in code) cause they are all related.

    Uscript is not as efficiant as native code, thus a lot of it is event driven. You try to write code that spends most of it's time waiting for the engine to pass an event to it. In the case of projectiles, there are three functions that might be called on collison with another obeject:
    ProccessTouch, called when an actor colides with another actor
    Landed, called when the actor hits a mostly horzontal pice of geometry
    HitWall, called when it hits a mostly vertical pice of geometry (or a static mesh)

    This is so you don't have to keep cheching in code every tick if the projectile collided with something. (wchi is very inefficient)

    So anhow the above says, "If I hit something, SpawnEffects (calles the SpawnEffects Funciton), and Explode (call the explode funciton)"

    The above two funcitons could have been merged, I think they sperated them to keep the code alittle cleaner...

    Code:
    simulated function SpawnEffects( vector HitLocation, vector HitNormal )
    {
    	local PlayerController PC;
    
    	PlaySound (Sound'WeaponSounds.BExplosion1',,3*TransientSoundVolume);
    	if ( EffectIsRelevant(Location,false) )
    	{
    		PC = Level.GetLocalPlayerController();
    		if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 3000 )
    			spawn(class'FlakExplosion',,,HitLocation + HitNormal*16 );
    		spawn(class'FlashExplosion',,,HitLocation + HitNormal*16 );
    		spawn(class'RocketSmokeRing',,,HitLocation + HitNormal*16, rotator(HitNormal) );
    		if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
    			Spawn(ExplosionDecal,self,,HitLocation, rotator(-HitNormal));
    	}
    }
    This makes all the smoke and **** when the flak shell hit someting

    Code:
    simulated function Explode(vector HitLocation, vector HitNormal)
    {
    	local vector start;
        local rotator rot;
        local int i;
        local FlakChunk NewChunk;
    
    	start = Location + 10 * HitNormal;
    	if ( Role == ROLE_Authority )
    	{
    		HurtRadius(damage, 220, MyDamageType, MomentumTransfer, HitLocation);	
    		for (i=0; i<6; i++)
    		{
    			rot = Rotation;
    			rot.yaw += FRand()*32000-16000;
    			rot.pitch += FRand()*32000-16000;
    			rot.roll += FRand()*32000-16000;
    			NewChunk = Spawn( class 'FlakChunk',, '', Start, rot);
    		}
    	}
        Destroy();
    }
    This part actually hurts anythng nearby to the flakshell when it explodes, and it also spawns the flakchunk shrapnel

    At the end it als destroys itself, this is because once the shell has exploded, it has finsihed it's task


    Anyhow hope this all helps... take a look through http://wiki.beyondunreal.com , it's a good read

    Leave a comment:


  • replied
    heres some of em:

    var in the beginning are class variables (default public)
    by using var() u can make editable parameters in the unrealEd actor properties menu.

    simulated means it can be executed as a simulated proxy, updating it client side, in other words, this function happens on the client and server.

    I assume ur familliar with functions and parameters....

    PlaySound and Spawn are actor class functions inherited, they are also native, but that really dosent mean that much to the average programmer...and keep in mind UnrealScript isnt case sensitive.

    Just realize theres rotators, and vectors that are used regularly, and most functions u mess with are built in to the game, and ur merely extending or modifying them.

    The section u cut off is default properties, the starting valuse for class variables, requires no semicolon, and many can be edited in unrealed if the actor is placeable (such as a static mesh or a trigger).

    helps?

    Leave a comment:


  • replied
    Im not gonna go through and explain every single parameter but if you list a couple lines I can explain them for you.

    Leave a comment:


  • started a topic I need UnrealScript help

    I need UnrealScript help

    I understand the concept of UnrealScript, (classes, subclasses, OOP) and I made this mod that I learned from 3DBuzz but I am not exactly getting it. I look at the scripts in the actor class browser and it just doesn't make much sense. Here is the script for the flak shell. //================================================== ===========================
    // flakshell
    //================================================== ===========================
    class flakshell extends Projectile;

    #exec TEXTURE IMPORT NAME=NewFlakSkin FILE=textures\jflakslugel1.bmp GROUP="Skins" DXT=5

    var xemitter trail;
    var vector initialDir;

    simulated function PostBeginPlay()
    {
    local Rotator R;

    if ( !PhysicsVolume.bWaterVolume && (Level.NetMode != NM_DedicatedServer) )
    Trail = Spawn(class'FlakShellTrail',self);

    Super.PostBeginPlay();
    Velocity = Vector(Rotation) * Speed;
    R = Rotation;
    R.Roll = 32768;
    SetRotation(R);
    Velocity.z += TossZ;
    initialDir = Velocity;
    }

    simulated function destroyed()
    {
    if (Trail!=None)
    Trail.mRegen=False;
    Super.Destroyed();
    }


    simulated function ProcessTouch(Actor Other, Vector HitLocation)
    {
    if ( Other != Instigator )
    {
    SpawnEffects(HitLocation, -1 * Normal(Velocity) );
    Explode(HitLocation,Normal(HitLocation-Other.Location));
    }
    }

    simulated function SpawnEffects( vector HitLocation, vector HitNormal )
    {
    PlaySound (Sound'WeaponSounds.BExplosion1',,3*TransientSound Volume);
    if ( EffectIsRelevant(Location,false) )
    {
    spawn(class'FlakExplosion',,,HitLocation + HitNormal*16 );
    spawn(class'FlashExplosion',,,HitLocation + HitNormal*16 );
    spawn(class'RocketSmokeRing',,,HitLocation + HitNormal*16, rotator(HitNormal) );
    if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
    Spawn(ExplosionDecal,self,,HitLocation, rotator(-HitNormal));
    }
    }

    simulated function Landed( vector HitNormal )
    {
    SpawnEffects( Location, HitNormal );
    Explode(Location,HitNormal);
    }

    simulated function HitWall (vector HitNormal, actor Wall)
    {
    Landed(HitNormal);
    }

    simulated function Explode(vector HitLocation, vector HitNormal)
    {
    local vector start;
    local rotator rot;
    local int i;
    local FlakChunk NewChunk;

    start = Location + 10 * HitNormal;
    if ( Role == ROLE_Authority )
    {
    HurtRadius(damage, 220, MyDamageType, MomentumTransfer, HitLocation);
    for (i=0; i<6; i++)
    {
    rot = Rotation;
    rot.yaw += FRand()*32000-16000;
    rot.pitch += FRand()*32000-16000;
    rot.roll += FRand()*32000-16000;
    NewChunk = Spawn( class 'FlakChunk',, '', Start, rot);
    }
    }
    Destroy();
    }
    I just don't fully get it, I mean why cant it just say press primary fire and play animation of flak shell exploding or something like that? Like I said I understand some things like variables and functions like + and - but some of the code makes no sense. Please help!!
Working...
X