Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Addon;
  4. using System.IO;
  5.  
  6. namespace MoonShop
  7. {
  8.     public class Shop : CPlugin
  9.     {
  10.         public string something = "AHAHHAHAHAHAHAHAHHAHAHA";
  11.  
  12.  
  13.         public Dictionary<String, String> menus = new Dictionary<String, String>();
  14.         public Dictionary<String, bool> isClassed = new Dictionary<String, bool>();
  15.  
  16.         public Dictionary<String, String> Language = new Dictionary<String, String>();
  17.         private Dictionary<String, double> justSpawned = new Dictionary<string, double>();
  18.  
  19.         // zoms
  20.         public Dictionary<String, float> speed = new Dictionary<String, float>();
  21.         public Dictionary<String, String> hpzom = new Dictionary<String, String>();
  22.         public Dictionary<String, bool> isJug = new Dictionary<string, bool>();
  23.  
  24.         public Dictionary<int, int> Client_HudElem_Shop = new Dictionary<int, int>();
  25.  
  26.         public override ChatType OnSay(string Message, ServerClient Client, bool Teamchat)
  27.         {
  28.             int points = getPoints(Client.XUID);
  29.             ToDo(Client, Message, points);
  30.  
  31.             return base.OnSay(Message, Client, Teamchat);
  32.         }
  33.  
  34.         Statistics stats;
  35.         int pointstokill = 20;
  36.  
  37.         public override int OnPlayerDamaged(ServerClient Attacker, ServerClient Victim, String Weapon, Int32 Damage, String DamageMod, HitLocations HitLocation)
  38.         {
  39.             if (Damage >= Victim.Other.Health && Attacker.Team != Victim.Team)
  40.             {
  41.                 UpdatePoints(pointstokill, Victim);
  42.             }
  43.  
  44.             return base.OnPlayerDamaged(Attacker, Victim, Weapon, Damage);
  45.         }
  46.  
  47.  
  48.         public override void OnServerLoad()
  49.         {
  50.             try
  51.             {
  52.                 stats = new Statistics();
  53.                 SV_Shop();
  54.             }
  55.             catch(Exception z)
  56.             {
  57.                 ServerPrint(string.Format("[mShop - ENG]: I couldn't launch mShop plugin because error happened. {0}", z.Message));
  58.                 ServerPrint(string.Format("[mShop - RUS]: Плагин mShop не был загружен, т.к ошибочка вышла - {0}", z.Message));
  59.             }
  60.             base.OnServerLoad();
  61.         }
  62.  
  63.         public override void OnAddonFrame()
  64.         {
  65.             Update();
  66.             base.OnAddonFrame();
  67.         }
  68.  
  69.         public void UpdatePoints(int inc, ServerClient c)
  70.         {
  71.             stats.updatePoints(inc, c);
  72.         }
  73.  
  74.         public int getPoints(String XUID)
  75.         {
  76.             return stats.Stats[XUID].Points;
  77.         }
  78.  
  79.  
  80.         public override void OnPlayerDisconnect(ServerClient client)
  81.         {
  82.             isClassed.Remove(client.XUID);
  83.             Language.Remove(client.XUID);
  84.             menus.Remove(client.XUID);
  85.             hpzom.Remove(client.XUID);
  86.             speed.Remove(client.XUID);
  87.             isJug.Remove(client.XUID);
  88.  
  89.             deleteHUD(client);
  90.         }
  91.  
  92.         public override void OnPlayerConnect(ServerClient client)
  93.         {
  94.             // default values
  95.             Language.Add(client.XUID, "eng");
  96.  
  97.             menus.Add(client.XUID, "0");
  98.             speed.Add(client.XUID, 1);
  99.             isJug.Add(client.XUID, false); // nononononono
  100.             hpzom.Add(client.XUID, "100");
  101.  
  102.             if (!stats.Stats.ContainsKey(client.XUID))
  103.                 stats.insertNewPerson(client);
  104.  
  105.             // heads up display
  106.             int clientshop = ShopMenu_HUD(client.ClientNum);
  107.             if (Client_HudElem_Shop.ContainsKey(client.ClientNum))
  108.                 Client_HudElem_Shop[client.ClientNum] = clientshop;
  109.             else
  110.                 Client_HudElem_Shop.Add(client.ClientNum, clientshop);
  111.         }
  112.  
  113.         private int ShopMenu_HUD(int ClientNum)
  114.         {
  115.             HudElem hud = CreateNewHudElem();
  116.             hud.Type = HudElementTypes.Text;
  117.             hud.ShowToEnt = ClientNum;
  118.             hud.HideInMenu = true;
  119.             hud.Font = HudElementFonts.Default;
  120.             hud.FontScale = 1.1f;
  121.             hud.PointType = 81;
  122.             hud.OriginY = 189f;
  123.             hud.OriginX = 10f;
  124.  
  125.             return hud.HudElementNum;
  126.         }
  127.  
  128.         public void deleteHUD(ServerClient client)
  129.         {
  130.             if (Client_HudElem_Shop.ContainsKey(client.ClientNum))
  131.             {
  132.                 HudElem kd = GetHudElement(Client_HudElem_Shop[client.ClientNum]);
  133.                 kd.Type = HudElementTypes.None;
  134.                 Client_HudElem_Shop.Remove(client.ClientNum);
  135.             }
  136.         }
  137.  
  138.  
  139.         public struct PerkInfo
  140.         {
  141.             public string perkname;
  142.             public string cost;
  143.             public string num;
  144.             public string perknamreal;
  145.             public PerkInfo(string wep, string costs, string numz, string fag)
  146.             {
  147.                 perkname = wep;
  148.                 cost = costs;
  149.                 num = numz;
  150.                 perknamreal = fag;
  151.             }
  152.         }
  153.  
  154.         public struct WepInfo
  155.         {
  156.             public string wepname;
  157.             public string cost;
  158.             public string type;
  159.             public string num;
  160.             public string realname;
  161.             public WepInfo(string wep, string costs, string typez, string numz, string fag)
  162.             {
  163.                 wepname = wep;
  164.                 cost = costs;
  165.                 type = typez;
  166.                 num = numz;
  167.                 realname = fag;
  168.             }
  169.         }
  170.  
  171.         public Dictionary<String, WepInfo> shopdata = new Dictionary<string, WepInfo>();
  172.         public Dictionary<String, PerkInfo> perkdata = new Dictionary<string, PerkInfo>();
  173.         public void SV_Shop()
  174.         {
  175.             string init = File.ReadAllText(Directory.GetCurrentDirectory() + "/plugins/items.txt");
  176.             string[] lines = init.Split('\n');
  177.             foreach (string line in lines)
  178.             {
  179.                 string[] item = line.Split(',');
  180.                 // 0 - func
  181.                 // 1 - item
  182.                 // 2 - cost
  183.                 // 3 - num
  184.                 // 4 - type
  185.                 if (item[0] == "addwep")
  186.                 {
  187.                     shopdata.Add(item[3], new WepInfo(item[1], item[2], item[4], item[3], item[5]));
  188.                     ServerPrint("mShop: Added " + item[1] + " " + item[2] + " " + item[4] + " " + item[3]);
  189.                 }
  190.                 else if (item[0] == "addperk")
  191.                     perkdata.Add(item[3], new PerkInfo(item[1], item[2], item[3], item[4]));
  192.                 else if (item[0] == "set")
  193.                 {
  194.                     if (item[1] == "xppoint")
  195.                     {
  196.                         pointstokill = Convert.ToInt32(item[2]);
  197.                     }
  198.                     else
  199.                     {
  200.                         ServerPrint("mShop - Unknown parameter " + item[1]);
  201.                     }
  202.                 }
  203.             }
  204.  
  205.  
  206.             foreach (KeyValuePair<String, WepInfo> it in shopdata)
  207.             {
  208.                 if (it.Value.type == "smg")
  209.                     smg += "\n!" + it.Value.num + "-" + it.Value.realname + "[" + it.Value.cost + "]";
  210.             }
  211.  
  212.             foreach (KeyValuePair<String, WepInfo> it in shopdata)
  213.             {
  214.                 if (it.Value.type == "ass")
  215.                     ass += "\n!" + it.Value.num + "-" + it.Value.realname + "[" + it.Value.cost + "]";
  216.             }
  217.  
  218.             foreach (KeyValuePair<String, WepInfo> it in shopdata)
  219.             {
  220.                 if (it.Value.type == "sg")
  221.                     sg += "\n!" + it.Value.num + "-" + it.Value.realname + "[" + it.Value.cost + "]";
  222.             }
  223.  
  224.             foreach (KeyValuePair<String, WepInfo> it in shopdata)
  225.             {
  226.                 if (it.Value.type == "snip")
  227.                     snip += "\n!" + it.Value.num + "-" + it.Value.realname + "[" + it.Value.cost + "]";
  228.             }
  229.  
  230.             foreach (KeyValuePair<String, WepInfo> it in shopdata)
  231.             {
  232.                 if (it.Value.type == "an")
  233.                     an += "\n!" + it.Value.num + "-" + it.Value.realname + "[" + it.Value.cost + "]";
  234.             }
  235.  
  236.             foreach (KeyValuePair<String, PerkInfo> it in perkdata)
  237.             {
  238.                 p += "\n!" + it.Value.num + "-" + it.Value.perknamreal + "[" + it.Value.cost + "]";
  239.             }
  240.             // now tell us!
  241.             ServerPrint("[ENG]: mShop plugin was successfuly loaded!");
  242.             ServerPrint("[ENG#RUS] mShop Plugin - Created by SailorMoon ( itsmods.com )");
  243.             ServerPrint("[RUS]: mShop плагин загрузился....");
  244.         }
  245.  
  246.         string smg = "";
  247.         string ass = "";
  248.         string sg = "";
  249.         string snip = "";
  250.         string an = "";
  251.  
  252.         string p = "";
  253.  
  254.  
  255.         public void Update()
  256.         {
  257.             HudElem text;
  258.             List<ServerClient> clients;
  259.  
  260.             clients = GetClients();
  261.             if (clients != null)
  262.             {
  263.                 if (clients.Count > 0)
  264.                 {
  265.                     foreach (ServerClient client in GetClients())
  266.                     {
  267.                         if (client.Ping == 999)
  268.                             continue;
  269.  
  270.                         if (client.Other.isAlive == true)
  271.                         {
  272.                             if (client.ConnectionState != ConnectionStates.MapLoading)
  273.                             {
  274.                                 if (client.ConnectionState != ConnectionStates.Connecting)
  275.                                 {
  276.                                     if (client.ConnectionState != ConnectionStates.Zombie)
  277.                                     {
  278.                                         if (menus[client.XUID] == "1")
  279.                                         {
  280.                                             if (client.Other.ButtonPressed(Buttons.Reload))
  281.                                             {
  282.                                                 menus[client.XUID] = "2";
  283.                                             }
  284.                                             else if (client.Other.ButtonPressed(Buttons.Prone))
  285.                                             {
  286.                                                 menus[client.XUID] = "3";
  287.                                             }
  288.                                             else if (client.Other.ButtonPressed(Buttons.Activate))
  289.                                             {
  290.                                                 menus[client.XUID] = "4";
  291.                                             }
  292.                                             else if (client.Other.ButtonPressed(Buttons.Knife))
  293.                                             {
  294.                                                 menus[client.XUID] = "5";
  295.                                             }
  296.                                             else if (client.Other.ButtonPressed(Buttons.Crouch))
  297.                                             {
  298.                                                 menus[client.XUID] = "6";
  299.                                             }
  300.                                             else if (client.Other.ButtonPressed(Buttons.Sprint))
  301.                                             {
  302.                                                 menus[client.XUID] = "7";
  303.                                             }
  304.                                         }
  305.  
  306.                                         // 1- allies
  307.                                         // 11 - axis
  308.                                         if (client.Other.ButtonPressed(Buttons.Equipment))
  309.                                         {
  310.                                             if (client.Team == Teams.Allies)
  311.                                             {
  312.                                                 if (menus[client.XUID] == "1")
  313.                                                 {
  314.                                                     menus[client.XUID] = "0";
  315.                                                 }
  316.                                                 else
  317.                                                 {
  318.                                                     menus[client.XUID] = "1";
  319.                                                 }
  320.                                             }
  321.                                             else if (client.Team == Teams.Axis)
  322.                                             {
  323.                                                 if (menus[client.XUID] == "11")
  324.                                                 {
  325.                                                     menus[client.XUID] = "0";
  326.                                                 }
  327.                                                 else
  328.                                                 {
  329.                                                     menus[client.XUID] = "11";
  330.                                                 }
  331.                                             }
  332.                                         }
  333.  
  334.                                         text = GetHudElement(Client_HudElem_Shop[client.ClientNum]);
  335.                                         switch (menus[client.XUID])
  336.                                         {
  337.                                             case "0": // closed
  338.                                                 if (Language[client.XUID] == "eng")
  339.                                                     text.SetString("^2Q (equipment) key ^7-^3 Shop");
  340.                                                 else if (Language[client.XUID] == "rus")
  341.                                                     text.SetString("^2Q (доп.граната) ^7-^3 Магазин");
  342.                                                 break;
  343.                                             case "1": // choose list
  344.                                                 if (Language[client.XUID] == "eng")
  345.                                                     text.SetString("R(reload)-SMG\nC(prone)-Assault\nF(use)-Shotguns\nE(knife)-Snips\nCrouch-Another\nShift-Perks\nQ-Back");
  346.                                                 else if (Language[client.XUID] == "rus")
  347.                                                     text.SetString("R(перезарядка)-ПП\nC(присесть)-Штурм.Вин.\nF(исп.)-Дробовики\nE(нож)-Снайп.\nЛечь-Прочее\nShift-Перки\nQ-Назад");
  348.                                                 break;
  349.  
  350.                                             // weps
  351.                                             case "2": // smg
  352.  
  353.                                                 text.SetString(smg + "\nQ - Back");
  354.                                                 break;
  355.                                             case "3": // assault
  356.      
  357.                                                 text.SetString(ass + "\nQ - Back");
  358.                                                 //text.SetString("!10 -M4[1000]\n!11 -M16[1100]\n!12 -FAD[1600]\n!13 -ACR[1700]\n!14 -T95[1600]\n!15 -M14[1700]\n!17 -G36[1500]\nQ-Back");
  359.                                                 break;
  360.                                             case "4": // shotguns
  361.                                              
  362.                                                 text.SetString(sg + "\nQ - Back");
  363.                                                // text.SetString("!21 - KSG[1600]\n!22 - SPAS12[1700]\n!23 - USAS12[1650]\nQ - Back");
  364.                                                 break;
  365.                                             case "5": // snipers
  366.  
  367.                                                 text.SetString(snip + "\nQ - Back");
  368.                                                // text.SetString("!18 - Barrett[900]\n!19 - MSR[1900]\n!20 - L96 [1800]\nQ - Back");
  369.                                                 break;
  370.                                             case "6": // another
  371.                                                
  372.                                                 text.SetString(an + "\nQ - Back");
  373.                                                // text.SetString("!24 - XM25[4000]\n!26 - Desert Eagle[800]\nQ - Back");
  374.                                                 break;
  375.                                             case "7": // perks
  376.                                                
  377.                                                 text.SetString(p + "\nQ - Back");
  378.                                                // text.SetString("!26-Marathon[1100]\n!27-Longer Sprint[1000]\n!28-FastReload[1400]\n!29-BulletAccuraty[1300]\nQ - Back");
  379.                                                 break;
  380.  
  381.                                             // axis
  382.                                             case "11":
  383.                                                 text.SetString("!31 - Throwing Knife[500]\n!32 - JUGGERNAUT ZOMBIE[6000]\n!33-More speed[1000]\n!34- More HP[200]");
  384.                                                 break;
  385.                                         }
  386.                                     }
  387.                                 }
  388.                             }
  389.                         }
  390.                     }
  391.                 }
  392.             }
  393.  
  394.         }
  395.  
  396.  
  397.         public ChatType ToDo(ServerClient Client, string Message, int point)
  398.         {
  399.             try
  400.             {
  401.                
  402.                 // POINTS
  403.                 int points = point;
  404.  
  405.                 if (Client.Team == Teams.Allies)
  406.                 {
  407.                     foreach (KeyValuePair<String, WepInfo> it in shopdata)
  408.                     {
  409.                         if (Message == "!" + it.Value.num)
  410.                         {
  411.                             if (getPoints(Client.XUID) >= Convert.ToInt32(it.Value.cost))
  412.                             {
  413.                                 if (it.Value.type != "an")
  414.                                     GiveWeaponTo(Client, it.Value.wepname, false);
  415.                                 else
  416.                                 {
  417.                                     GiveWeaponTo(Client, it.Value.wepname, true);
  418.                                 }
  419.  
  420.                                 UpdatePoints(-Convert.ToInt32(it.Value.cost), Client);
  421.  
  422.                             }
  423.                             else
  424.                             {
  425.                                 if (Language[Client.XUID] == "eng")
  426.                                 {
  427.                                     iPrintLnBold("^1No enough points!", Client);
  428.                                 }
  429.                                 else
  430.                                 {
  431.                                     iPrintLnBold("^1Не достаточно очков!", Client);
  432.                                 }
  433.                             }
  434.                             return ChatType.ChatNone;
  435.                         }
  436.  
  437.                     }
  438.  
  439.                     foreach (KeyValuePair<String, PerkInfo> it in perkdata)
  440.                     {
  441.                         if (Message == "!" + it.Value.num)
  442.                         {
  443.                             if (getPoints(Client.XUID) >= Convert.ToInt32(it.Value.cost))
  444.                             {
  445.                                 Client.Other.SetPerk(GetPerk(it.Value.perkname));
  446.                                 UpdatePoints(-Convert.ToInt32(it.Value.cost), Client);
  447.                             }
  448.                             else
  449.                             {
  450.                                 if (Language[Client.XUID] == "eng")
  451.                                 {
  452.                                     iPrintLnBold("^1No enough points!", Client);
  453.                                 }
  454.                                 else
  455.                                 {
  456.                                     iPrintLnBold("^1Не достаточно очков!", Client);
  457.                                 }
  458.                             }
  459.                             return ChatType.ChatNone;
  460.                         }
  461.                     }
  462.                 }
  463.  
  464.  
  465.                 // -------------------------------------------------------------- //
  466.                 if (Message == "!31")
  467.                 {
  468.                     if (Client.Team == Teams.Axis)
  469.                     {
  470.                         if (getPoints(Client.XUID) >= 500)
  471.                         {
  472.                             Client.Other.SetPerk(GetPerk("throwingknife_mp"));
  473.                             Client.Other.EquipementDisabled = true;
  474.                             Client.Other.EquipmentType = EquipementTypes.ThrowingKnife;
  475.                             Client.Other.Equipment = GetWeapon("throwingknife_mp");
  476.                         }
  477.                         else
  478.                         {
  479.                             if (Language[Client.XUID] == "eng")
  480.                                 iPrintLnBold("^1No enough points :(", Client);
  481.                             else
  482.                                 iPrintLnBold("^1Не достаточно очков :(", Client);
  483.                         }
  484.                     }
  485.                     return ChatType.ChatNone;
  486.                 }
  487.  
  488.                 if (Message == "!32")
  489.                 {
  490.                     if (Client.Team == Teams.Axis)
  491.                     {
  492.                         if (getPoints(Client.XUID) >= 6000)
  493.                         {
  494.                             isJug[Client.XUID] = true;
  495.                             // jug
  496.                             Client.Other.SetPlayerModel("mp_fullbody_opforce_juggernaut");
  497.                             hpzom[Client.XUID] = "1000";
  498.                             Client.Other.Health = Convert.ToInt32(hpzom[Client.XUID]);
  499.                             Client.Other.MaxHealth = Client.Other.Health;
  500.                         }
  501.                         else
  502.                         {
  503.                             if (Language[Client.XUID] == "eng")
  504.                                 iPrintLnBold("^1No enough points :(", Client);
  505.                             else
  506.                                 iPrintLnBold("^1Не достаточно очков :(", Client);
  507.                         }
  508.                     }
  509.                     return ChatType.ChatNone;
  510.                 }
  511.  
  512.                 if (Message == "!33")
  513.                 {
  514.                     if (Client.Team == Teams.Axis)
  515.                     {
  516.                         if (getPoints(Client.XUID) >= 1000)
  517.                         {
  518.                             speed[Client.XUID] = 1.2f;
  519.                             Client.Other.SpeedScale = 1.2f;
  520.                         }
  521.                         else
  522.                         {
  523.                             if (Language[Client.XUID] == "eng")
  524.                                 iPrintLnBold("^1No enough points :(", Client);
  525.                             else
  526.                                 iPrintLnBold("^1Не достаточно очков :(", Client);
  527.                         }
  528.                     }
  529.                     return ChatType.ChatNone;
  530.                 }
  531.  
  532.                 if (Message == "!34")
  533.                 {
  534.                     if (Client.Team == Teams.Axis)
  535.                     {
  536.                         if (getPoints(Client.XUID) >= 2000)
  537.                         {
  538.                             hpzom[Client.XUID] = "210";
  539.                             Client.Other.Health = Convert.ToInt32(hpzom[Client.XUID]);
  540.                             Client.Other.MaxHealth = Client.Other.Health;
  541.                         }
  542.                         else
  543.                         {
  544.                             if (Language[Client.XUID] == "eng")
  545.                                 iPrintLnBold("^1No enough points :(", Client);
  546.                             else
  547.                                 iPrintLnBold("^1Не достаточно очков :(", Client);
  548.                         }
  549.                     }
  550.                 }
  551.  
  552.                 // -----------------------------------------------------------------//
  553.                 if (Message == "!info")
  554.                 {
  555.                     iPrintLnBold("Created by SailorMoon ( itsmods.com ), type !mp to get points, type !eng or !rus to toggle languages!", Client);
  556.                 }
  557.  
  558.                 if (Message == "!rus")
  559.                 {
  560.                     Language[Client.XUID] = "rus";
  561.                     iPrintLnBold("Язык переключен.", Client);
  562.                     return ChatType.ChatNone;
  563.                 }
  564.  
  565.                 if (Message == "!eng")
  566.                 {
  567.                     Language[Client.XUID] = "eng";
  568.                     iPrintLnBold("Language was switched!", Client);
  569.                     return ChatType.ChatNone;
  570.                 }
  571.  
  572.                 if (Message == "!mp")
  573.                 {
  574.                     switch (Language[Client.XUID])
  575.                     {
  576.                         case "rus":
  577.                             iPrintLnBold(string.Format("У вас {0} очков!", getPoints(Client.XUID)), Client);
  578.                             return ChatType.ChatNone;
  579.                             break;
  580.                         case "eng":
  581.                             iPrintLnBold(string.Format("You have {0} points!", getPoints(Client.XUID)), Client);
  582.                             return ChatType.ChatNone;
  583.                             break;
  584.                     }
  585.                 }
  586.  
  587.                 if (Message == "!ABRA")
  588.                 {
  589.                     UpdatePoints(1000, Client);
  590.                 }
  591.  
  592.  
  593.                 return ChatType.ChatContinue;
  594.             }
  595.             catch (Exception z)
  596.             {
  597.                 ServerPrint(z.Message);
  598.                 return ChatType.ChatContinue;
  599.             }
  600.  
  601.             return ChatType.ChatContinue;
  602.         }
  603.  
  604.         public void GiveWeaponTo(ServerClient client, string weapon, bool issec)
  605.         {
  606.             if (issec == false)
  607.             {
  608.                 int WepSecID = GetWeapon(weapon);
  609.                 client.Other.SecondaryWeapon = WepSecID;
  610.                 client.Other.CurrentWeapon = WepSecID;
  611.  
  612.                 int clip = 0;
  613.                 int ammo = 0;
  614.                 Weapons weap = new Weapons(this);
  615.  
  616.                 weap.refill(WepSecID, ref ammo, ref clip);
  617.                 client.Ammo.SecondaryAmmo = ammo;
  618.                 client.Ammo.SecondaryAmmoClip = clip * 2;
  619.             }
  620.             else if (issec == true)
  621.             {
  622.                 int WepPist = GetWeapon(weapon);
  623.                 client.Other.PrimaryWeapon = WepPist;
  624.  
  625.                 int clipsec = 0;
  626.                 int ammosec = 0;
  627.  
  628.                 Weapons weap = new Weapons(this);
  629.                 weap.refill(WepPist, ref ammosec, ref clipsec);
  630.                 client.Ammo.PrimaryAmmo = ammosec;
  631.                 client.Ammo.PrimaryAmmoClip = clipsec * 2;
  632.             }
  633.         }
  634.  
  635.     }
  636. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement