08-10-2013, 20:05
I always get the error The type or namespace name could not be found, but if I add InfinityScript as reference then i get more errors. This is a decompiled dll file which I edited for my liking, I included the original dll as attachment if it helps.
infected.rar (Size: 6.45 KB / Downloads: 34)
Code:
namespace Sharpshooter_Infected
{
using InfinityScript;
using System;
using System.Collections.Generic;
using System.Linq;
public class SharpshooterInfected : BaseScript
{
private string _currentWeapon;
private int _cycleRemaining;
private SharpshooterPerk[] _perkList;
private Random _rng;
private int _switchTime;
private List<string> _usedWeapons;
private Dictionary<string, string[]> _validAttachments;
private string[] _weaponList;
public SharpshooterInfected()
{
Func<bool> func = null;
Func<bool> func2 = null;
Action<Entity> action = null;
this._rng = new Random();
this._usedWeapons = new List<string>();
this._switchTime = base.Call<int>("getDvarInt", new Parameter[] { "shrp_switchTime", 30 });
this._cycleRemaining = this._switchTime;
SharpshooterPerk[] perkArray = new SharpshooterPerk[7];
SharpshooterPerk perk2 = new SharpshooterPerk {
perkName = "Sleight of Hand",
perks = new string[] { "specialty_fastreload", "specialty_quickswap" }
};
perkArray[0] = perk2;
SharpshooterPerk perk3 = new SharpshooterPerk {
perkName = "Quickdraw",
perks = new string[] { "specialty_quickdraw" }
};
perkArray[1] = perk3;
SharpshooterPerk perk4 = new SharpshooterPerk {
perkName = "Stalker",
perks = new string[] { "specialty_stalker" }
};
perkArray[2] = perk4;
SharpshooterPerk perk5 = new SharpshooterPerk {
perkName = "Marathon",
perks = new string[] { "specialty_longersprint", "specialty_fastmantle" }
};
perkArray[3] = perk5;
SharpshooterPerk perk6 = new SharpshooterPerk {
perkName = "Range",
perks = new string[] { "specialty_longerrange" },
isWeapon = true
};
perkArray[4] = perk6;
SharpshooterPerk perk7 = new SharpshooterPerk {
perkName = "Stability",
perks = new string[] { "specialty_reducedsway" },
isWeapon = true
};
perkArray[5] = perk7;
SharpshooterPerk perk8 = new SharpshooterPerk {
perkName = "Speed",
perks = new string[] { "specialty_lightweight" },
isWeapon = true
};
perkArray[6] = perk8;
this._perkList = perkArray;
foreach (SharpshooterPerk perk in this._perkList)
{
string str = perk.perks[0] + (perk.isWeapon ? "" : "_upgrade");
base.Call("precacheShader", new Parameter[] { str });
}
this.PrepareWeaponLists();
this._currentWeapon = this.GetRandomWeapon();
if (func == null)
{
func = delegate {
this._cycleRemaining--;
if (this._cycleRemaining == 0)
{
this._cycleRemaining = this._switchTime;
}
foreach (Entity entity in base.get_Players())
{
if (entity.HasField("bohud_created"))
{
entity.GetField<HudElem[]>("bohud_messageText")[0].SetText("Changing weapons in: " + this.FormatTime(this._cycleRemaining));
}
}
return true;
};
}
base.OnInterval(0x3e8, func);
if (func2 == null)
{
func2 = delegate {
Action<Entity> action = null;
this._currentWeapon = this.GetRandomWeapon();
this._cycleRemaining = this._switchTime;
foreach (Entity entity in base.get_Players())
{
if (entity.get_IsAlive() && (entity.GetField<string>("sessionteam") != "axis"))
{
entity.TakeAllWeapons();
entity.GiveWeapon(this._currentWeapon);
entity.Call("giveMaxAmmo", new Parameter[] { this._currentWeapon });
if (action == null)
{
action = entity => entity.SwitchToWeaponImmediate(this._currentWeapon);
}
entity.AfterDelay(100, action);
}
}
return true;
};
}
base.OnInterval(this._switchTime * 0x3e8, func2);
if (action == null)
{
action = delegate (Entity entity) {
this.createServerHud();
base.Call("setdvar", new Parameter[] { "motd", "" });
entity.OnNotify("joined_team", delegate (Entity player) {
entity.Call("closePopupMenu", new Parameter[0]);
entity.Call("closeIngameMenu", new Parameter[0]);
});
entity.OnInterval(250, delegate (Entity player) {
if (player.get_IsAlive() && (player.GetField<string>("sessionteam") != "axis"))
{
string str = player.get_CurrentWeapon();
string realWeaponName = this.GetRealWeaponName(this._currentWeapon);
if (!((!(str != "none") || !(str != "")) || str.Contains(realWeaponName)))
{
}
}
return true;
});
entity.OnInterval(0xdac, delegate (Entity player) {
if (player.get_IsAlive() && (player.GetField<string>("sessionteam") != "axis"))
{
string str = player.get_CurrentWeapon();
if (str.StartsWith("iw5_44magnum") || str.StartsWith("iw5_44magnum"))
{
player.Call("giveMaxAmmo", new Parameter[] { str });
}
}
return true;
});
entity.add_SpawnedPlayer(delegate {
if (entity.GetField<string>("sessionteam") == "axis")
{
this.createServerHud();
}
else
{
entity.TakeAllWeapons();
entity.Call("clearPerks", new Parameter[0]);
this.createServerHud();
entity.SetField("shrp_perkc", 0);
entity.SetField("shrp_perks", new Parameter(new string[3]));
entity.GiveWeapon(this._currentWeapon);
entity.Call("giveMaxAmmo", new Parameter[] { this._currentWeapon });
entity.AfterDelay(100, player => player.SwitchToWeaponImmediate(this._currentWeapon));
}
});
};
}
base.add_PlayerConnected(action);
}
private string AddRandomAttachmentToWeapon(string baseWeapon)
{
string[] source = this._validAttachments[baseWeapon];
if (source.Length == 0)
{
return Utilities.BuildWeaponName(baseWeapon, "none", "none", this._rng.Next(0, 14), this._rng.Next(0, 7));
}
bool flag = false;
string[] desiredAttachments = null;
while (!flag)
{
desiredAttachments = this.GetDesiredAttachments();
if (desiredAttachments.Length == 0)
{
return Utilities.BuildWeaponName(baseWeapon, "none", "none", this._rng.Next(0, 14), this._rng.Next(0, 7));
}
foreach (string str in desiredAttachments)
{
if (source.Contains<string>(str))
{
flag = true;
break;
}
}
}
string str2 = "none";
bool flag2 = false;
while (!flag2)
{
str2 = desiredAttachments[this._rng.Next(0, desiredAttachments.Length)];
if (source.Contains<string>(str2))
{
flag2 = true;
}
}
Log.Write(1, "weapon {0} with a {1}", new object[] { baseWeapon, str2 });
return Utilities.BuildWeaponName(baseWeapon, str2, "none", this._rng.Next(0, 14), this._rng.Next(0, 7));
}
private void createServerHud()
{
HudElem motd = HudElem.CreateServerFontString("boldFont", 1f);
motd.SetPoint("CENTER", "BOTTOM", 0, -19);
motd.set_Foreground(true);
motd.set_HideWhenInMenu(true);
base.OnInterval(0x61a8, delegate {
motd.SetText(this.Call<string>("getdvar", new Parameter[] { "motd" }));
motd.SetPoint("CENTER", "BOTTOM", 0x44c, -10);
motd.Call("moveovertime", new Parameter[] { 0x19 });
motd.set_X(-700f);
return true;
});
}
private string FormatTime(int seconds)
{
int num = seconds % 60;
return string.Format("{0}:{1}", seconds / 60, num.ToString().PadLeft(2, '0'));
}
private string[] GetDesiredAttachments()
{
string[] strArray = new string[] { "none", "sight", "sight", "sight", "sight", "sight", "other", "other", "other", "final" };
switch (strArray[this._rng.Next(0, strArray.Length)])
{
case "none":
return new string[0];
case "sight":
return new string[] { "acog", "reflex", "hamrhybrid", "hybrid", "zoomscope", "eotech", "vzscope" };
case "other":
return new string[] { "silencer", "silencer02", "silencer03", "grip", "gl", "gp25", "m320", "shotgun" };
case "final":
return new string[] { "thermal", "heartbeat" };
}
return new string[0];
}
private string GetRandomWeapon()
{
string item = (from w in this._weaponList
where !this._usedWeapons.Contains(w)
orderby this._rng.Next()
select w).FirstOrDefault<string>();
if (item == null)
{
this._usedWeapons.Clear();
item = this._weaponList[this._rng.Next(0, this._weaponList.Length)];
}
this._usedWeapons.Add(item);
return this.AddRandomAttachmentToWeapon(item);
}
private string GetRealWeaponName(string weapon)
{
string[] strArray = weapon.Split(new char[] { '_' });
if (strArray[0] == "iw5")
{
return strArray[1];
}
return strArray[0];
}
public override void OnPlayerKilled(Entity player, Entity inflictor, Entity attacker, int damage, string mod, string weapon, Vector3 dir, string hitLoc)
{
if (((attacker != player) && (attacker.GetField<string>("classname") == "player")) && attacker.get_IsAlive())
{
}
}
private void PrepareWeaponLists()
{
this._weaponList = new string[] {
"iw5_44magnum", "iw5_usp45", "iw5_deserteagle", "iw5_mp412", "iw5_p99", "iw5_fnfiveseven", "iw5_fmg9", "iw5_skorpion", "iw5_mp9", "iw5_g18", "iw5_mp5", "iw5_m9", "iw5_p90", "iw5_pp90m1", "iw5_ump45", "iw5_mp7",
"iw5_ak47", "iw5_m16", "iw5_m4", "iw5_fad", "iw5_acr", "iw5_type95", "iw5_mk14", "iw5_scar", "iw5_g36c", "iw5_cm901", "rpg", "iw5_smaw", "xm25", "iw5_dragunov", "iw5_msr", "iw5_barrett",
"iw5_rsass", "iw5_as50", "iw5_l96a1", "iw5_ksg", "iw5_1887", "iw5_striker", "iw5_aa12", "iw5_usas12", "iw5_spas12", "iw5_m60", "iw5_mk46", "iw5_pecheneg", "iw5_sa80", "iw5_mg36"
};
this._validAttachments = new Dictionary<string, string[]>();
foreach (string str in this._weaponList)
{
List<string> list = new List<string>();
for (int i = 11; i <= 0x15; i++)
{
string item = base.Call<string>("tableLookup", new Parameter[] { "mp/statstable.csv", 4, str, i });
if (item != "")
{
list.Add(item);
}
}
this._validAttachments.Add(str, list.ToArray());
}
}
private class SharpshooterPerk
{
public bool isWeapon;
public string perkName;
public string[] perks;
}
}
}
infected.rar (Size: 6.45 KB / Downloads: 34)