Need help with code for new dynamic decoration

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Silver_Ibex

Member
Feb 27, 2001
654
0
16
Need help with code to tell a Decoration, that when grabbed, to move up/rise vertically a set number of units, and then when Grabbed again it lowers back to its starting position.

This could be done with a standard toggle trigger mover, but I have very specific reasons not to use a normal mover.

It just needs to move vertically. Would be nice to have the move speed and height adjustable in the editor properties.

After looking at the Inf Turret Decoration code, I think something like the following script would work to detect the Grab.

Now I just need to know how to go about changing the height.

Code:
function Grab( actor Other, pawn EventInstigator )
{
	if ( Other.IsInState('Dying') || Other.IsInState('PlayerSpectating') || Other.bHidden )
		return;

	if (Pawn(Other) == None)
		return;
	if ( !Pawn(Other).bIsPlayer )
		return;
	
	if	(	!bOPened
		||	( PlayerPawn(Other) != None)
		)
	{
		bOPened = True;
		GotoState( 'openmesh' ); //Needs to tell decoration to rise up to its variable set open height position
 
	}

	else if	(	bOPened
		||	( PlayerPawn(Other) != None)
		)
	{
		bOPened = False;
		GotoState( 'Closemesh' ); //Needs to tell decoration to lower back to its default start position. 
	}
}
 

ant75

aaaaaaaaaaaaaaaaa
Jan 11, 2001
1,050
0
36
Paris
I beg anyone not to answer your question until you start mapping for Inf again.



(no, seriously, is it for a new map ? :))
 

Silver_Ibex

Member
Feb 27, 2001
654
0
16
more like a reload for an old map :D see attached pic.

