Page 1 of 1

Can someone explain this routine?

Posted: Tue Mar 15, 2005 9:49 am
by Grassy
This routine was pinched from a BreakThrough MP obj map that I modded some time ago, the routine was an existing one in the existing scr. I have looked over it countless times and it still dosn't make sense to me.
Could some script guru's have a look and explain in simplistic step by step terms how it is supposed to switch spawns over?

Code: Select all

reverseSpawnPoints:

	if(!($axisspawn) || !($alliedspawn))
		End
	local.axis = $axisspawn.size
	local.allies = $alliedspawn.size
  
	if(local.axis > local.allies)
		{
			for(local.a = 1; local.a <= local.allies; local.a++)
			{
				local.temporigin = $axisspawn[local.a].origin
				local.tempangles = $axisspawn[local.a].angles
				$axisspawn[local.a].origin = $alliedspawn[local.a].origin
				$axisspawn[local.a].angles = $alliedspawn[local.a].angles

				$alliedspawn[local.a].origin = local.temporigin
				$alliedspawn[local.a].angles = local.tempangles
			}
			for(local.b = local.allies + 1; local.b <= local.axis; local.b++)
				$axisspawn[local.a] disablespawn
		}
	else
		{
			for(local.a = 1; local.a <= local.axis; local.a++)
			{
				local.temporigin = $axisspawn[local.a].origin
				local.tempangles = $axisspawn[local.a].angles
				$axisspawn[local.a].origin = $alliedspawn[local.a].origin
				$axisspawn[local.a].angles = $alliedspawn[local.a].angles

				$alliedspawn[local.a].origin = local.temporigin
				$alliedspawn[local.a].angles = local.tempangles
			}
			for(local.b = local.axis + 1; local.b <= local.allies; local.b++)
				$alliedspawn[local.a] disablespawn
		}	
	
End
Thanks Grassy

Posted: Tue Mar 15, 2005 11:21 am
by bdbodger
reverseSpawnPoints:

Check to see if you have enities with the targetname axisspawn or alliesspawn if not end

if(!($axisspawn) || !($alliedspawn))
End

// local.axis is the number of entities with the targetname axisspawn
local.axis = $axisspawn.size
//local.allies is the number of entities with the targetname alliedspawn
local.allies = $alliedspawn.size
if there are more $axisspawn then $alliedspawn do this
if(local.axis > local.allies)
{
// do a for loop from 1 to then number of $alliedspawn
for(local.a = 1; local.a <= local.allies; local.a++)
{
// save the origin of the $axisspawn number local.a
local.temporigin = $axisspawn[local.a].origin
// save the angles of the $axisspawn number local.a
local.tempangles = $axisspawn[local.a].angles
// move the origin of $axisspawn[local.a] to the origin of $alliedspawn[local.a]
$axisspawn[local.a].origin = $alliedspawn[local.a].origin
// give the angles of $axisspawn[local.a] the angles of $alliedspawn[local.a]
$axisspawn[local.a].angles = $alliedspawn[local.a].angles

// move the $alliedspawn[local.a] to the coords of $axisspawn[local.a] that where saved at the start of the loop befor $axisspawn[local.a] was moved
$alliedspawn[local.a].origin = local.temporigin
// give the $alliedspawn[local.a] the angles of $axisspawn[local.a] that where saved at the start of the loop
$alliedspawn[local.a].angles = local.tempangles
}
// these two lines disable the extra $axisspawn spawnpoints if there are more of them than $alliedspawn spawnpoints
for(local.b = local.allies + 1; local.b <= local.axis; local.b++)
$axisspawn[local.a] disablespawn
}
This next part is the same only the other way around
else
{
for(local.a = 1; local.a <= local.axis; local.a++)
{
local.temporigin = $axisspawn[local.a].origin
local.tempangles = $axisspawn[local.a].angles
$axisspawn[local.a].origin = $alliedspawn[local.a].origin
$axisspawn[local.a].angles = $alliedspawn[local.a].angles

$alliedspawn[local.a].origin = local.temporigin
$alliedspawn[local.a].angles = local.tempangles
}
for(local.b = local.axis + 1; local.b <= local.allies; local.b++)
$alliedspawn[local.a] disablespawn
}

End

Posted: Tue Mar 15, 2005 1:42 pm
by Rookie One.pl
It just reverses spawnpoints and makes sure the numbers are even.

Posted: Wed Mar 16, 2005 7:09 am
by Grassy
Wow :shock: thanks BD, that's exactly the type of response I was after! The disableling of spawns was one thing that had me stumped, also let me get this right.....
// local.axis is the number of entities with the targetname axisspawn
local.axis = $axisspawn.size
Is this looking at the actual info_player spawn object or is it looking for an actual player spawning in it? This is my other problem.. to me it is only looking at the actual info_player spawn entities, not the players themselves. ? is that correct? If so then this routine will never work if both sides have the same number of spawn locations.. ?? :?
Grassy

Posted: Wed Mar 16, 2005 10:17 am
by bdbodger
$axisspawn is the targetname of the axis spawnpoints info_player_axis and yes it will run because if the first thing is not true

if(local.axis > local.allies)
....
else
....

then the second part after the else will run the only thing that will make it end is

if(!($axisspawn) || !($alliedspawn))

if(not($axisspawn) or not($alliedspawn))

if one of those is true in other words if there are no axis spawnpoints with the targetname $axisspawn or no allied spawn points with the targetname $alliedspawn then the script just ends to avoid errors , just make sure to use those targetnames for the spawnpoints .