Author Topic: Making a player spawn at a specific spawn point.  (Read 3962 times)

I want to make players spawn at a certain point based on a variable.

And looking through addons has not been that much help.

so could someone explain to me how to do this?

package the spawnplayer function and set their location to where you want.  I recommend terminal velocity falling height.

look at my unlimited mining mod -- it does exactly that.  spawn player at a certian spawnpoint based on a variable.

GameMode_ZAPT/scripts/package.cs
Overriding the default spawning mechanism.
(Must go in a package.)
Code: [Select]
function MinigameSO::pickSpawnPoint(%so, %client)
{
// Are we spawning as the tank?
if(%client.spawningAsTank)
{
// Get a tank spawn point.
%point = ZombieDirector.pickSpawnPointTank(%client);
}

// If we aren't, or there is no tank spawn point...
if(%point $= "")
{
// Are we spawning as a zombie?
if(%client.isZombie)
{
// Get a zombie spawn point.
%point = ZombieDirector.pickSpawnPoint(%so, %client);
}

// If we aren't, or there is no zombie spawn point...
if(%point $= "")
{
// Get a default spawn location.
%point = parent::pickSpawnPoint(%so, client);
}
}

// Return our spawn spot.
return %point;
}

GameMode_ZAPT/scripts/scriptobjects.cs
Scanning through a group of spawns to find the one we want.
This is a bit clumsy and hard to read, so just keep in mind all we're doing here is going through a simgroup and applying logic to it to determine which ones are valid.
Code: [Select]
function ZombieDirector::pickSpawnPoint(%so, %mini, %client, %ignorePref)
{
if(zombieGameSetUpRight(%mini))
{
%ss = %so.zombieKeeper;

if(isObject(%ss))
{
%spawns = 0;
%spawnList = "";

for(%a = 0; %a < %ss.getCount(); %a++)
{
%spawn = %ss.getObject(%a);
%spawnMini = getMiniGameFromObject(%spawn);

if(zombieSameGame(%client, %spawn) && miniGameCstar fishe(%spawnMini.owner, %spawn))
{
%db = %spawn.vehicleDatablock;
%spawnPos = %spawn.zombieSpawnPoint();

if(isObject(%db) && %db.isZombieArmor && !%db.zombieAIOnly && (!%db.zombieAdminOnly || %client.isAdmin))
{
if(%so.isPosNearPlayer(%mini, %spawnPos, %ignorePref != 2 ? $ZAPT::MaxDist : -1,  8))
{
if(%ignorePref || %db.getID() != %client.zombieDidNotWant)
{
if(!%spawns)
{
%spawnList = %spawn.getID();
}
else
{
%spawnList = %spawnList TAB %spawn.getID();
}

%spawns++;
}
}
}
}
}

if(%spawns)
{
%spawnBrick = getField(%spawnList, getRandom(0, %spawns - 1));
%spawnPoint = %spawnBrick.zombieSpawnPoint();

%client.zombieSpawnBrick = %spawnBrick;

return %spawnPoint;
}
// Rerun the test, this time ignoring any preferences.
else if(%ignorePref < 2)
{
return %so.pickSpawnPoint(%mini, %client, %ignorePref++);
}
}
else
{
error("CRITICAL ERROR: ZombieDirector.zombieKeeper not found!");
}
}

return "";
}

GameMode_ZAPT/scripts/functions.cs
Getting a proper 7-point float from a brick to give to the spawn system.
This function is a convenience thing. I advise that you just apply this code to the brick instead of making a function to do it for you.
Code: [Select]
function fxDTSBrick::zombieSpawnPoint(%this)
{
%box = %this.getWorldBox();
%point = vectorAdd(getWords(%box, 0, 1) SPC 0, getWords(%box, 3, 4) SPC 0);
%point = getWords(vectorScale(%point, 0.5), 0, 1) SPC getWord(%box, 5);
%trans = %point SPC getWords(%this.getTransform(), 3, 6);

return %trans;
}



package the spawnplayer function and set their location to where you want.  I recommend terminal velocity falling height.
Terminal velocity is not the velocity at which a person dies or will collide with the ground so hard they die.
Terminal velocity refers to the speed at which an object can not be accelerated further by gravity (or something like that).
« Last Edit: February 26, 2011, 12:54:06 PM by Iban »

Thanks for the help. C:

-helpsnip-

Oh my god. That was the first thing I ever understood in scripting, thanks!