I have run into a weird bug when running the code under Inf :(

Take a look at the attached demo map, it contains example breakable window meshes and some standard UT pots.
Rename it from “.txt” to “.unr”, I had to call it a txt to allow attaching the file.

When played with UT, the windows brake in a shower of glass, and so do the pots.

When played with Inf, the windows glass shards remain in a tight ball as if glued together (they are not getting any dispersion force), and the “bMeshEnviroMap” (to make the glass shards shiny) is no longer on.

However the pots still appear to work, shattering as they did in UT???
 

Attachments

  • DM-INF-WindowCode.txt
    12.2 KB · Views: 15
  • WindowWork.jpg
    WindowWork.jpg
    31.1 KB · Views: 49
Last edited:

Freon

Braaaaiinss...
Jan 27, 2002
4,546
0
0
43
France
www.3dfrags.com
(bear in mind that I'm not a UScript expect :p)

There are 2 ways to do it:
- using an animated mesh, with an animation for the going up part, one for going down and 2 still anim for up position and down position. The script will togglebetween these (LoopAnim or PlayAnim).
Have a look at FreonDecos4.u, it contains a few dynamic decorations (a door, a frigde and so on). The only difference is that they are activated by a regular trigger.

- you need more states:
-up
-goingup
-down
-goingdown

In the tick function of the goinup and goindown states, you only have to move the deco up and down and adjust a counter or something. When the the right position is reached go to the 'up' or 'down' state and the deco will stop moving.
You can define a rate or a distance with var() int something; declarations.
 

Silver_Ibex

Member
Feb 27, 2001
654
0
16
I could not locate FreonDecos4.u in either the UT or INF system folder, so where do I get it?

Moving an unanimated mesh would be the best, since I want to be able to quickly create new windows with Mesh Maker.

The four states sounds like the way to go, just how do you determine the height of the mesh and know where it started?

Right now I am trying to locate an existing class that does something similar to the desired location change/flip flop.
 
Last edited:

Silver_Ibex

Member
Feb 27, 2001
654
0
16
Update
I have the movement code and TakeDamage working nicely :)

However the detect “Grab” code does not do anything, I cannot get it to run and triger the movment code, if I put the GotoState code in the TakeDamage function, the window opens/closes when shot. :(

if someone could explain how the Inf weapons and turrets detect Grab code works I could finish this.

Code:
auto state active
{

	function Grab( actor Other )
	{

	if (Pawn(Other) != None)
		{
			if	( !bOPened )
			{
				bOPened = True;
				PlaySound(MovmentSound, SLOT_Misc,1.0);
				GotoState( 'openmesh' ); 
			}
	
			else if	( bOPened )
			{
				bOPened = False;
				PlaySound(MovmentSound, SLOT_Misc,1.0);
				GotoState( 'closemesh' ); 
			}
		}
	}		


	function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, 
						Vector momentum, name damageType)
	{
		PlaySound(PushSound, SLOT_Misc,1.0);
		skinnedFrag(class'IbexGlassShard',texture'Detail.dirty2', Momentum,0.4,7);
		Instigator = InstigatedBy;
		if ( Instigator != None )
			MakeNoise(1.0);

			Disable( 'Tick' );
			tTime = 0.0;

			if ( bRespawning )
			GotoState ( 'WaitForRespawn', 'Begin' );

			else
			{
				Destroy();
			}	



Begin:
}
 
Last edited:

Beppo

Infiltration Lead-Programmer
Jul 29, 1999
2,290
5
38
52
Aachen, Germany
infiltration.sentrystudios.net
Hi, the grab stuff is using the following codes... so it can only grab specific classes and its subclasses:
Code:
from INFc_sMaleBase.uc

function GrabDecoration()
{
...
	if ( Mover(HitActor) != None )
	{
		if ( Mover(HitActor).bUseTriggered )
			HitActor.Trigger( self, self );
	}
	else if ( INFUT_ADD_Decoration(HitActor) != None )  // 2.86
	{
		if ( !INFUT_ADD_Decoration(HitActor).bActive )
			INFUT_ADD_Decoration(HitActor).Grab( self, self );
		else if ( INFUT_ADD_Decoration(HitActor).bActive )
			INFUT_ADD_Decoration(HitActor).UnGrab( self, self );
	}
	else if ( INFm_ActivateInfo(HitActor) != None )
	{
		INFm_ActivateInfo(HitActor).GrabMe(self);
	}
	else if ( INFm_GrabTrigger(HitActor) != None )
	{
		INFm_GrabTrigger(HitActor).GrabMe(self);
	}
	else if ( INFd_Ladder(HitActor) != None )
	{
		MyLadder = HitActor;
		GotoState('OnLadder');
	}
	else if ( (Decoration(HitActor) != None)  && ((weapon == None) || (weapon.Mass < 20)) )
	{
		CarriedDecoration = Decoration(HitActor);
		if ( !CarriedDecoration.bPushable || (CarriedDecoration.Mass > 40)
			|| (CarriedDecoration.StandingCount > 0) )
		{
			CarriedDecoration = None;
			return;
		}
		lookDir.Z = 0;
		if ( CarriedDecoration.SetLocation(Location + (0.5 * CollisionRadius + CarriedDecoration.CollisionRadius) * lookDir) )
		{
			CarriedDecoration.SetPhysics(PHYS_None);
			CarriedDecoration.SetBase(self);
		}
		else
			CarriedDecoration = None;
	}
	else if ( INFc_Weapon(HitActor) != None )
	{
		INFc_Weapon(HitActor).Grab(self);
	}
	else if ( INFc_Ammo(HitActor) != None )
	{
		INFc_Ammo(HitActor).Grab(self);
	}
...
So the classes that get a trigger or grab call are:
Mover - Trigger
INFUT_ADD_Decoration - Grab/UnGrab
INFc_Weapon - Grab
INFc_Ammo - Grab
INFm_ActivateInfo - GrabMe
INFm_GrabTrigger - GrabMe
INFd_Ladder - GotoState('OnLadder');
Decoration - if pushable then SetBase.... means you carry it in front of you
 

Beppo

Infiltration Lead-Programmer
Jul 29, 1999
2,290
5
38
52
Aachen, Germany
infiltration.sentrystudios.net
But you can also check for players hitting the grab key from the class you are using... that's how the Claymores and stuff alike do it.

ie:
Code:
class INFe_Claymore... slightly modified for your needs... 
this is more complicated looking than it really is... 
it uses a timer countdown in addition to the check and 
only grabs the stuff if you face the object and hold the 
grab key for TimeToActivate seconds. It lowers your weapon
 while holding down the grab key, puts it back up once you 
release the grab key and stuff like this. So this stuff forces 
you to look, grab and hold to actually do something with the object.

function bool CheckGrab(pawn Other)
{
    if	(	Other != None
	&&	Other.Health > 0
	&& !Other.IsInState('PlayerSpectating')
	&& !Other.IsInState('Dying')
	&& !Other.PlayerReplicationInfo.bIsSpectator
	&& !Other.PlayerReplicationInfo.bWaitingPlayer
	)
    {
	if (VSize(Location - Other.Location) > 75)
		return false;

	if (INFc_SMaleBase(Other) != None)
	{
		if (FacingDeco(Other))
			return INFc_SMaleBase(Other).bGrabbing;
	}
	else if (Bot(Other) != None)
	{
		INFc_SMale1Bot(Other).bStayDuck = true;
		if ( TimeLeft > 0 )
			Bot(Other).MoveTimer = TimeLeft + 1;
		else
			Bot(Other).MoveTimer = 6;
		return True;
	}
    }
    return False;
}

function Tick(float DeltaTime)
{
	local pawn Other;
	local bool obGrabbing;

	obGrabbing = bGrabbing;
	// check if "grabber" is still grabbing...
	if ( Grabbing != None )
		bGrabbing = CheckGrab(Grabbing);
	// check if someone is around and grabbing...
	if ( Grabbing == None )
	{
		foreach RadiusActors(class'Pawn', Other, 75, Location)
		{
			if ( CheckGrab(Other) )
			{
				Grabbing = Other;
				bGrabbing = True;
				break;
			}
		}
	}

	// if the grabbing just started
	if ( !obGrabbing && bGrabbing )
	{
                          ...
		TimeLeft = TimeToActivate;
                          ...
		if(Grabbing != None && Grabbing.Weapon != None && INFc_Weapon(Grabbing.Weapon) != None)
			INFc_Weapon(Grabbing.Weapon).WeaponStayDown();
	}
	// if grabbing just stopped
	else if ( obGrabbing && !bGrabbing )
	{
                         ...
		if( !bArmed && TimeLeft > (TimeToActivate-0.5) )	// can Grab if not activated
			if ( Grabbing != None && INFc_SMaleBase(Grabbing) != None && !INFc_SMaleBase(Grabbing).bGrabbing )
				Grab(Grabbing);

		TimeLeft = 0;

		if(Grabbing != None && Grabbing.Weapon != None && INFc_Weapon(Grabbing.Weapon) != None)
			INFc_Weapon(Grabbing.Weapon).WeaponBringUp();
	}
	// if still is grabbing
	else if ( obGrabbing && bGrabbing )
	{
		TimeLeft -= DeltaTime;
                          ...

		if (TimeLeft <= 0)
		{
			if	(   Grabbing.Health > 0
				&& !Grabbing.IsInState('PlayerSpectating')
				&& !Grabbing.IsInState('Dying')
				&& !Grabbing.PlayerReplicationInfo.bIsSpectator
				&& !Grabbing.PlayerReplicationInfo.bWaitingPlayer
				)
			{
				if(Grabbing != None && Grabbing.Weapon != None && INFc_Weapon(Grabbing.Weapon) != None)
					INFc_Weapon(Grabbing.Weapon).WeaponBringUp();

				// Player grabs it then for example
					Grab(Grabbing);
					if (INFc_SMaleBase(Grabbing) != None){
						INFc_SMaleBase(Grabbing).bINFGrab = 0;
					}
					bGrabbing = False;
					Grabbing = None;
				}
			}

			if (INFc_SMale1Bot(Grabbing) != None)
				INFc_SMale1Bot(Grabbing).bStayDuck = false;

			bGrabbing = False;
		}
	}

	// no one is grabbing so ...
	if (!bGrabbing ) {
		Grabbing = None;
	}
}

function bool FacingDeco(Pawn P)
{
	local float theta;
	local vector OTrace;
	local vector HitLocation, HitNormal;

	if (VSize(Location - P.Location) > 75)
		return false;

	// a) the angle between a direct trace between the two object locations
	// and the viewrotation of the player
	// means ... the player has to face the claymore
	OTrace = Location - P.Location;		// vector pointing towards claymore
	theta = Normal(vector(P.ViewRotation)) Dot Normal(OTrace);
	if (theta > cos((P.FOVAngle * 0.15 * 3.141) / 180 ))
		return true;
	return false;
}
 
Last edited:

zeep

:(
Feb 16, 2001
1,741
1
36
Visit site
And since in your map there are a lot of places where there is hay, grass and leaves etc perhaps you want to add Freon's random deco generator in some locations. It makes the map come alive even more!
Freon said:
..It adds little flying decos around the player a bit like in GTA. It's flexible enough to make it use anything though. Like grass, clouds and so on.
 

Freon

Braaaaiinss...
Jan 27, 2002
4,546
0
0
43
France
www.3dfrags.com
If it's a big map where FPS is crucial I'd recommend against it. I had to remove it from Dullrocks2 because it was 5 FPS slower. Of course it was 15 to 10. So if your map runs at 30 FPS it won't be a problem :p
 

Silver_Ibex

Member
Feb 27, 2001
654
0
16
Here is the code I have hacked together so far, it appears to get the job done, but I have not tested it in multiplayer. And would appreciate feedback, especially from experienced coders.

The attached map is an example house with the windows installed like they would be in a full map.

The windows can be variably opened depending on how long you hold the key.
Their Moment speed is mapper adjustable.
The windows time till respawn can be set for purposes of testing, or turned off.
When the window is open all the way the block player is turned off so you can climb through.
There is a lock variable for if the mapper does not want the window to open/move (all the top glass is set to lock in the attached map).
 

Attachments

  • DM-INF-WindowCode.zip
    145 KB · Views: 14