09-25-2013, 17:13
(This post was last modified: 12-30-2013, 15:10 by [HARD] Tony..)
Code:
using System;
using System.Collections.Generic;
using Addon;
using System.Collections;
using System.IO;
using System.Timers;
using System.Runtime.InteropServices;
namespace Door
{
public class Door : CPlugin
{
Dictionary<int, int> Client_HudElem_lm = new Dictionary<int, int>();
int fx = 0;
enum DoorState
{
Button,
Top,
Destroy
};
public int DoorHealth = 750;
int Interval = 0;
public int State = 0;
public bool DoorWork = false;
List<Entity> Boxes = new List<Entity>();
public override void OnServerLoad()
{
Th.Elapsed += new ElapsedEventHandler(Event);
Th.Interval = 150;
}
Timer Th = new Timer();
int Counter = 0;
public override void OnMapChange()
{
Counter = 0;
Th.Stop();
Boxes.Clear();
Interval = 0;
DoorHealth = 100;
State = 0;
DoorWork = false;
string map = GetDvar("mapname");
if (map == "mp_lambeth")
{
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(2850f, 703.719f, -281.875f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(2850f, 703.583f, -210.0819f)));
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], Extensions.FindAirdropCrateCollisionId());
}
}
if (map == "mp_lambeth")
{
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(1887.093f, -520.5082f, -241.7929f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(1890.825f, -520.6057f, -172.9306f)));
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], Extensions.FindAirdropCrateCollisionId());
Vector vector = Extensions.GetAngles(Boxes[i]); vector.Y += 90; Extensions.SetAngles(Boxes[i], vector);
}
}
if (map == "mp_terminal_cls")
{
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3538.042f, 204.125f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3481.042f, 204.125f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3424.042f, 204.125f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3538.042f, 270.125f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3481.042f, 270.125f)));
Boxes.Add(SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(3861.388f, 3424.042f, 270.125f)));
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], Extensions.FindAirdropCrateCollisionId());
Vector vector = Extensions.GetAngles(Boxes[i]); vector.Y += 90; Extensions.SetAngles(Boxes[i], vector);
}
}
}
public override void OnServerFrame()
{
if (Interval == 0)
{
Interval = 10;
}
else
{
Interval--;
}
}
public void Event(object source, ElapsedEventArgs e)
{
//Counter -
if (Counter <= 17)
{
if (State == (int)DoorState.Button)
{
for (int i = 0; i < Boxes.Count; i++)
{
// 5 = Z
Boxes[i].OriginY += 10;
}
}
else if (State == (int)DoorState.Top)
{
for (int i = 0; i < Boxes.Count; i++)
{
Boxes[i].OriginY -= 10;
}
}
Counter++;
}
else
{
if (State == (int)DoorState.Button)
{
State = (int)DoorState.Top;
}
else
{
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], Extensions.FindAirdropCrateCollisionId());
}
State = (int)DoorState.Button;
}
DoorWork = false;
Counter = 0;
Th.Stop();
}
}
public override void OnAddonFrame()
{
List<ServerClient> clients;
try
{
clients = GetClients();
if (clients != null && clients.Count > 0)
{
foreach (ServerClient c in GetClients())
{
if (c.Other.isAlive == true/* && !DoorDestroy*/)
{
HudElem hl = GetHudElement(Client_HudElem_lm[c.ClientNum]);
string map = GetDvar("mapname");
if (map == "mp_lambeth" && State != (int)DoorState.Destroy)
{
if ((Difference(c.OriginY, 703.0484f) <= 150) && (Difference(c.OriginX, 2850.202f) <= 150) && c.OriginZ >= -306.1291f)
{
if (c.Team == Teams.Allies)
{
if (!DoorWork && State == (int)DoorState.Button)
{
hl.SetString(" ^3F^7 ^1");
}
if (!DoorWork && State == (int)DoorState.Top)
{
hl.SetString(" ^3F^7 ^1");
}
if (c.Other.ButtonPressed(Buttons.Activate) && !DoorWork)
{
if (State == (int)DoorState.Button)
{
PlaySoundOnPlayer(c, "elev_door_close");
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
}
}
if (State == (int)DoorState.Top)
{
PlaySoundOnPlayer(c, "elev_door_interupt");
}
DoorWork = true;
Counter = 0;
Th.Start();
}
}
else
{
hl.SetString(" -^1 ^7!");
if (c.Other.ButtonPressed(Buttons.Knife) && !DoorWork && State == (int)DoorState.Button)
{
if (DoorHealth > 5)
{
if (Interval == 0)
{
DoorHealth -= 5;
iPrintLnBold(": ^2 " + DoorHealth, c);
}
}
else
{
hl.SetString("");
State = (int)DoorState.Destroy;
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
Boxes[i].Delete();
}
Boxes.Clear();
}
}
}
}
else
{
hl.SetString("");
}
}
/////////
if (map == "mp_terminal_cls" && State != (int)DoorState.Destroy)
{
if ((Difference(c.OriginY, 3490.191f) <= 150) && (Difference(c.OriginX, 3864.955f) <= 150) && c.OriginZ >= 100.125f)
{
if (c.Team == Teams.Allies)
{
if (!DoorWork && State == (int)DoorState.Button)
{
hl.SetString(" ^3F^7 ^1");
}
if (!DoorWork && State == (int)DoorState.Top)
{
hl.SetString(" ^3F^7 ^1");
}
if (c.Other.ButtonPressed(Buttons.Activate) && !DoorWork)
{
if (State == (int)DoorState.Button)
{
PlaySoundOnPlayer(c, "elev_door_close");
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
}
}
if (State == (int)DoorState.Top)
{
PlaySoundOnPlayer(c, "elev_door_interupt");
}
DoorWork = true;
Counter = 0;
Th.Start();
}
}
else
{
hl.SetString(" -^1 ^7!");
if (c.Other.ButtonPressed(Buttons.Knife) && !DoorWork && State == (int)DoorState.Button)
{
if (DoorHealth > 5)
{
if (Interval == 0)
{
DoorHealth -= 5;
iPrintLnBold(": ^2 " + DoorHealth, c);
}
}
else
{
hl.SetString("");
State = (int)DoorState.Destroy;
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
Boxes[i].Delete();
}
Boxes.Clear();
}
}
}
}
else
{
hl.SetString("");
}
}
if (map == "mp_lambeth" && State != (int)DoorState.Destroy)
{
if ((Difference(c.OriginY, -534.8205f) <= 150) && (Difference(c.OriginX, 1895.324f) <= 150) && c.OriginZ >= -253.5872f)
{
if (c.Team == Teams.Allies)
{
if (!DoorWork && State == (int)DoorState.Button)
{
hl.SetString(" ^3F^7 ^1");
}
if (!DoorWork && State == (int)DoorState.Top)
{
hl.SetString(" ^3F^7 ^1");
}
if (c.Other.ButtonPressed(Buttons.Activate) && !DoorWork)
{
if (State == (int)DoorState.Button)
{
PlaySoundOnPlayer(c, "elev_door_close");
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
}
}
if (State == (int)DoorState.Top)
{
PlaySoundOnPlayer(c, "elev_door_interupt");
}
DoorWork = true;
Counter = 0;
Th.Start();
}
}
else
{
hl.SetString(" -^1 ^7!");
if (c.Other.ButtonPressed(Buttons.Knife) && !DoorWork && State == (int)DoorState.Button)
{
if (DoorHealth > 3)
{
if (Interval == 0)
{
;
DoorHealth -= 3;
iPrintLnBold(": ^2 " + DoorHealth, c);
}
}
else
{
hl.SetString("");
State = (int)DoorState.Destroy;
for (int i = 0; i < Boxes.Count; i++)
{
Extensions.PlayFX(fx, new Vector(1895.324f, -534.8205f, -253.5872f));
Extensions.CloneBrushModelToScriptModel(Boxes[i], 0);
Boxes[i].Delete();
}
Boxes.Clear();
}
}
}
}
else
{
hl.SetString("");
}
}
}
}
}
}
catch (Exception z)
{
ServerPrint("Error Doors: " + z.Message);
}
}
public static float Difference(float loc, float loc2)
{
return Math.Abs(loc - loc2);
}
public override void OnPlayerDisconnect(ServerClient client)
{
if (Client_HudElem_lm.ContainsKey(client.ClientNum))
{
HudElem info2 = GetHudElement(Client_HudElem_lm[client.ClientNum]);
info2.Type = HudElementTypes.None;
Client_HudElem_lm.Remove(client.ClientNum);
}
}
public override void OnPlayerConnect(ServerClient client)
{
int HudElemNum1 = CreateHud_lm(client.ClientNum);
if (Client_HudElem_lm.ContainsKey(client.ClientNum))
{
Client_HudElem_lm[client.ClientNum] = HudElemNum1;
}
else
{
Client_HudElem_lm.Add(client.ClientNum, HudElemNum1);
}
}
private int CreateHud_lm(int ClientNum)
{
HudElem hud = CreateNewHudElem();
hud.Type = HudElementTypes.Text;
hud.ShowToEnt = ClientNum;
hud.HideInMenu = true;
hud.Font = HudElementFonts.Default;
hud.FontScale = 1.7f;
hud.PointType = 120;
hud.OriginY = 180f;
hud.OriginX = -100f;
hud.SetString("");
return hud.HudElementNum;
}
}
}idea @[Z00MBY] Alex
help @extreme2010 (aka [MEM] So Close )
main @master131
creator http://www.forum.hard-zombie.com


