Release [CODE] Custom spawns
#1
Brick 
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
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
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click

#2
There is meteorite in Chelyabinsk. I'm so scary about it.

#3
(02-15-2013, 16:32)SMIRNOFF2096 Wrote: There is meteorite in Chelyabinsk. I'm so scary about it.

Yeah, and Russia kills meteorite
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click

#4
(02-15-2013, 18:16)SailorMoon Wrote:
(02-15-2013, 16:32)SMIRNOFF2096 Wrote: There is meteorite in Chelyabinsk. I'm so scary about it.

Yeah, and Russia kills meteorite

I'm from this fucking country D:

#5
Awesome, but how do I get the numbers?

#6
(03-05-2013, 05:29)napok Wrote: Awesome, but how do I get the numbers?

Use the event onsay like down here:
If you say !pos the "numbers" (coordinates) get printed in the console, and also toldto you.
Code:
public override ChatType OnSay(String Message, ServerClient Client, bool Teamchat) { if (Message == "!pos") { TellClient(Client.ClientNum, "You are on the position X: " + Client.OriginX + " Y: " + Client.OriginY + " Z: " + Client.OriginZ, true); ServerPrint(Client.Name + Client.OriginX + "f, " + Client.OriginY + "f, " + Client.OriginZ + "f"); } }
[Image: b_560_95_1.png]
[Image: hax0r3ez.gif]

#7
So where can we download the plugin?

#8
It's just a code ..


You can download my c# code lightweight compiler and compile it. Nyan Cat
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click

#9
Hey, you might think im a noob, i am, in programming, I tried using your compiler, but errors show up.

#10
Which errors?
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Custom mod Karesz12345678 0 3,308 11-27-2018, 21:26
Last Post: Karesz12345678
  [Release] Custom Shop SgtLegend 1 5,010 06-16-2016, 18:57
Last Post: abidullah
Brick [Release] Custom MysterBox V1.0 Ich1994 13 14,351 04-14-2013, 08:47
Last Post: hillbilly
Rainbow [Release] [Code] Akimbo weapon fix (new) Nekochan 11 11,845 02-27-2013, 23:49
Last Post: Krusty123
  [Release] [CODE][TUT]Boxes 99IRock 40 31,545 01-14-2013, 20:18
Last Post: EnVi Sweden Rocks
Thumbs Up [Release] XP Manager V1.75 Fixed & Source Code kokole 17 15,318 03-09-2012, 21:36
Last Post: stillframe
Rainbow [Release] MW3 Custom RCON Server + Client ALPHA JariZ 25 28,669 01-06-2012, 13:36
Last Post: JariZ
  [Release] Custom Camo maker photoshop plug-in iPaddie 3 9,923 02-16-2011, 02:58
Last Post: Cgallagher

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.