Guest User

Untitled

a guest
Feb 13th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using MapEdit;
  6. using Addon;
  7. using System.CodeDom.Compiler;
  8. using System.Diagnostics;
  9.  
  10. namespace Bunker
  11. {
  12.     public class TVector
  13.     {
  14.         public Vector Vec1 = null;
  15.         public Vector vec2 = null;
  16.         public bool one;
  17.     }
  18.     public class Class1 : MapEdit.MapEdit
  19.     {
  20.  
  21.         List<string> Lines = new List<string>();
  22.         string _LastMap = "";
  23.         public override void OnPreMapChange()
  24.         {
  25.             _LastMap = GetDvar("mapname");
  26.             base.OnPreMapChange();
  27.         }
  28.         public override void OnMapChange()
  29.         {
  30.  
  31.             try
  32.             {
  33.                 foreach (string line in Lines)
  34.                 {
  35.                     ServerPrint(line);
  36.                 }
  37.                 if (GetServerCFG("BUNKER", "Save", "false") == "true")
  38.                 {
  39.                     string DllLines = System.IO.File.ReadAllText("plugins\\refer.txt");
  40.                     DllLines = DllLines.Replace("{0}", _LastMap);
  41.                     string Line = string.Join("\r\n", Lines.ToArray());
  42.                     DllLines = DllLines.Replace("{1}", Line);
  43.                     CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
  44.                     string Output = _LastMap + ".dll";
  45.                     System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
  46.                     parameters.ReferencedAssemblies.Add("plugins\\mapedit.dll");
  47.                     parameters.ReferencedAssemblies.Add("addon\\dist\\addon.dll");
  48.                     parameters.GenerateExecutable = false;
  49.                     parameters.OutputAssembly = Output;
  50.                     CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, DllLines);
  51.  
  52.                     if (results.Errors.Count > 0)
  53.                     {
  54.                         System.IO.File.WriteAllText("hohoohoho.txt", DllLines);
  55.                         foreach (CompilerError CompErr in results.Errors)
  56.                         {
  57.                             ServerPrint(
  58.                                          "Line number " + CompErr.Line +
  59.                                          ", Error Number: " + CompErr.ErrorNumber +
  60.                                          ", '" + CompErr.ErrorText + ";" +
  61.                                          Environment.NewLine + Environment.NewLine);
  62.                         }
  63.                     }
  64.                     else
  65.                     {
  66.                         System.IO.File.Copy(Output, "plugins\\" + Output, true);
  67.                     }
  68.                 }
  69.             }
  70.             catch (Exception e)
  71.             {
  72.                 ServerPrint(e.ToString());
  73.             }
  74.             ServerPrint(_LastMap);
  75.             Lines.Clear();
  76.         }
  77.         TVector wall = new TVector();
  78.         TVector ramp = new TVector();
  79.         TVector door = new TVector();
  80.         TVector floor = new TVector();
  81.         static string GetString(Vector vec1)
  82.         {
  83.             return "new Vector(" + Math.Round(vec1.X, 0, MidpointRounding.AwayFromZero) + "f," + Math.Round(vec1.Y, 0, MidpointRounding.AwayFromZero) + "f," + Math.Round(vec1.Z, 0, MidpointRounding.AwayFromZero) + "f)";
  84.         }
  85.         public override Addon.ChatType OnSay(string Message, Addon.ServerClient Client, bool Teamchat)
  86.         {
  87.             if (Message
  88.                 == "!door")
  89.             {
  90.                 if (door.one)
  91.                 {
  92.                     door.vec2 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  93.  
  94.                     iPrintLnBold("two vector of door", Client);
  95.                     CreateDoor(door.Vec1, door.vec2);
  96.                     Lines.Add("CreateDoor(" + GetString(door.Vec1) + "," + GetString(door.vec2) + ");");
  97.                     door = new TVector();
  98.                 }
  99.                 else
  100.                 {
  101.                     door.one = true;
  102.                     door.Vec1 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  103.                     iPrintLnBold("One vector of door", Client);
  104.  
  105.                 }
  106.                 return ChatType.ChatNone;
  107.             }
  108.             if (Message == "!wall")
  109.             {
  110.  
  111.  
  112.                 if (wall.one == true)
  113.                 {
  114.                     wall.vec2 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  115.  
  116.                     iPrintLnBold("two vector of wall", Client);
  117.                     CreateWall(wall.Vec1, wall.vec2);
  118.                     Lines.Add("CreateWall(" + GetString(wall.Vec1) + "," + GetString(wall.vec2) + ");");
  119.                     wall = new TVector();
  120.                 }
  121.                 else
  122.                 {
  123.                     wall.one = true;
  124.                     wall.Vec1 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  125.                     iPrintLnBold("One vector of wall", Client);
  126.                 }
  127.  
  128.                 return ChatType.ChatNone;
  129.             }
  130.             if (Message == "!weapon")
  131.             {
  132.                 SpawnModel("script_model", "weapon_aa12_iw5", new Vector(Client.OriginX, Client.OriginY, Client.OriginZ+10));
  133.  
  134.                 SpawnModel("script_model", "viewmodel_aa12_iw5", new Vector(Client.OriginX, Client.OriginY, Client.OriginZ+50));
  135.  
  136.                 return ChatType.ChatNone;
  137.             }
  138.             if (Message == "!floor")
  139.             {
  140.  
  141.                 if (floor.one == true)
  142.                 {
  143.                     floor.vec2 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  144.  
  145.                     iPrintLnBold("two vector of floor", Client);
  146.                     createfloor(floor.Vec1, floor.vec2);
  147.                     Lines.Add("createfloor(" + GetString(floor.Vec1) + "," + GetString(floor.vec2) + ");");
  148.                     floor = new TVector();
  149.                 }
  150.                 else
  151.                 {
  152.                     floor.one = true;
  153.                     floor.Vec1 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  154.                     iPrintLnBold("Floor vector of one", Client);
  155.                 }
  156.  
  157.  
  158.                 return ChatType.ChatNone;
  159.             }
  160.             if (Message == "!ramp")
  161.             {
  162.                 if (ramp.one == true)
  163.                 {
  164.                     ramp.vec2 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  165.                     iPrintLnBold("two vector of ramp", Client);
  166.                     CreateRamp(ramp.Vec1, ramp.vec2);
  167.                     Lines.Add("CreateRamp(" + GetString(ramp.Vec1) + "," + GetString(ramp.vec2) + ");");
  168.                     ramp = new TVector();
  169.                 }
  170.                 else
  171.                 {
  172.                     ramp.one = true;
  173.                     ramp.Vec1 = new Vector(Client.OriginX, Client.OriginY, Client.OriginZ);
  174.                     iPrintLnBold("Floor vector of ramp", Client);
  175.                 }
  176.  
  177.                 return ChatType.ChatNone;
  178.             }
  179.             if (Message == "!fwall")
  180.             {
  181.                 wall = new TVector();
  182.  
  183.                 return ChatType.ChatNone;
  184.             }
  185.             if (Message == "!ffloor")
  186.             {
  187.                 floor = new TVector();
  188.  
  189.                 return ChatType.ChatNone;
  190.             }
  191.             if (Message == "!framp")
  192.             {
  193.                 ramp = new TVector();
  194.  
  195.                 return ChatType.ChatNone;
  196.             }
  197.             if (Message == "!fdoor")
  198.             {
  199.                 door = new TVector();
  200.                 return ChatType.ChatNone;
  201.             }
  202.             if (Message == "!noclip")
  203.             {
  204.                 Client.Other.NoClip = true;
  205.                 return ChatType.ChatNone;
  206.             }
  207.             if (Message == "!nclip")
  208.             {
  209.                 Client.Other.NoClip = false;
  210.                 return ChatType.ChatNone;
  211.             }
  212.             else
  213.                 return base.OnSay(Message, Client,
  214.                 Teamchat);
  215.         }
  216.     }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment