Can someone explain this routine?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Can someone explain this routine?

Post 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
An ambiguous question will get a similar answer...
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

It just reverses spawnpoints and makes sure the numbers are even.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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
An ambiguous question will get a similar answer...
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 .
Image
Post Reply