Announcement

Collapse
No announcement yet.

New to Unreal script Need help with a weapon Mod

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

    New to Unreal script Need help with a weapon Mod

    UT2004
    FIrst off this is my first attempt with unreal script although I have programed in C++ before.I've just watched the VTMs that came with UT2k4 about Unrealscript and made their concussion rifle. I understand how it works but I have been trying to be able to make it zoom. I tried to have the rifle inherit the zoom capabilties of other guns (such as the sniper rifle) through the extends command but I can't get it to work. Any help would be greatly appreciated. Listed below is all my code.
    //=============================================
    //ConcussionRifle
    //This is your inventory class
    //=============================================
    class zoomrifle extends ShockRifle;

    defaultproperties
    {
    ItemName="zoomrifleFire"
    FireModeClass(0)=zoomriflefire
    FiremodeClass(1)=zoomriflezoom
    PickupClass=class'zoomriflePickup'
    }

    //=============================================
    // ConcussionRiflePickup
    //=============================================

    class zoomriflePickup extends ShockRiflePickup;

    defaultproperties
    {
    InventoryType=class'zoomrifle'
    PickupMessage="You got the zoomRifle."
    }

    //=============================================
    //Zoomrifle
    //This is your fire class
    //=============================================
    class zoomrifleFire extends ShockBeamFire;

    defaultproperties
    {
    Momentum=+1000000.0
    DamageMin=0
    DamageMax=0
    }

    Lastly this is what I'm trying to get the zoom out of but it does'nt seem to work, I guess if someone can point me to the correct direction that would be great.
    //=============================================
    //This supposeed to extend the zoom capabilty to the shock rifle
    //=============================================
    class zoomriflezoom extends SniperZoom;

    defaultproperties
    {

    }

    #2
    This should be your ShockRifle Code:
    Code:
    //=============================================
    //ConcussionRifle
    //This is your inventory class
    //=============================================
    class zoomrifle extends ShockRifle;
    
    var(Gfx) float testX;
    var(Gfx) float testY;
    
    var(Gfx) float borderX;
    var(Gfx) float borderY;
    
    var(Gfx) float focusX;
    var(Gfx) float focusY;
    var(Gfx) float innerArrowsX;
    var(Gfx) float innerArrowsY;
    var(Gfx) Color ArrowColor;
    var(Gfx) Color TargetColor;
    var(Gfx) Color NoTargetColor;
    var(Gfx) Color FocusColor;
    var(Gfx) Color ChargeColor;
    
    var(Gfx) vector RechargeOrigin;
    var(Gfx) vector RechargeSize;
    
    var transient float LastFOV;
    var() bool zoomed;
    var() xEmitter  chargeEmitter;
    
    simulated function PostBeginPlay()
    {
        Super.PostBeginPlay();
    }
    
    simulated function bool WeaponCentered()
    {
    	return ( zoomed || bSpectated || (Hand > 1) );
    }
    
    simulated function Destroyed()
    {
        if (chargeEmitter != None)
            chargeEmitter.Destroy();
    
        Super.Destroyed();
    }
    
    simulated function ClientWeaponThrown()
    {
        if( Instigator != None && Instigator.Controller.IsA( 'PlayerController' ) )
            PlayerController(Instigator.Controller).EndZoom();
        Super.ClientWeaponThrown();
    }
    
    // compensate for bright fog
    simulated function SetZoomBlendColor(Canvas c)
    {
        local Byte    val;
        local Color   clr;
        local Color   fog;
    
        clr.R = 255;
        clr.G = 255;
        clr.B = 255;
        clr.A = 255;
    
        if( Instigator.Region.Zone.bDistanceFog )
        {
            fog = Instigator.Region.Zone.DistanceFogColor;
            val = 0;
            val = Max( val, fog.R);
            val = Max( val, fog.G);
            val = Max( val, fog.B);
    
            if( val > 128 )
            {
                val -= 128;
                clr.R -= val;
                clr.G -= val;
                clr.B -= val;
            }
        }
        c.DrawColor = clr;
    }
    
    simulated event RenderOverlays( Canvas Canvas )
    {
    	local float tileScaleX;
    	local float tileScaleY;
    	local float bX;
    	local float bY;
    	local float fX;
    	local float fY;
    	local float ChargeBar;
    
    	local float tX;
    	local float tY;
    
    	local float barOrgX;
    	local float barOrgY;
    	local float barSizeX;
    	local float barSizeY;
    
        if ( LastFOV > PlayerController(Instigator.Controller).DesiredFOV )
        {
            PlaySound(Sound'WeaponSounds.LightningGun.LightningZoomIn', SLOT_Misc,,,,,false);
        }
        else if ( LastFOV < PlayerController(Instigator.Controller).DesiredFOV )
        {
            PlaySound(Sound'WeaponSounds.LightningGun.LightningZoomOut', SLOT_Misc,,,,,false);
        }
        LastFOV = PlayerController(Instigator.Controller).DesiredFOV;
    
        if ( PlayerController(Instigator.Controller).DesiredFOV == PlayerController(Instigator.Controller).DefaultFOV )
    	{
            Super.RenderOverlays(Canvas);
    		zoomed=false;
    	}
    	else
        {
    
    		if ( FireMode[0].NextFireTime <= Level.TimeSeconds )
    		{
    			ChargeBar = 1.0;
    		}
    		else
    		{
    			ChargeBar = 1.0 - ((FireMode[0].NextFireTime-Level.TimeSeconds) / FireMode[0].FireRate);
    		}
    
    		tileScaleX = Canvas.SizeX / 640.0f;
    		tileScaleY = Canvas.SizeY / 480.0f;
    
    		bX = borderX * tileScaleX;
    		bY = borderY * tileScaleY;
    		fX = focusX * tileScaleX;
    		fY = focusY * tileScaleX;
    
    		tX = testX * tileScaleX;
    		tY = testY * tileScaleX;
    
    		barOrgX = RechargeOrigin.X * tileScaleX;
    		barOrgY = RechargeOrigin.Y * tileScaleY;
    
    		barSizeX = RechargeSize.X * tileScaleX;
    		barSizeY = RechargeSize.Y * tileScaleY;
    
            SetZoomBlendColor(Canvas);
    
            Canvas.Style = 255;
    		Canvas.SetPos(0,0);
            Canvas.DrawTile( Material'ZoomFB', Canvas.SizeX, Canvas.SizeY, 0.0, 0.0, 512, 512 ); // !! hardcoded size
    
    		Canvas.DrawColor = FocusColor;
            Canvas.DrawColor.A = 255; // 255 was the original -asp. WTF??!?!?!
    		Canvas.Style = ERenderStyle.STY_Alpha;
    
    		Canvas.SetPos((Canvas.SizeX*0.5)-fX,(Canvas.SizeY*0.5)-fY);
    		Canvas.DrawTile( Texture'SniperFocus', fX*2.0, fY*2.0, 0.0, 0.0, Texture'SniperFocus'.USize, Texture'SniperFocus'.VSize );
    
            fX = innerArrowsX * tileScaleX;
    		fY = innerArrowsY * tileScaleY;
    
            Canvas.DrawColor = ArrowColor;
            Canvas.SetPos((Canvas.SizeX*0.5)-fX,(Canvas.SizeY*0.5)-fY);
    		Canvas.DrawTile( Texture'SniperArrows', fX*2.0, fY*2.0, 0.0, 0.0, Texture'SniperArrows'.USize, Texture'SniperArrows'.VSize );
    
    
    		// Draw the Charging meter  -AsP
    		Canvas.DrawColor = ChargeColor;
            Canvas.DrawColor.A = 255;
    
    		if(ChargeBar <1)
    		    Canvas.DrawColor.R = 255*ChargeBar;
    		else
            {
                Canvas.DrawColor.R = 0;
    		    Canvas.DrawColor.B = 0;
            }
    
    		if(ChargeBar == 1)
    		    Canvas.DrawColor.G = 255;
    		else
    		    Canvas.DrawColor.G = 0;
    
    		Canvas.Style = ERenderStyle.STY_Alpha;
    		Canvas.SetPos( barOrgX, barOrgY );
    		Canvas.DrawTile(Texture'Engine.WhiteTexture',barSizeX,barSizeY*ChargeBar, 0.0, 0.0,Texture'Engine.WhiteTexture'.USize,Texture'Engine.WhiteTexture'.VSize*ChargeBar);
    		zoomed = true;
    	}
    }
    
    simulated function ClientStartFire(int mode)
    {
        if (mode == 1)
        {
            FireMode[mode].bIsFiring = true;
            if( Instigator.Controller.IsA( 'PlayerController' ) )
                PlayerController(Instigator.Controller).ToggleZoom();
        }
        else
        {
            Super.ClientStartFire(mode);
        }
    }
    
    simulated function ClientStopFire(int mode)
    {
        if (mode == 1)
        {
            FireMode[mode].bIsFiring = false;
            if( Instigator.Controller.IsA( 'PlayerController' ) )
                PlayerController(Instigator.Controller).StopZoom();
        }
        else
        {
            Super.ClientStopFire(mode);
        }
    }
    
    simulated function BringUp(optional Weapon PrevWeapon)
    {
        if ( PlayerController(Instigator.Controller) != None )
            LastFOV = PlayerController(Instigator.Controller).DesiredFOV;
        Super.BringUp();
    }
    
    simulated function bool PutDown()
    {
        if( Instigator.Controller.IsA( 'PlayerController' ) )
            PlayerController(Instigator.Controller).EndZoom();
        if ( Super.PutDown() )
        {
    		GotoState('');
    		return true;
    	}
    	return false;
    }
    
    simulated function IncrementFlashCount(int Mode)
    {
    	if ( Mode == 1 )
    		return;
    	Super.IncrementFlashCount(Mode);
    }
    
    defaultproperties
    {
        testX=100.00
        testY=100.00
        borderX=60.00
        borderY=60.00
        focusX=135.00
        focusY=105.00
        innerArrowsX=42.00
        innerArrowsY=42.00
        ArrowColor=(R=0,G=0,B=255,A=255),
        TargetColor=(R=255,G=255,B=255,A=255),
        NoTargetColor=(R=200,G=200,B=200,A=255),
        FocusColor=(R=126,G=90,B=71,A=215),
        ChargeColor=(R=255,G=255,B=255,A=255),
        RechargeOrigin=(X=600.00,Y=330.00,Z=0.00),
        RechargeSize=(X=10.00,Y=-180.00,Z=0.00),
        FireModeClass(0)=zoomriflefire
        FireModeClass(1)=Class'SniperZoom'
        bSniping=True
        PickupClass=class'zoomriflePickup'
    }
    I Guess they left out a few parts XD Thats Right From The ZoomShockRifle That UT Comes Wit

    Comment


      #3
      hey thanks alot for that code. I was looking at UT2k4 code for their zooming shock rifle but I could'nt figure out what I needed from it.

      Comment


        #4
        Some things - like PostBeginPlay() - should not be needed, though.

        Also, it sometimes maybe be faster to extend the weapon that uses zoom directly instead of pasting the code. It all depends on what you want to do exactly.

        Comment


          #5
          oh lol thats right from epic code!

          Comment


            #6
            Originally posted by ^::B!G-A::
            oh lol thats right from epic code!
            I know, but it doesn't mean it's perfect.
            And if he's new to scripting, maybe he doesn't know that extends allows to skip some data's

            Comment


              #7
              The problem with what you were doing Atilla76 is that if you look into the SniperZoom class it actually doesnt include any of its own code, all it does is extends WeaponFire (which is only very general info about how a gun shoots stuff) and modifies a few default properties. The actual sniper zoom code is done in the SniperRifle class which is pretty much the code given by B!G-A there.

              A few of the most interesting parts of that code related to the zoom:

              The renderoverlays function seems to be putting up all the pretty pictures of the scope and charge bars and so on, also seems to be playing sounds (what the heck has the sound got to do with overlays! )

              The clientstartfire and clientstopfire seem to be doing the main decisions about zooming in or out and are calling functions from the PlayerController class, namely ToggleZoom() and StopZoom(). In specific clientstartfire sets bIsFiring to true, then if its alt fire it will call the ToggleZoom function and if it is not (ie primary fire) it will use the ShockRifle primary fire. ClientStopFire first sets bIsFiring to false, then if its alt fire it will call StopZoom and if it is primary fire it will do the ShockRifle primary fire. Fairly simple!

              I would guess that if you wanted a zoom fairly similar to the vehicle turret zooming (ie no overlays) you could probably get away with just calling the ToggleZoom() and StopZoom() functions.

              Comment


                #8
                RenderOverlays does draw the graphics (RenderOverlays is a hook in weapon to allow canvas drawing in first person), and the sounds get played when the player zooms in or out, its played there because you can tell the zoom level has changed since the last time you drew the graphics.

                As for the simplified zoom, just take out the RenderOverlays function (make it blank, dont just delete it), and it will probably accomplish what is wanted. No promises, as I havent studied the code long enough to know for sure.

                The zoom is really just a hack from the PC, and is implemented backwards imo. For my TC mod I had to switch some things around to get the zoom to work (we are third person, and zooming is still considered first person, especially since RenderOverlays is first person only).

                Comment


                  #9
                  Originally posted by Bonehed316
                  As for the simplified zoom, just take out the RenderOverlays function (make it blank, dont just delete it), and it will probably accomplish what is wanted. No promises, as I havent studied the code long enough to know for sure.
                  A simplified zoom example (no overlays, reverts to normal fov when fire is released). I only put two functions : the ones that handle zooming. 'Stolen' and adapted from the sniper
                  Code:
                  simulated function ClientStartFire(int mode) {
                      if (mode == 1) {
                          FireMode[mode].bIsFiring = true;
                          if( Instigator.Controller.IsA( 'PlayerController' ) )
                              PlayerController(Instigator.Controller).ToggleZoomWithMax(0.9);
                      } else
                          Super.ClientStartFire(mode);
                  }
                  
                  simulated function ClientStopFire(int mode) {
                      if (mode == 1) {
                          FireMode[mode].bIsFiring = false;
                          if( PlayerController(Instigator.Controller) != None )
                              PlayerController(Instigator.Controller).EndZoom();
                      } else
                          Super.ClientStopFire(mode);
                  }
                  If player fires, I let the parent class handling it. If he alt-fires, I zoom in.
                  My alt-fire class extends SniperZoom. If it doesn't, it is important that you add
                  Code:
                  bModeExclusive=false
                  in your altfire class to allow both firing and zooming.

                  Comment


                    #10
                    Thanks Guys

                    Sorry I did'nt respond sooner. Thanks for the more in depth explanation of the code. I really did'nt have a clue what the actual code was doing untill you explained it. I just don't have enough background knowledge of Unreal's classes functions and variable names. But I'll get there sooner or later.

                    Comment

                    Working...
                    X