Hey,
I just made small plugin for 30 minutes, it sets custom spawn points, made by request. You can modify code or make it better.
How to use it?
You need to create /maps folder inside plugins folder and make files, for map data. File name should be 'mapname.dat'. Ie mp_dome.dat
Example of mp_Dome.dat
Comma at end of all lines is required.
In next version i'll add spawn protection.
Code:
Math_.cs ( by @Ich1994 )
You can modify code as you want.
Credits:
@Sailormoon - creator
@aka46 - testing
Download for lazy people:
http://www.itsmods.com/forum/Thread-Rele...5#pid98565
I just made small plugin for 30 minutes, it sets custom spawn points, made by request. You can modify code or make it better.
How to use it?
You need to create /maps folder inside plugins folder and make files, for map data. File name should be 'mapname.dat'. Ie mp_dome.dat
Example of mp_Dome.dat
Code:
maxpos,1000, // Maximal position of enemy detecting
0,12312;12312;123423, // Custom spawn points, separates by semicolon;
1,12124;1212312;123121,
2,21312343; 423424;234234,
Comma at end of all lines is required.
In next version i'll add spawn protection.
Code:
Code:
using System;
using System.Collections.Generic;
using System.IO;
using Addon;
// compile in net3.0 mode
namespace newspawns
{
public class main : CPlugin
{
private Dictionary<string, string> spawn = new Dictionary<string, string>();
public int maxpos = 100; // default
private void CL_LoadSpawnData(string map)
{
string spawns = string.Empty;
string file = string.Format("maps\\{0}.dat", map);
string[] parsedData;
if(!File.Exists(string.Format("{0}\\plugins\\{1}", Directory.GetCurrentDirectory(), file)))
{
ServerPrint("cSpawns: Couldn't find " + file + " map file.");
return;
}
spawns = File.ReadAllText(string.Format("{0}\\plugins\\{1}", Directory.GetCurrentDirectory(), file)); // getting text data
parsedData = spawns.Split('\n'); // new line
spawn.Clear();
foreach (string dataline in parsedData)
{
// split'd by commas
string[] linedata = dataline.Split(','); // line
// num, pos,
if (linedata[0] == null)
{
ServerPrint("cSpawns: Corrupted data");
return;
}
if (linedata[1] == null)
{
ServerPrint("cSpawns: Corrupted data");
return;
}
if (linedata[0] == "maxpos")
{
maxpos = Convert.ToInt32(linedata[1]);
}
else
{
string num = linedata[0];
string pos = linedata[1];
spawn.Add(num, pos);
}
}
foreach(KeyValuePair<string, string> s in spawn)
{
ServerPrint(s.Key + " " + s.Value);
}
}
private void CL_SetOrigin(ServerClient c, Vector pos)
{
c.OriginX = pos.X;
c.OriginY = pos.Y;
c.OriginZ = pos.Z;
}
private Boolean isCloseToPlayer(Vector pos)//(ServerClient iam)
{
List<ServerClient> clients;
clients = GetClients();
if (clients != null)
{
if (clients.Count > 0)
{
foreach (ServerClient client in GetClients())
{
if (client.Other.isAlive == true &&
client.ConnectionState != ConnectionStates.MapLoading &&
client.ConnectionState != ConnectionStates.Connecting &&
client.ConnectionState != ConnectionStates.Zombie &&
client.Team != Teams.Spectator)
{
float Y3 = client.OriginY;
float X3 = client.OriginX;
float Z3 = client.OriginZ;
if ((Math_.Difference(pos.Y, Y3) <= maxpos) && (Math_.Difference(pos.X, X3) <= maxpos) && Math_.Difference(pos.Z, Z3) <= maxpos)
{
return true;
}
}
}
}
}
return false;
}
public override void OnFastRestart() { OnMapChange(); }
public override void OnMapChange()
{
CL_LoadSpawnData(GetDvar("mapname"));
base.OnMapChange();
}
public override void OnServerLoad()
{
try
{
ServerPrint("CustomSpawn: Loading.....");
//CL_LoadSpawnData("test");
ServerPrint(" > ---------------------------------------- < ");
ServerPrint("CustomSpawn plugin was successfuly loaded!");
ServerPrint("Created by SailorMoon (itsmods.com)");
ServerPrint(" > ---------------------------------------- < ");
}
catch(Exception z)
{
ServerPrint("CustomSpawn plugin: Failed to load\n\n " + z.Message);
}
}
private Vector ParseVector(string input)
{
string[] coords = input.Split(new Char[] { ';' });
int x = Int32.Parse(coords[0]);
int y = Int32.Parse(coords[1]);
int z = Int32.Parse(coords[2]);
return new Vector(x, y, z);
}
public void CL_FindSpawn(ServerClient c)
{
foreach (KeyValuePair<string, string> s in spawn)
{
// all spawns
// try to set origin
if (!isCloseToPlayer(ParseVector(s.Value)))
{
CL_SetOrigin(c, ParseVector(s.Value));
}
else
{
// do nothing, it'll use default spawn
//Random spawns = new Random();
//spawns.Next(Convert.ToInt32(s));
}
}
}
public override void OnPlayerSpawned(ServerClient Client)
{
CL_FindSpawn(Client);
}
}
}
Math_.cs ( by @Ich1994 )
Code:
using System;
using Addon;
namespace newspawns
{
public class Math_
{
public static Vector getOrigin(ServerClient c)
{
return new Vector(c.OriginX, c.OriginY, c.OriginZ);
}
public static Vector subtract(Vector v1, Vector v2)
{
return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
}
public static float length(Vector v)
{
return (float)Math.Sqrt(v.X * v.X + v.Y * v.Y + v.Z * v.Z);
}
public static Vector normalize(Vector v)
{
float l = length(v);
if (l == 0)
{
v = new Vector(0, 0, 1);
return v;
}
return div(v, l);
}
public static Vector mul(Vector v, float f)
{
return new Vector(v.X * f, v.Y * f, v.Z * f);
}
public static Vector div(Vector v, float f)
{
return new Vector(v.X / f, v.Y / f, v.Z / f);
}
public static float Difference(float loc, float loc2)
{
return Math.Abs(loc - loc2);
}
}
}
You can modify code as you want.
Credits:
@Sailormoon - creator
@aka46 - testing
Download for lazy people:
http://www.itsmods.com/forum/Thread-Rele...5#pid98565