Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
Reply

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

#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
Reply

#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:
Reply

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

#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]
Reply

#7
So where can we download the plugin?
Reply

#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
Reply

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

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



Possibly Related Threads…
Thread Author Replies Views Last Post
  Black Ops 2 Custom background? jotape99 10 12,456 10-29-2013, 07:22
Last Post: xInfinity.
  Help Code color crosshairs koren30 3 4,016 10-02-2013, 19:26
Last Post: koren30
  Help need help?how to make plugins code hXnarutoXone 12 8,551 09-01-2013, 18:30
Last Post: Bandarigoda123
  Custom xanims DidUknowiPwn 8 7,076 08-28-2013, 08:17
Last Post: RaZ
  Help Need Help with C# code tubwux 2 3,314 08-27-2013, 18:18
Last Post: tubwux
  [Request] Compile this code please dozsa0 4 4,134 08-10-2013, 21:02
Last Post: Nukem
  Compile this code please First_Semyon 12 9,686 08-08-2013, 14:53
Last Post: Bandarigoda123
  Compile please this code First_Semyon 8 5,639 07-28-2013, 01:52
Last Post: First_Semyon
  Help Make ac130 shoot custom bullets Ra3shed 0 2,730 07-23-2013, 13:02
Last Post: Ra3shed
  [Tutorial] Custom gametype HUD iAegle 17 15,353 07-14-2013, 01:16
Last Post: Nekochan

Forum Jump:


Users browsing this thread:
1 Guest(s)

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