Results 1 to 4 of 4
  1. #1

    Default Problem: syntax for checking and changing a variable in a different class

    I am trying to modify the LoTrap mod (Valve portal gun for UT3) so that it will not work if it hits an unvalid wall. I have created a new type of Volume called LoTrapVolume and I have an edited version of the Weap_LoTrap gun that will clean up the portals if it hits an invalid wall.

    Essentially I do not know the syntax to be able to reference:

    If the object that is colliding with my LoTrapVolume is a LoTrap projectile
    Access and change a variable within another script ( from LoTrapVolume01.uc I need to change 'bValidWall' boolean, located in Weap_LoTrap_Edit01.uc, to false )

    I am new to unreal script, so saying - just look up documentation, does not help me.

    Following is my edited version of the Weap_LoTrap gun
    Code:
    class Weap_LoTrap_Edit extends Weap_LoTrap;
    
     // Is the wall valid to create a portal on?
     var bool bValidWall;
     var int whichPortalToCleanUp;
     
     
     // check whether Portal has hit a valid wall or not (based on hitting a LotrapVolume). 
    function bool HitValidPortalWall( vector HitLocation, vector HitNormal )
    {
    	if (bValidWall)
    	{
    		return true;
    	}
    	else 
    	{
    		
    		return false;
    	}
    
    }
    
    /* original CleanUpPortals function
    
    
    // Cleans up any existing portals
    simulated function CleanUpPortals()
    {
    	
    	if( m_Teleporters[0] != none )
    	{
    		m_Teleporters[0].BeginClose();
    	}
    
    	if( m_Teleporters[1] != none )
    	{
    		m_Teleporters[1].BeginClose();
    	}
    
    	// Even if the teleporters are destroyed, they aren't garbage collected unless we clean up references to them as well
    	m_Teleporters[0] = none;
    	m_Teleporters[1] = none;
    }
    
    */
    
    simulated function ProcessPortalHit( byte FiringMode, vector HitLocation, vector HitNormal )
    {
    	local byte OtherMode;
    
    	// Server side code only
    	if( Role != ROLE_Authority )
    	{
    		return;
    	}
    
    	// We are allowed to fire again now.
    	m_MyProjectile = none;
    
    	// Only continue if we hit a wall that is big enough for our portal
    	if( HitValidPortalWall( HitLocation, HitNormal ) )
    	{
    
    		OtherMode = (FiringMode == 1 ) ? 0 : 1;
    
    		if( m_Teleporters[FiringMode] == none )
    		{
    			if( FiringMode == 0 )
    			{
    				m_Teleporters[FiringMode] =	Spawn( class'LoTrap_Teleporter_Blue',,,HitLocation, rotator(HitNormal),,true );
    			}
    			else
    			{
    				m_Teleporters[FiringMode] =	Spawn( class'LoTrap_Teleporter_Red',,,HitLocation, rotator(HitNormal),,true );
    			}
    		}
    		else
    		{
    			m_Teleporters[FiringMode].SetLocation( HitLocation);
    			m_Teleporters[FiringMode].SetRotation(  rotator(HitNormal)  );
    		}
    
    		// Begins the scaling of the portal
    		m_Teleporters[FiringMode].BeginOpen();
    
    		// Update both the portals
    		m_Teleporters[FiringMode].SetTargetTeleporter( m_Teleporters[OtherMode] );
    
    		if( m_Teleporters[OtherMode] != none )
    		{
    			m_Teleporters[OtherMode].SetTargetTeleporter( m_Teleporters[FiringMode] );
    		}
    
    		m_Teleporters[FiringMode].UpdateRenderTarget();
    
    		if( m_Teleporters[OtherMode] != none )
    		{
    			m_Teleporters[OtherMode].UpdateRenderTarget();
    		}
    	} else
    	{
    		// I may need to split up this function to know whether it was the blue or orange portal which hit so the CleanUpPortals function does not destroy valid portals
    		CleanUpPortals();
    		
    		// clean up validity check
    		bValidWall = true;
    	}
    }
    Here is my attempt to create the LoTrapVolume

    Code:
    /**
     * Copyright 2012 Dale, Alison. All Rights Reserved.
     * Desctiption: Custom volume which stops Lotrap portals from occuring
     */
    
    class LotrapVolume01 extends Volume
    	native
    	placeable;
    
    var bool bNotValidWall;
    var bool bBounceHitObject;
    
    
    
    // On Touch with a LoTrap projectile will set the HitValidPortalWall return value to false. (HitValidPortalWall function is found in Weap_LoTrap.uc)
    event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
    {
    	// ? super.Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal );
    	
    	// Check whether the actor touching the volume is one of the LoTrap projectiles (there is a different projectile whether you click with the left or right mouse button)
    	AssociatedActor.Touch(Other, OtherComp, HitLocation, HitNormal);
    	
    	/* I'm not sure on the syntax with check if it is a Lotrap projectile */
    	If (Pawn(Other) != None && Pawn(Other) = /*REFERENCE LOTRAP Projectile*/ )
    	{
    		// Change the 'bValidWall' boolean in Weap_LoTrap_Edit.uc to false
    		/* Again, I need to learn how to reference and edit variables in other scripts */
    		// I may need to split up this function to know whether it was the blue or orange portal which hit so the CleanUpPortals function does not destroy valid portals
    		
    		
    	}
    }
    
    
    event UnTouch(Actor Other)
    {
        super.UnTouch(Other);
    
        if (Pawn(Other) != none && Pawn(Other) = /* REFERENCE LOTRAP PROJECTILE*/)
        {
    	
    	// TODO: Change the 'bValidWall' boolean in Weap_LoTrap_Edit.uc to True - NOT SURE HOW
    	}
    }
    
    simulated event PostBeginPlay()
    {
    	Super.PostBeginPlay();
    
    	// match bProjTarget to weapons (zero extent) collision setting
    	if (BrushComponent != None)
    	{
    		bProjTarget = BrushComponent.BlockZeroExtent;
    	}
    }
    
    simulated function bool StopsProjectile(Projectile P)
    {
    	return false;
    }
    
    defaultproperties
    {
       BrushColor=(B=200,G=177,R=72,A=255)
       bColored=True
       Begin Object Class=BrushComponent Name=BrushComponent0 ObjName=BrushComponent0 Archetype=BrushComponent'Engine.Default__Volume:BrushComponent0'
          ObjectArchetype=BrushComponent'Engine.Default__Volume:BrushComponent0'
       End Object
       BrushComponent=BrushComponent0
       Components(0)=BrushComponent0
       bProjTarget=True
       CollisionComponent=BrushComponent0
       SupportedEvents(1)=Class'Engine.SeqEvent_TakeDamage'
       Name="Default__LoTrapVolume"
       ObjectArchetype=Volume'Engine.Default__Volume'
    }

    Here is the original Weap_Lotrap code, if it helps
    Code:
    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------
    class Weap_LoTrap extends UTWeapon;
    
    /* List of teleporters that we have currently in existence */
    var LoTrap_Teleporter m_Teleporters[2];
    
    /* The pretty particle system for this weapon */
    var UTParticleSystemComponent m_ParticleSwirly;
    var UTParticleSystemComponent m_ParticleLeftBlue;
    var UTParticleSystemComponent m_ParticleRightOrange;
    
    /* Keeps track of the current projectile, to make sure we only have one in the air at a time */
    var LoTrap_Proj m_MyProjectile;
    
    simulated state Active
    {
    	simulated function BeginState( name PreviousStateName )
    	{
    		Super.BeginState( PreviousStateName );
    
    		// Attach the system to the 1st person mesh.
    		if( SkeletalMeshComponent( Mesh ) != none )
    		{
    			SkeletalMeshComponent( Mesh ).AttachComponentToSocket( m_ParticleSwirly, 'FX_Socket' );
    			SkeletalMeshComponent( Mesh ).AttachComponentToSocket( m_ParticleLeftBlue, 'Left' );
    			SkeletalMeshComponent( Mesh ).AttachComponentToSocket( m_ParticleRightOrange, 'Right' );
    
    			m_ParticleLeftBlue.SetDepthPriorityGroup(SDPG_Foreground);
    			m_ParticleLeftBlue.SetFOV(UTSkeletalMeshComponent(Mesh).FOV);
    
    			m_ParticleRightOrange.SetDepthPriorityGroup(SDPG_Foreground);
    			m_ParticleRightOrange.SetFOV(UTSkeletalMeshComponent(Mesh).FOV);
    
    			// Activate it.
    			m_ParticleLeftBlue.ActivateSystem();
    			m_ParticleRightOrange.ActivateSystem();
    			m_ParticleSwirly.ActivateSystem();
    		}
    	}
    }
    
    simulated function Projectile ProjectileFire()
    {
    	// Already have one in the air, destroy it.
    	if( m_MyProjectile != none )
    	{
    		m_MyProjectile.Destroy();
    	}
    
    	m_MyProjectile = LoTrap_Proj(Super.ProjectileFire());
    
    	if (m_MyProjectile != None )
    	{
    		m_MyProjectile.m_MyWeapon = self;
    	}
    
    	return m_MyProjectile;
    }
    
    function bool HitValidPortalWall( vector HitLocation, vector HitNormal )
    {
    	// make sure that the four corners from the hit location will be big enough to support our mesh.
    	return true;
    }
    
    /**
     * When destroyed, make sure we clean up any portals that are still around
     */
    simulated event Destroyed()
    {
    	super.Destroyed();
    
    	CleanUpPortals();
    }
    
    /**
     * A notification call when this weapon is removed from the Inventory of a pawn
     * @see Inventory::ItemRemovedFromInvManager
     */
    
    function ItemRemovedFromInvManager()
    {
    	Super.ItemRemovedFromInvManager( );
    	CleanUpPortals();
    }
    
    // Cleans up any existing portals
    simulated function CleanUpPortals()
    {
    	if( m_Teleporters[0] != none )
    	{
    		m_Teleporters[0].BeginClose();
    	}
    
    	if( m_Teleporters[1] != none )
    	{
    		m_Teleporters[1].BeginClose();
    	}
    
    	// Even if the teleporters are destroyed, they aren't garbage collected unless we clean up references to them as well
    	m_Teleporters[0] = none;
    	m_Teleporters[1] = none;
    }
    
    simulated function ProcessPortalHit( byte FiringMode, vector HitLocation, vector HitNormal )
    {
    	local byte OtherMode;
    
    	// Server side code only
    	if( Role != ROLE_Authority )
    	{
    		return;
    	}
    
    	// We are allowed to fire again now.
    	m_MyProjectile = none;
    
    	// Only continue if we hit a wall that is big enough for our portal
    	if( HitValidPortalWall( HitLocation, HitNormal ) )
    	{
    
    		OtherMode = (FiringMode == 1 ) ? 0 : 1;
    
    		if( m_Teleporters[FiringMode] == none )
    		{
    			if( FiringMode == 0 )
    			{
    				m_Teleporters[FiringMode] =	Spawn( class'LoTrap_Teleporter_Blue',,,HitLocation, rotator(HitNormal),,true );
    			}
    			else
    			{
    				m_Teleporters[FiringMode] =	Spawn( class'LoTrap_Teleporter_Red',,,HitLocation, rotator(HitNormal),,true );
    			}
    		}
    		else
    		{
    			m_Teleporters[FiringMode].SetLocation( HitLocation);
    			m_Teleporters[FiringMode].SetRotation(  rotator(HitNormal)  );
    		}
    
    		// Begins the scaling of the portal
    		m_Teleporters[FiringMode].BeginOpen();
    
    		// Update both the portals
    		m_Teleporters[FiringMode].SetTargetTeleporter( m_Teleporters[OtherMode] );
    
    		if( m_Teleporters[OtherMode] != none )
    		{
    			m_Teleporters[OtherMode].SetTargetTeleporter( m_Teleporters[FiringMode] );
    		}
    
    		m_Teleporters[FiringMode].UpdateRenderTarget();
    
    		if( m_Teleporters[OtherMode] != none )
    		{
    			m_Teleporters[OtherMode].UpdateRenderTarget();
    		}
    	}
    }
    simulated function String GetHumanReadableName()
    {
    	return "LoTrap Gun";
    }
    
    defaultproperties
    {
       Begin Object Class=UTParticleSystemComponent Name=Particle_Swirly ObjName=Particle_Swirly Archetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
          Template=ParticleSystem'WP_LoTrap.FX.FX_LoTrapSwirly'
          SecondsBeforeInactive=0.000000
          Name="Particle_Swirly"
          ObjectArchetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
       End Object
       m_ParticleSwirly=Particle_Swirly
       Begin Object Class=UTParticleSystemComponent Name=Particle_LeftBlue ObjName=Particle_LeftBlue Archetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
          Template=ParticleSystem'WP_LoTrap.FX.FX_LeftBlue'
          SecondsBeforeInactive=0.000000
          Name="Particle_LeftBlue"
          ObjectArchetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
       End Object
       m_ParticleLeftBlue=Particle_LeftBlue
       Begin Object Class=UTParticleSystemComponent Name=Particle_RightOrange ObjName=Particle_RightOrange Archetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
          Template=ParticleSystem'WP_LoTrap.FX.FX_RightOrange'
          SecondsBeforeInactive=0.000000
          Name="Particle_RightOrange"
          ObjectArchetype=UTParticleSystemComponent'UTGame.Default__UTParticleSystemComponent'
       End Object
       m_ParticleRightOrange=Particle_RightOrange
       ShotCost(0)=0
       ShotCost(1)=0
       InventoryGroup=1
       AttachmentClass=Class'LoTrap.Attachment_LoTrap'
       GroupWeight=0.700000
       ArmsAnimSet=AnimSet'WP_FlakCannon.Anims.K_WP_FlakCannon_1P_Arms'
       WeaponFireSnd(0)=SoundCue'A_Weapon_FlakCannon.Weapons.A_FlakCannon_FireAltCue'
       WeaponFireSnd(1)=SoundCue'A_Weapon_FlakCannon.Weapons.A_FlakCannon_FireAltCue'
       WeaponPutDownSnd=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_LowerCue'
       WeaponEquipSnd=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_RaiseCue'
       MuzzleFlashSocket="MuzzleFlash"
       MuzzleFlashPSCTemplate=ParticleSystem'WP_ShockRifle.Particles.P_ShockRifle_MF_Alt'
       WeaponFireTypes(0)=EWFT_Projectile
       WeaponFireTypes(1)=EWFT_Projectile
       WeaponProjectiles(0)=Class'LoTrap.LoTrap_Proj_Primary'
       WeaponProjectiles(1)=Class'LoTrap.LoTrap_Proj_Alt'
       Begin Object Class=UTSkeletalMeshComponent Name=FirstPersonMesh ObjName=FirstPersonMesh Archetype=UTSkeletalMeshComponent'UTGame.Default__UTWeapon:FirstPersonMesh'
          FOV=60.000000
          SkeletalMesh=SkeletalMesh'WP_LoTrap.Meshes.SK_WP_LoTrap'
          Animations=UTAnimNodeSequence'LoTrap.Default__Attachment_LoTrap:SkeletalMeshComponent0.MeshSequenceA'
          AnimSets(0)=AnimSet'WP_Translocator.Anims.K_WP_Translocator_1P_Base'
          Translation=(X=-6.000000,Y=0.000000,Z=-4.000000)
          ObjectArchetype=UTSkeletalMeshComponent'UTGame.Default__UTWeapon:FirstPersonMesh'
       End Object
       Mesh=FirstPersonMesh
       Begin Object Class=SkeletalMeshComponent Name=PickupMesh ObjName=PickupMesh Archetype=SkeletalMeshComponent'UTGame.Default__UTWeapon:PickupMesh'
          SkeletalMesh=SkeletalMesh'WP_LoTrap.Meshes.SK_WP_LoTrap_MID'
          ObjectArchetype=SkeletalMeshComponent'UTGame.Default__UTWeapon:PickupMesh'
       End Object
       DroppedPickupMesh=PickupMesh
       PickupFactoryMesh=PickupMesh
       Name="Default__Weap_LoTrap"
       ObjectArchetype=UTWeapon'UTGame.Default__UTWeapon'
    }
    Thankyou for whatever help you can give me on this.

  2. #2

    Default

    Well, basically you access properties and change its value by having an instance of a class - like in the most OOP languages

    Code:
    class O extends Object;
    
    var int MyVar;
    Code:
    class A extends Actor placeable;
    
    var O MyObject;
    
    event PostBeginPlay()
    {
        // this creates an instance
        MyObject = new class'O';
    
        `Log("Old value:"@MyObject.MyVar);
        // adding 5 to the properties
        MyObject.MyVar = MyObject.MyVar + 5
        // can also be written as:
        // MyObject.MyVar += 5
    
        `Log("New value:"@MyObject.MyVar);
    }
    This is a basic example for accessing a variable.

    --------------------------

    But if you want to access a variable of a child class but you have only a variable of the parent class you need to cast the object

    Code:
    class O2 extends O;
    
    var int MyVar2;
    Code:
    class A2 extends Actor placeable;
    
    var O MyObject;
    
    event PostBeginPlay()
    {
        // this creates an instance of O2 but stored in a Ovar
        // it's possible because O is a parent of O2
        MyObject = new class'O2';
       
    
        `Log("Old value:"@MyObject.MyVar);
        // adding 5 to the properties
        MyObject.MyVar += 7
    
        `Log("New value:"@MyObject.MyVar);
    
    
        // this will cause a error on compiling because the properties is not accessible on design-time
        //`Log("New var:"@MyObject.MyVar2);
    
        // casting object and accessing props
        // casted object = CLASSNAME(INSTANCED_OBJECT)
        // O2(MyObject)
        `Log("Old value MyVar2:"@ O2(MyObject).MyVar2);
        // adding 10 to the properties
        MyObject.MyVar2 += 10
    
        `Log("New value MyVar2:"@O2(MyObject).MyVar2);
    }

    So the key to success: Casting

    You may also check the following page.
    http://udn.epicgames.com/Three/Unrea...Reference.html
    and it's subpages:
    http://udn.epicgames.com/Three/UnrealScriptReference.html#Language Features
    --------------------------------------

    If you want to check if an actor is a type of another class (existing one on design-time) you can get this by casting the object.

    Code:
    function RandomF(Actor a)
    {
        if (Pawn(a) != none) {
            // the Actor is a Pawn
            // do something
        }
        if (Projectile(a) != none) {
            // the Actor is a Projectile
            // do something
        }
    }
    ---------------------------

    Regarding the LoTrap code. I created a quick version of the custom volume. The volume as 4 properties (to be set in the editor). This volume needs the CollisionType property set to COLLIDE_BlockAll.

    • bAllowBluePortal: If set, you can only shoot blue portals on this "surface".
    • bAllowRedPortal: If set, you can only shoot red portals on this "surface".
    • TeamNum: The team number this volume belongs to (255 for no team)
    • bAllowOnlyTeam: If set, only players of the same team can shoot a portal on this "surface"



    The volume code
    Code:
    class LoTrap_Volume extends Volume
        placeable;
    
    var(LoTrap) byte TeamNum;
    var(LoTrap) bool bAllowOnlyTeam;
    var(LoTrap) bool bAllowBluePortal;
    var(LoTrap) bool bAllowRedPortal;
    
    function CheckProjectile(Actor Other)
    {
        if (Other != none && LoTrap_Proj(Other) != none) {
    
            // only change bValidWall if either bAllowOnlyTeam is false (=any team is allowed to put portals on it) 
            // or the TeamNum is the same as the projectiles ones (so a Team members has fired the projectile)
            if (!bAllowOnlyTeam || Other.GetTeamNum() == TeamNum) {
    
                // Casting Other to LoTrap_Proj to access porperties of the new class
                if( LoTrap_Proj(Other).m_MyWeapon != none && Weap_LoTrapCustom(LoTrap_Proj(Other).m_MyWeapon) != none)
                {
                    // check if the player/weapon has the correct firemode to spawn the specific portal
                    if (LoTrap_Proj(Other).m_iMyFireMode == 0 && bAllowBluePortal) {
                        Weap_LoTrapCustom(LoTrap_Proj(Other).m_MyWeapon).bValidWall = true;
                    } else if (LoTrap_Proj(Other).m_iMyFireMode == 1 && bAllowRedPortal ) {
                        Weap_LoTrapCustom(LoTrap_Proj(Other).m_MyWeapon).bValidWall = true;
                    }
                }
            }
        }
    }
    
    event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
    {
        CheckProjectile(Other);
    
        super.Touch(Other, OtherComp, HitLocation, HitNormal);
    }
    
    event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal )
    {
        CheckProjectile(Other);
    
        super.Bump(Other, OtherComp, HitNormal);
    }
    
    // No need to handle a special untouch event for LoTrap projectiles
    event UnTouch( Actor Other )
    {
        super.UnTouch(Other);
    }
    
    DefaultProperties
    {
        // use COLLIDE_BlockAll to have a portal on a Volume
        //CollisionType=COLLIDE_TouchAll
        CollisionType=COLLIDE_BlockAll
        BlockRigidBody=true
    
        TeamNum=255
        bAllowOnlyTeam=false
        bAllowBluePortal=true
        bAllowRedPortal=true
    }
    Weapon code
    Code:
    class Weap_LoTrapCustom extends Weap_LoTrap;
    
    var bool bValidWall;
    
    simulated function FireAmmunition()
    {
        // Server side code only
        if( Role != ROLE_Authority )
        {
            bValidWall = false;
        }
    
        super.FireAmmunition();    
    }
    
    function bool HitValidPortalWall( vector HitLocation, vector HitNormal )
    {
        return bValidWall;
    }
    
    DefaultProperties
    {
    }
    --------------------

    Regarding your code:
    There are several problems with your code. This post is too long already. Let me know, if you want to know the points.

  3. #3

    Default

    Thankyou so much. It is helpful to have it in such simple terms with examples. I will go and code my heart away now and get back if I have any more trouble.

  4. #4

    Default

    So I have tried your code, and no matter where I shoot, the portal is not made. I tried editing my code and stops one portal being made (no matter where it is shot) and then you may shoot anywhere.

    As a side note, I also have to have the volume so that it allows the players to walk through it (like the emansipation grid in portal). I won't worry about cleaning up all portals if you go through it though. Im guessing that will take me way too long for now.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.