[Script] Underground

Post Reply
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

[Script] Underground

Post by perrinoia »

This is a server side script which converts the rotation of each terrain into a perpendicular vector... For instance, if the terrain's rotation is "0 0 0" the vector will be "0 0 10000", and if the rotation is "0 3.14159 0", the vector will be "0 0 -10000". Then, it looks in those directions from a given position, for the terrain's object ID associated with each vector. If the terrain ID matches the LOS::Object (Line of Sight), the given position is underground, and the function returns true, otherwise, it returns false.

Code: Select all

function SimTerrain::underground(%this)
{
	if(getObjectType(%this) == SimTerrain)
	{
		$SimTerrain::ground[($SimTerrains++)] = %this;
		$SimTerrain::vector[($SimTerrains)] = Vector::getFromRot(Vector::add("1.570796 0 0", GameBase::getRotation(%this)), 10000, 0);
	}
}

function underground(%pos)
{
	deleteVariables("SimTerrain*");
	Group::iterateRecursive(MissionGroup, "SimTerrain::underground");
	while(%i++ <= $SimTerrains)
	{
		echo($SimTerrain::vector[%i]);
		deleteVariables("LOS::*");
		if(getLOSInfo(%pos, Vector::add($SimTerrain::vector[%i], %pos), 1))
		{
			if($SimTerrain::ground[%i] == $LOS::Object)
				return true;
		}
	}
	return false;
}
I intend to add this script to my mission BottomsUp, and crush those sneaky snakes who slither where they don't belong.

But first, I'm posting it here, so anyone else can use it as they see fit.
Image
AnniDv6
Posts: 1031
Joined: Mon Dec 12, 2011 3:25 pm

Re: [Script] Underground

Post by AnniDv6 »

Thanks. I can think of a few cave ctf maps this will work for.
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: [Script] Underground

Post by perrinoia »

Yes, it is compatible with multiple terrains. Even IV, which has a valley made from 2 terrains, should behave well.

It's important to note, however, that this code only looks in one direction for each terrain, so it's entirely conceivable that a skilled douche will easily thwart it.

Also, it will not give false positives when you are inside the belly of a bunker, or something like that, but it will give positive results for players who go beneath the terrain on maps that allow it, such as Roach Motel... So what is done with this information should be mission specific, even if the ability to retrieve this information is available during any mission.

This is what I plan to do with it, in BottomsUp.

Code: Select all

function Player::Whack_A_Mole(%this)
{
	%pos = getBoxCenter(%this);
	if(underGround(%pos))
		GameBase::applyDamage(%this, $CrushDamageType, 0.01, %pos, "0 0 0", "0 0 0", %this);
}

function Whack_A_Mole(%this)
{
	Group::iterateRecursive(MissionCleanup, GameBase::virtual, "Whack_A_Mole");
	schedule(sprintf("if($MissionName == \"%1\") Whack_A_Mole(\"%1\");", $MissionName), 1/3);
}

Whack_A_Mole($MissionName);
This script can be executed by any mission file, and will damage players 3 times a second while they remain underground, until the mission changes.

It's important to note that if the mission repeats, the script will run twice as often, sneaky players will die faster, and it may cause lag if the same mission repeats several times in a row... I could probably figure out a way to prevent that if it becomes a problem.
Image
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: [Script] Underground

Post by perrinoia »

Unfortunately, if I look in any direction other than completely perpendicular to the terrain rotation, I'll get false positives from players in valleys, so unless I retrieve the actual terrain heightmap, and do some calculus to figure out which side of the terrain your on, this is the best I can do.
Image
Post Reply