Jump to content
Racey66

init.c coder required

Recommended Posts

Is there anyone who knows how to add a code to our init.c file so that we can enter a steam i.d. and that player will spawn in a specific location? There would be about 20 or so Steam id,s so hopefully if it can be done their numbers could be added to a string of some kind. $$ Donation available to anyone who can help

Share this post


Link to post
Share on other sites

You can make a list of strings and check if the each connected player is in the list then spawn them at a desired location

Here's an example code:

const int MaxSpecialPlayers=10; //number of players 

std::string SpecialPlayers[MaxSpecialPlayers]={ steam ids here seperated by comas };

for(unsigned char i=0;i<MaxSpecialPlayers;i++)

{

  if(connected player==SpecialPlayers)

         {

                 vector pos=coordinates of the place you want the player to spawn;

                Entity playerEnt = GetGame().CreatePlayer(identity, characterName, pos, 0, "NONE");

        }

}

Share this post


Link to post
Share on other sites

This code works for me:

 

class CustomMission: MissionServer
{





	// Default code for this class goes here. Put the code below at the bottom of this class.





	// Teleport player to a specified coordinate on connect depending on the SteamID - Code start
	override void InvokeOnConnect(PlayerBase player, PlayerIdentity identity)
	{
		super.InvokeOnConnect(player, identity);

		// Define the X and Z coordinates below where the player(s) will spawn when they connect.
		float xCoordinate = 4661;
		float zCoordinate = 10330;
		
		// Enter the SteamID or the BI-UID for the player(s) you want to spawn at the above coordinates.
		// Separate with a comma if you have more than one player.
		ref TStringArray spawnPlayers = {"76561198000000001", "76561198000000002", "76561198000000003"};

		// Check if the current player is on the above list. If so, make him/her spawn at the specified coordinates.
		for (int i = 0; i < spawnPlayers.Count(); ++i ) 
		{
			if(player.GetIdentity().GetId() == spawnPlayers[i] || player.GetIdentity().GetPlainId() == spawnPlayers[i])
			{
				float yCoordinate = GetGame().SurfaceY(xCoordinate, zCoordinate);
				vector spawnCoordinates = Vector(xCoordinate, yCoordinate, zCoordinate);
				player.SetPosition(spawnCoordinates);
				
				break;
			}
		}
	}
	// Teleport player to a specified coordinate on connect depending on the SteamID - Code end
};

 

This will apply to respawns as well. If a player with a matching SteamID dies he/she will respawn at the given coordinates.

I haven't tried the code with multiple Steam ID's, but it should work.

Edited by NoBeansForMe

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×