Hey everyone
I created this plugin because I was bored, you can spawn a working ac130 turret with it.
sv_config:
screenshot
![[Image: E2BE8B3A0F0375B4C949DFA2310ACD7E4F5CC991]](http://cloud-2.steampowered.com/ugc/541833502896437263/E2BE8B3A0F0375B4C949DFA2310ACD7E4F5CC991/)
Modelname: sentry_minigun
I didn't test the plugin with more than one turret in a map, that won't work probably.
It's only storing primary and secondary weapons so you shouldn't use it if you got more weapon slots.
Maybe I will update the plugin if it's necessary.
You can edit the code but don't change the credits please
Credits:
@8q4s8 - creator
@alex - I rebuilt the one from his preview
@master131 - rotate stuff extension
Please +rep if you're using this plugin!
I created this plugin because I was bored, you can spawn a working ac130 turret with it.
sv_config:
Code:
[TURRET]
//how long you can use the turret until it breaks
timeinturret=10
//how long the turrets pause
pause=20
//the press F radius of the turrets
radius=100
//gametype infected (true/false)
infected=true
turrets=2
//Format: turret123=mapname,OriginX,OriginY,OriginZ,rotation
//use 0,90,180,270 or 360 for the rotation
turret1=mp_dome,-583,124,-414.89,180
turret2=mp_underground,0,0,0,90screenshot
Modelname: sentry_minigun
I didn't test the plugin with more than one turret in a map, that won't work probably.
It's only storing primary and secondary weapons so you shouldn't use it if you got more weapon slots.
Maybe I will update the plugin if it's necessary.
You can edit the code but don't change the credits please
SourceCode (Click to View)
Code:
using System;
using System.Collections.Generic;
using Addon;
using System.Text;
using System.Timers;
namespace ClassLibrary1
{
public class TurretLoc
{
public float x;
public float y;
public float z;
public float rotation;
public TurretLoc(float _x,float _y,float _z,float _rotation)
{
x = _x;
y = _y;
z = _z;
rotation = _rotation;
}
}
public class Class1 : CPlugin
{
#region variables
string map = "";
bool isinturret = false;
float radius;
int timeInTurret;
int pause;
int seconds;
int seconds2;
int Primary;
int Secondary;
int Current;
int turret;
int turretAmmo = 10000;
int primaryAmmo;
int secondaryAmmo;
int primaryAmmoClip;
int secondaryAmmoClip;
Timer timer = new Timer();
ServerClient c;
Dictionary<int, int> Client_HudElem_lm = new Dictionary<int, int>();
Dictionary<string, TurretLoc> maps = new Dictionary<string,TurretLoc>();
Dictionary<string, bool> user = new Dictionary<string, bool>();
#endregion
public override void OnServerLoad()
{
ServerPrint("\n Turret Plugin by 8Q4S8 loaded! \n");
ConfigStuff();
timer.Elapsed += new ElapsedEventHandler(tmr);
timer.Interval = 1000;
timer.Enabled = true;
}
public static float Difference(float loc1, float loc2)
{
return Math.Abs(loc1 - loc2);
}
public override int OnPlayerDamaged(ServerClient Attacker, ServerClient Victim, string Weapon, int Damage)
{
if (Victim.Other.PrimaryWeapon == turret && Victim.XUID == Attacker.XUID && user[Victim.XUID] == true)
{
Damage = 0;
}
return Damage;
}
public override void OnMapChange()
{
map = GetDvar("mapname");
isinturret = false;
Primary = 0;
Secondary = 0;
Current = 0;
turret = GetWeapon("ac130_25mm_mp");
primaryAmmo = 0;
secondaryAmmo = 0;
primaryAmmoClip = 0;
secondaryAmmoClip = 0;
seconds = 0;
seconds2 = 0;
foreach (string key in maps.Keys)
{
if (key.Contains(map))
{
Entity ent1 = SpawnModel("script_model", "sentry_minigun", new Vector(maps[key].x,maps[key].y,maps[key].z));
Extensions.SetAngles(ent1, new Vector(0, maps[key].rotation, 0));
}
}
}
#region Turret functions
public void RemoveTurret()
{
c.Other.PrimaryWeapon = Primary;
c.Other.SecondaryWeapon = Secondary;
c.Other.CurrentWeapon = Current;
c.Ammo.PrimaryAmmo = primaryAmmo;
c.Ammo.SecondaryAmmo = secondaryAmmo;
c.Ammo.PrimaryAmmoClip = primaryAmmoClip;
c.Ammo.SecondaryAmmoClip = secondaryAmmoClip;
PlaySoundOnPlayer(c, "sentry_explode");
c.Other.AllowJump = true;
isinturret = false;
user.Remove(c.XUID);
seconds = pause;
seconds2 = timeInTurret;
}
public void GetTurret()
{
Primary = c.Other.PrimaryWeapon;
Secondary = c.Other.SecondaryWeapon;
Current = c.Other.CurrentWeapon;
primaryAmmo = c.Ammo.PrimaryAmmo;
secondaryAmmo = c.Ammo.SecondaryAmmo;
primaryAmmoClip = c.Ammo.PrimaryAmmoClip;
secondaryAmmoClip = c.Ammo.SecondaryAmmoClip;
turret = GetWeapon("ac130_25mm_mp");
turretAmmo = 10000;
c.Other.SpeedScale = 0;
c.Other.AllowJump = false;
c.Other.PrimaryWeapon = turret;
c.Other.SecondaryWeapon = turret;
c.Other.CurrentWeapon = turret;
c.Ammo.PrimaryAmmoClip = turretAmmo;
c.Ammo.PrimaryAmmo = turretAmmo;
c.Ammo.SecondaryAmmo = turretAmmo;
c.Ammo.SecondaryAmmoClip = turretAmmo;
seconds = pause;
seconds2 = timeInTurret;
isinturret = true;
user.Add(c.XUID, true);
}
#endregion
public void tmr(object s, ElapsedEventArgs e)
{
seconds--;
foreach (ServerClient Client in GetClients())
{
c = Client;
HudElem hl = GetHudElement(Client_HudElem_lm[c.ClientNum]);
if (c.Team == Teams.Allies)
{
foreach (string key in maps.Keys)
{
if (key.Contains(map))
{
if (Difference(c.OriginX, maps[key].x) <= radius && Difference(c.OriginY, maps[key].y) <= radius && Difference(c.OriginZ, maps[key].z) <= radius)
{
if (isinturret == true)
{
seconds2--;
if (user.ContainsKey(c.XUID))
{
hl.SetString("Press ^2F ^7to leave the turret");
if (c.Other.ButtonPressed(Buttons.Activate))
{
RemoveTurret();
}
if (seconds2 <= 0)
{
RemoveTurret();
}
}
else
{
hl.SetString("Someone is already using the turret");
}
}
else
{
if (seconds <= 0)
{
hl.SetString("Press ^2F ^7to use the turret");
if (c.Other.ButtonPressed(Buttons.Activate))
{
GetTurret();
//too lazy to add math function :P
if (maps[key].rotation >= 0 && maps[key].rotation <= 44)
{
c.OriginX = maps[key].x - 20;
c.OriginY = maps[key].y;
}
if (maps[key].rotation <= 135 && maps[key].rotation >= 45)
{
c.OriginX = maps[key].x;
c.OriginY = maps[key].y - 20f;
}
if (maps[key].rotation <= 225 && maps[key].rotation >= 136)
{
c.OriginX = maps[key].x + 20f;
c.OriginY = maps[key].y;
}
if (maps[key].rotation <= 315 && maps[key].rotation >= 226)
{
c.OriginX = maps[key].x;
c.OriginY = maps[key].y + 20f;
}
if (maps[key].rotation <= 360 && maps[key].rotation >= 316)
{
c.OriginX = maps[key].x - 20f;
c.OriginY = maps[key].y;
}
}
}
else
{
hl.SetString("You can use the turret again in ^2" + seconds.ToString() + "^7 seconds");
}
}
}
else
{
hl.SetString("");
}
}
}
}
else
{
hl.SetString("");
}
}
}
public void ConfigStuff()
{
//[TURRET]
//turrets=1
//turret1=mp_dome,12,12,0,90
radius = float.Parse(GetServerCFG("TURRET", "radius",""));
timeInTurret = int.Parse(GetServerCFG("TURRET", "timeinturret", ""));
pause = int.Parse(GetServerCFG("TURRET", "pause", ""));
try
{
string turrets = GetServerCFG("TURRET", "turrets", "");
if (turrets != "0")
{
for (int i = 1; i <= int.Parse(turrets); i++)
{
string loc = GetServerCFG("TURRET", string.Format("turret{0}", i), "");
if (loc != null)
{
string mp = loc.Split(',')[0];
string x = loc.Split(',')[1];
string y = loc.Split(',')[2];
string z = loc.Split(',')[3];
string rotation = loc.Split(',')[4];
maps.Add(i.ToString() + mp, new TurretLoc(float.Parse(x),float.Parse(y),float.Parse(z),float.Parse(rotation)));
}
}
}
}
catch (Exception ex) { ServerPrint("Loading turrets failed: " + ex.Message); }
}
#region HUD stuff
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.5f;
hud.PointType = 120;
hud.OriginY = 300f;
hud.OriginX = -100f;
hud.SetString("");
return hud.HudElementNum;
}
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);
}
#endregion
}
}Spoiler (Click to View)
Change Log
Code:
v1.0 initial release
v1.1 fixed small bugs, you can't kill yourself anymore
v1.2 added support for every gametypeCredits:
@8q4s8 - creator
@alex - I rebuilt the one from his preview
@master131 - rotate stuff extension
Please +rep if you're using this plugin!

