Velocity Trigger

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Post Reply
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Velocity Trigger

Post by Cybernetic pig »

So I'm just experimenting with the simple idea of a velocity trigger, which is nice as it doesn't require messing around with zones and can be applied more liberally, for example now we can have more than one force per zone, however:

Code: Select all

//=============================================================================
// VelocityTrigger.   //CyberP: applies velocity to touching actors
//=============================================================================
class VelocityTrigger expands Trigger;

var() vector AppliedVelocity;
var Actor forced;
var () float accelerationRate;
var bool bIsOn;

function Timer()
{
	if (!bIsOn)
	{
		SetTimer(0.1, False);
		return;
	}

	if (forced != None)
	{
	    if (appliedVelocity.Z != 0)
	        forced.SetPhysics(PHYS_Falling);
	    forced.Velocity += appliedVelocity;
       }
}

function Touch(Actor Other)
{
	if (!bIsOn)
		return;

	// should we even pay attention to this actor?
	if (!IsRelevant(Other) && !Other.IsA('DeusExDecoration'))
		return;

	forced = Other;

//CyberP: need to figure out the best way to handle more than one //touching actor at a time.

    SetTimer(accelerationRate, True);

	Super.Touch(Other);
}

function UnTouch(Actor Other)
{
    SetTimer(0.1, false);

	if (!bIsOn)
		return;
}

// if we are triggered, turn us on
function Trigger(Actor Other, Pawn Instigator)
{
	if (!bIsOn)
		bIsOn = True;

	Super.Trigger(Other, Instigator);
}

// if we are untriggered, turn us off
function UnTrigger(Actor Other, Pawn Instigator)
{
	if (bIsOn)
		bIsOn = False;

	SetTimer(0.1, false);

	Super.UnTrigger(Other, Instigator);
}

defaultproperties
{
     bIsOn=True
     accelerationRate=0.100000
}
...I'm trying to think of the best way to handle more than one actor at a time, as the native Touch() only passes 1. Foreach Radius Actors would work, but isn't desirable, or just custom traces, but there is surely a better way?

Perhaps I should take a look at how Touch() itself works and then just create a Touch2(), Touch3() etc using the same methods, and only activate them when the first Touch() is being called, like a switch gate, yet I suspect Touch simply traces collision radius and collision height anyway.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Velocity Trigger

Post by Hanfling »

Well, basically you get a Touch() event for each Actor, and it's perfectly fine to just handle one Actor at a time there. Also there is this Touching[] array, though if two Actors starting to touch it the same frame, you probably won't have the second one in Touching[] when you get your first Touch() event. The real concern is that if too many Actors stick around at that spot, you fill up the Touching[] array and afaik won't get further Touch() events.

However saving just one Actor in the class itsself is kinda bad, as you run into conflicts, so you should consider just applying the velocity once (and you might need to use the singular keyword for the Touch() event to avoid reentry loops), walk every now and them through the Touching[] list, or if you want to do this timer passed per Actor, store an array of Actors in your class and use some your custom timer code, preferable the one epic used for their timers (can post this again if needed). Also you could add the code to your Pawn classes, so they handle getting pushed themself...

In any case, you might want to take a look at Nerf Arena Blast code, as it has some jumppads in.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: Velocity Trigger

Post by Cybernetic pig »

Ah, I didn't know there was a touching array. You did mention before that the engine only handles up to five touching actors, I should have figured from that.

Thanks for the advice, should be easy to handle.
Also you could add the code to your Pawn classes, so they handle getting pushed themself...
And decoration and such, it's cool throwing a box in the trigger and watching it fly around.
Yeah this would definitely be a very easy, risk-free method.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: Velocity Trigger

Post by Cybernetic pig »

Unrelated to the above, the following code puts select items in hand if we have them. If you drop the desired item (multitool or lockpick) and then pick it up again it no longer works anymore, any ideas why that may be? Must be something to do with the Inventory vars.

Code: Select all

local Inventory item, nextItem;

if (inHand == None && FrobTarget != None && FrobTarget.IsA('DeusExMover'))
    {
      if (DeusExMover(FrobTarget).bLocked)
      {
      for(item = Inventory; item != None; item = nextItem)
	  {
		nextItem = item.Inventory;
	    	if (nextItem.IsA('Lockpick'))
	    	{
	    	   if (DeusExMover(FrobTarget).bPickable==True)
	    	   {
	    	      PutInHand(nextItem);
	    	      break;
	    	   }
	    	}
	    	else if (nextItem.IsA('NanoKeyRing'))
	    	{
	    	   PutInHand(nextItem);
  	           break;
	    	}
      }
      }
    }
    else if (inHand == None && FrobTarget != None && FrobTarget.IsA('HackableDevices'))
    {
       for(item = Inventory; item != None; item = nextItem)
	   {
		nextItem = item.Inventory;
	    	if (nextItem.IsA('Multitool') || nextItem.IsA('NanoKeyRing'))
	    	{
	    	   if (nextItem.IsA('Multitool'))
	    	      PutInHand(nextItem);
	    	   else
                {
                }
    	       break;
	    	}
       }
    }
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: Velocity Trigger

Post by Hanfling »

Code: Select all

for(item = Inventory; item != None; item = nextItem)
{
  nextItem = item.Inventory;
  if (nextItem.IsA('Lockpick'))
  { /*...*/ }
  else if (nextItem.IsA('NanoKeyRing'))
  { /*...*/ }
}
You start with Actor.Inventory.Inventory and not with Actor.Inventory, and the most recent (new) inventory item you picked up gets added in front of the inventory chain, e.g. will become Actor.Inventory, and hence if you start with Actor.Inventory.Inventory you skip it.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: Velocity Trigger

Post by Cybernetic pig »

I don't entirely understand. I see now that picking up the multitool/lockpick is adding it to the end of the inventory list, and thus is listed after the nanokeyring, but I don't get what the inventory of an actor's inventory even is (actor.inventory.inventory).
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: Velocity Trigger

Post by Cybernetic pig »

Ah, I see, the conditions disregard the first item in the list, only the nextItem is checked. OK.

Solution:

Code: Select all

if (inHand == None && FrobTarget != None && FrobTarget.IsA('DeusExMover'))
    {
      if (DeusExMover(FrobTarget).bLocked)
      {
      for(item = Inventory; item != None; item = nextItem)
	  {
		nextItem = item.Inventory;
		    if (item.IsA('Lockpick'))
		    {
		       if (DeusExMover(FrobTarget).bPickable==True)
	    	   {
	    	      PutInHand(item);
	    	      break;
	    	   }
		    }
	    	else if (nextItem.IsA('Lockpick'))
	    	{
	    	   if (DeusExMover(FrobTarget).bPickable==True)
	    	   {
	    	      PutInHand(nextItem);
	    	      break;
	    	   }
	    	}
	    	else if (nextItem.IsA('NanoKeyRing'))
	    	{
	    	   PutInHand(nextItem);
  	           break;
	    	}
      }
      }
    }
    else if (inHand == None && FrobTarget != None && FrobTarget.IsA('HackableDevices'))
    {
       for(item = Inventory; item != None; item = nextItem)
	   {
		nextItem = item.Inventory;
		    if (item.IsA('Multitool'))
		    {
		        PutInHand(item);
		        break;
		    }
	    	else if (nextItem.IsA('Multitool') || nextItem.IsA('NanoKeyRing'))
	    	{
	    	   if (nextItem.IsA('Multitool'))
	    	      PutInHand(nextItem);
	    	   else
               {
               }
   	        break;
	    	}
       }
    }
Post Reply