Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Add RList config for spawn locations
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonWizard committed Mar 15, 2019
1 parent d3c978c commit c7bd25c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tranqgun_firerate | Float | 3 | Time (in seconds) between each shot. Can be igno
tranqgun_magazine | Int | 1 | Amount of shots per magazine.
tranqgun_reserveammo | Int | 2 | Default reserve ammo for each player.
tranqgun_duration | Float | 5 | Time (in seconds) the target is tranquilized for.
tranqun_spawns | RList | 096chamber | RList of locations to spawn the gun. Valid locations are: 049chamber, 096chamber, 173armory, surfacenuke, nuke, bathrooms.

*Note that all configs should go in your server config file, not config_remoteadmin.txt

Expand Down
81 changes: 62 additions & 19 deletions TranquilizerGun/MiscEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,85 @@ public void OnSetConfig(SetConfigEvent ev)

public void OnRoundStart(RoundStartEvent ev)
{
foreach (RandomItemSpawner.PositionPosIdRelation item in UnityEngine.Object.FindObjectOfType<RandomItemSpawner>().posIds)
RandomItemSpawner ris = UnityEngine.Object.FindObjectOfType<RandomItemSpawner>();

List<SpawnLocation> spawns = new List<SpawnLocation>();
foreach (string slRaw in TranqGunPlugin.SpawnLocations)
{
if (item.posID == "Fireman")
string sl = slRaw.ToLower();
this.plugin.Info("Spawning tranquilizer gun at: " + sl);
List<SpawnLocation> choices = null;

if (sl == "049chamber")
{
this.plugin.Handler.CreateOfType(item.position.position, item.position.rotation);
break;
choices = ris
.posIds
.Where(x => x.posID == "049_Medkit")
.Select(x => new SpawnLocation(x.position.position, x.position.rotation))
.ToList();
}
}

foreach (string sl in TranqGunPlugin.SpawnLocations)
{
if (sl.ToLower() == "049chamber")
else if (sl == "096chamber")
{

choices = ris
.posIds
.Where(x => x.posID == "Fireman")
.Select(x => new SpawnLocation(x.position.position, x.position.rotation))
.ToList();
}
else if (sl.ToLower() == "173chamber")
else if (sl == "173armory")
{

choices = ris
.posIds
.Where(x => x.posID == "RandomPistol" && x.position.parent.parent.gameObject.name == "Root_173")
.Select(x => new SpawnLocation(x.position.position, x.position.rotation))
.ToList();
}
else if (sl.ToLower() == "surfacenuke")
else if (sl == "surfacenuke")
{

Transform t = GameObject.Find("SCPSLNukeRoom/Table01 (2)").transform;
choices = new List<SpawnLocation>() { new SpawnLocation(t.position + Vector3.up*2.5f, Quaternion.identity) };
}
else if (sl.ToLower() == "nuke")
else if (sl == "nuke")
{

choices = ris
.posIds
.Where(x => x.posID == "Nuke")
.Select(x => new SpawnLocation(x.position.position, x.position.rotation))
.ToList();
}
else if (sl.ToLower() == "bathrooms")
else if (sl == "bathrooms")
{

choices = ris
.posIds
.Where(x => x.posID == "toilet_keycard")
.Select(x => new SpawnLocation(x.position.position, x.position.rotation))
.ToList();
}
else

if (choices == null || choices.Count == 0)
{
this.plugin.Info("Invalid spawn location: " + sl);
return;
}

spawns.Add(choices[UnityEngine.Random.Range(0, choices.Count)]);
}

foreach (SpawnLocation sl in spawns)
{
this.plugin.Handler.CreateOfType(sl.position, sl.rotation);
}
}
}

public struct SpawnLocation
{
public Vector3 position { get; private set; }
public Quaternion rotation { get; private set; }
public SpawnLocation(Vector3 p, Quaternion r)
{
this.position = p;
this.rotation = r;
}
}
}
18 changes: 5 additions & 13 deletions TranquilizerGun/TranqGunPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace TranquilizerGun
name = "TranquilizerGun",
description = "Adds a tranquilizer gun with temporarily ragdolls players.",
id = "xyz.wizardlywonders.TranquilizerGun",
version = "1.0.1",
version = "1.1.0",
SmodMajor = 3,
SmodMinor = 3,
SmodRevision = 0
Expand All @@ -35,7 +35,7 @@ public class TranqGunPlugin : Plugin

public static float TranqDuration { get; private set; }

public static List<string> SpawnLocations = new List<string>();
public static List<string> SpawnLocations;

public override void OnDisable()
{
Expand All @@ -61,7 +61,7 @@ public override void Register()

this.AddConfig(new ConfigSetting("tranqgun_duration", 5f, SettingType.FLOAT, true, "Time (in seconds) the target is tranquilized for."));

this.AddConfig(new ConfigSetting("tranqgun_spawns", new string[] { "wheremyhotdogsat" }, true, SettingType.LIST, true, "Locations that the tranquilizer gun can spawn in."));
this.AddConfig(new ConfigSetting("tranqgun_spawns", new string[] { "096chamber" }, true, SettingType.LIST, true, "Locations that the tranquilizer gun can spawn in."));

// -- Register events
this.AddEventHandlers(new MiscEventHandler(this), Smod2.Events.Priority.Low);
Expand All @@ -70,8 +70,7 @@ public override void Register()
this.Handler = new CustomWeaponHandler<TranquilizerGun>(TranqGunPlugin.TranqID)
{
DefaultType = ItemType.USP,
AmmoName = "Tranquilizer Dart",
DefaultReserveAmmo = 2
AmmoName = "Tranquilizer Dart"
};
this.Handler.Register();
Items.AddRecipe(new Id914Recipe(KnobSetting.FINE, (int)ItemType.USP, TranqGunPlugin.TranqID, 1));
Expand All @@ -90,14 +89,7 @@ public void ReloadConfig()

TranqGunPlugin.TranqDuration = GetConfigFloat("tranqgun_duration");

List<string> spawns = new List<string>(GetConfigList("tranqgun_spawns"));
if (spawns.Count == 1 && spawns[0] == "wheremyhotdogsat")
{
// -- Random defaults {173chamber|surfacenuke|nuke}
List<string> hotdogDefault = new List<string> { "173chamber", "surfacenuke", "nuke" };
spawns = new List<string> { hotdogDefault[new Random().Next(0, hotdogDefault.Count)] };
}
TranqGunPlugin.SpawnLocations = spawns;
TranqGunPlugin.SpawnLocations = new List<string>(GetConfigList("tranqgun_spawns"));
}
}
}

0 comments on commit c7bd25c

Please sign in to comment.