Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HoldfastSharedMethods;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- //using System.Linq; -- this causes an error?????????? WTF
- using UnityEngine;
- using UnityEngine.UI;
- public class AutoAdmin : MonoBehaviour
- {
- public static InputField f1MenuInputField;
- public static float currentTime = -1;
- public static float FOL_TIME_CHECK_AMOUNT = 2; // seconds
- public static float DEFAULT_SAFE = 3;
- public static float DEFAULT_DAMEGE_RANGE = 8;
- public static float DEFAULT_DAMEGE_MOD = 1;
- public static float DEFAULT_OTHER_PLAYERS_NEEDED = 2;
- public static float DEFAULT_MAX_WARNING_DAMEGE = 33;
- public static string MESSAGE_PREFIT = "AUTOMOD: ";
- public static Dictionary<int, playerStruct> playerIdDictionary = new Dictionary<int, playerStruct>();
- public static Dictionary<int, joinStruct> playerJoinedDictionary = new Dictionary<int, joinStruct>();
- private static int PLAYER_LAYER = 11;
- // Class -> [safe zone, warning zone, damege mod,minimumotherPlayersNeeded,maxWarningDamege]
- public static Dictionary<PlayerClass, float[]> classInfomation = new Dictionary<PlayerClass, float[]>()
- {
- { PlayerClass.ArmyLineInfantry, new float[]{3,8,1,2,25} },
- { PlayerClass.NavalMarine, new float[]{3,8,1,2, 25 } },
- { PlayerClass.NavalCaptain, new float[]{3,8,1,2, 25 } },
- { PlayerClass.NavalSailor, new float[]{3,8,1,2, 25 } },
- { PlayerClass.NavalSailor2, new float[]{3,8,1,2, 25 } },
- { PlayerClass.ArmyInfantryOfficer, new float[]{3,8,1,2, 25 } },
- { PlayerClass.CoastGuard, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Carpenter, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Surgeon, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Rifleman, new float[]{3,8,1, 2, 25 } },
- { PlayerClass.LightInfantry, new float[]{3,8,1, 2, 25 } },
- { PlayerClass.FlagBearer, new float[]{3,8,1, 2, 25 } },
- { PlayerClass.Customs, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Drummer, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Fifer, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Guard, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Violinist, new float[]{3,8,1, 2, 25 } },
- { PlayerClass.Grenadier, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Bagpiper, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Cannoneer, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Rocketeer, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Sapper, new float[]{3,8,1,2, 25 } },
- { PlayerClass.Hussar, new float[]{3,8,1,2, 25 } },
- { PlayerClass.CuirassierDragoon, new float[]{3,8,1, 2, 25 } }
- };
- //METHODS
- public static void TextCommandController(int playerId, TextChatChannel channel, string text)
- {
- if (channel != TextChatChannel.Admin) { return; }
- string[] temp = text.Split(' ');
- switch(temp[0])
- {
- case "ac":
- if (temp.Length != 2) { break; }
- allCharge(temp[1]);
- break;
- default:
- break;
- }
- }
- private static void allCharge(string v)
- {
- broadcast("enumerator method");
- float timer;
- if (float.TryParse(v, out timer))
- {
- broadcast(timer.ToString());
- if (timer >= 0)
- {
- broadcast("current time: " + currentTime);
- float timeForAC = currentTime - timer;
- float minutes = Mathf.Floor(timeForAC / 60); //could also use int division
- float seconds = timeForAC - 60 * minutes; //could also use mod.
- var message = MESSAGE_PREFIT + " All charge at " + minutes + ":" + seconds;
- broadcast(message);
- var acCommand = MESSAGE_PREFIT + " All charge - Cav dismount;set allowFiring false";
- var temp = new allCharge(timer, acCommand);
- //broadcast(acCommand);
- }
- }
- }
- public static void PlayerJoined(int playerId, ulong steamId, string name, string regimentTag, bool isBot)
- {
- joinStruct temp = new joinStruct()
- {
- _steamId = steamId,
- _name = name,
- _regimentTag = regimentTag,
- _isBot = isBot
- };
- playerJoinedDictionary.Add(playerId, temp);
- }
- public static void PlayerLeft(int playerId)
- {
- playerJoinedDictionary.Remove(playerId);
- playerIdDictionary.Remove(playerId);
- }
- public static void playerSpawned(int playerId, FactionCountry playerFaction, PlayerClass playerClass, int uniformId, GameObject playerObject)
- {
- playerStruct temp = new playerStruct()
- {
- _playerFaction = playerFaction,
- _playerClass = playerClass,
- _uniformId = uniformId,
- _playerObject = playerObject
- };
- //check that its not already on dictionary -- danger is death evaders -- tut tut
- if (playerIdDictionary.ContainsKey(playerId))
- {
- playerIdDictionary[playerId] = temp;
- return;
- }
- playerIdDictionary.Add(playerId, temp);
- }
- public static void main_FOL(int playerId, bool dryShot)
- {
- if (dryShot) { return; }
- PlayerClass pClass = playerIdDictionary[playerId]._playerClass;
- var sZone = classInfomation[pClass][0];
- var dZone = classInfomation[pClass][1];
- var damegeMod = classInfomation[pClass][2];
- int playersNeeded = (int)classInfomation[pClass][3];
- int maxWarningDamege = (int)classInfomation[pClass][4];
- FOL_Detector(playerId, sZone, dZone, damegeMod, playersNeeded, maxWarningDamege);
- }
- public static void playerKilled(int killerPlayerId, int victimPlayerId, EntityHealthChangedReason reason, string additionalDetails)
- {
- if (reason != EntityHealthChangedReason.ShotByFirearm) { return; }
- //this should never run, but just incase
- if (!playerIdDictionary.ContainsKey(killerPlayerId)) { return; }
- float maxTimeDiffrence = 2;
- //was it an FOL?
- var killerInfo = playerIdDictionary[killerPlayerId].shotInfo;
- broadcast("current time: " + currentTime + " , FOL time: " + killerInfo._timeRemaining);
- if (killerInfo._timeRemaining == 0) { return; }
- if (killerInfo._timeRemaining - currentTime > maxTimeDiffrence || killerInfo._timeRemaining == 0) { return; }
- // if so slay and revive player.
- string msgReason = MESSAGE_PREFIT + "You fired : " + killerInfo._distance + "m out of line. Make sure to be shoulder to shoulder when firing.";
- slayPlayer(killerPlayerId, msgReason);
- revivePlayer(victimPlayerId, "Killed by an FOL");
- }
- private static void revivePlayer(int playerID, string reason)
- {
- if (f1MenuInputField == null) { return; }
- var rcCommand = string.Format("serverAdmin revive {0}", playerID, reason);
- f1MenuInputField.onEndEdit.Invoke(rcCommand);
- }
- public static void FOL_Detector(int playerId, float safe_zone, float max_warning_distance,float damege_mod,int numberOfPlayersNeeded,int maxWarningDamege)
- {
- if (numberOfPlayersNeeded <= 0 || damege_mod == 0) { return; }
- float playersInSafeZone = 0;
- float playersInDamegeZone = 0;
- float closestD = float.MaxValue;
- Vector3 playerPos = playerIdDictionary[playerId]._playerObject.transform.position;
- Collider[] hitColliders = Physics.OverlapSphere(playerPos, max_warning_distance,1 << PLAYER_LAYER); // when using layer mask , this returns empty. Weird.
- foreach (var hitCollider in hitColliders)
- {
- //if (hitCollider.gameObject.layer != PLAYER_LAYER) { continue; }
- broadcast(hitCollider.gameObject.name);
- float dist = Vector3.Distance(hitCollider.gameObject.transform.position, playerIdDictionary[playerId]._playerObject.transform.position);
- broadcast("distance: " + dist + " safezone dist: " + safe_zone + " , warning dist: " + max_warning_distance);
- if (dist < safe_zone && dist != 0)
- {
- playersInSafeZone += 1;
- }
- //if (dist >= safe_zone && dist < max_warning_distance)
- if (dist >= safe_zone)
- {
- playersInDamegeZone += 1;
- if (dist < closestD)
- {
- closestD = dist;
- }
- }
- }
- if (playersInSafeZone >= numberOfPlayersNeeded) { return; } //will always interact with themself
- string reason;
- int damege;
- if (playersInSafeZone + playersInDamegeZone >= numberOfPlayersNeeded)
- {
- //apply damege scaling
- reason = MESSAGE_PREFIT + "You fired : " + closestD + "m out of line. Make sure to be shoulder to shoulder when firing.";
- damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
- updateShotInfomation(playerId, closestD);
- slapPlayer(playerId, damege, reason);
- return;
- }
- //apply max damege
- reason = MESSAGE_PREFIT + "You fired without " +numberOfPlayersNeeded + " players within a radius of " +max_warning_distance+ "m. Make sure to be shoulder to shoulder with atleast " + numberOfPlayersNeeded + " other players before firing.";
- damege = (int)Mathf.Floor(damege_mod * maxWarningDamege);
- updateShotInfomation(playerId, closestD);
- slapPlayer(playerId, damege, reason);
- return;
- #region Old system
- /*
- if (playersInSafeZone + playersInDamegeZone >= numberOfPlayersNeeded)
- {
- string reason = "You fired : " + closestD + "m out of line. Make sure to be shoulder to shoulder when firing.";
- int damege;
- if (numberOfPlayersNeeded == 0)
- {
- damege = (int)Mathf.Floor(damege_mod * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
- }
- else
- {
- damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(maxWarningDamege / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
- }
- slapPlayer(playerId, damege, reason);
- updateShotInfomation(playerId, closestD);
- return;
- }
- //Apply max damege
- //kill
- string slayReason = "you fired beyond the slap zone thus max slap damege applied. Make sure to be shouldered when firing";
- updateShotInfomation(playerId, closestD);
- slapPlayer(playerId,(int)Mathf.Floor(damege_mod * maxWarningDamege) , slayReason);
- */
- #endregion
- }
- private static void updateShotInfomation(int playerID, float distance)
- {
- shotStruct temp = new shotStruct()
- {
- _timeRemaining = currentTime,
- _distance = distance
- };
- var change = playerIdDictionary[playerID];
- change.shotInfo = temp;
- playerIdDictionary[playerID] = change;
- }
- private static void slayPlayer(int playerID, string reason)
- {
- if (f1MenuInputField == null) { return; }
- var rcCommand = string.Format("serverAdmin slay {0} {1}", playerID, reason);
- f1MenuInputField.onEndEdit.Invoke(rcCommand);
- }
- private static void slapPlayer(int playerID, int damege, string reason)
- {
- if (f1MenuInputField == null) { return; }
- var rcCommand = string.Format("serverAdmin slap {0} {1} {2}", playerID, damege, reason);
- f1MenuInputField.onEndEdit.Invoke(rcCommand);
- }
- public static void broadcast(string message)
- {
- if (f1MenuInputField == null) { return; }
- f1MenuInputField.onEndEdit.Invoke("broadcast "+message);
- }
- public static bool CustomContains(string[] array, string obj)
- {
- foreach(var e in array)
- {
- if (e==obj)
- {
- return true;
- }
- }
- return false;
- }
- public static void PassConfigVariables(string[] value)
- {
- string modID = "2531692643";
- int numberOfVariables = 5;
- for (int i = 0; i < value.Length; i++)
- {
- var splitData = value[i].Split(':');
- if (splitData.Length != 3)
- {
- Debug.LogError("invalid number of variables");
- continue;
- }
- //so first variable should be the mod id
- if (splitData[0] == modID)
- {
- //Debug.Log("correect mod ID");
- string[] classTypes = System.Enum.GetNames(typeof(PlayerClass));
- if (!AutoAdmin.CustomContains(classTypes, splitData[1])) { continue; }
- PlayerClass variableClass = (PlayerClass)System.Enum.Parse(typeof(PlayerClass), splitData[1]);
- var variableSplit = splitData[2].Split(',');
- //should have 4 data parameters
- if (variableSplit.Length != numberOfVariables) { continue; }
- float safe = AutoAdmin.DEFAULT_SAFE;
- float range = AutoAdmin.DEFAULT_DAMEGE_RANGE;
- float damegeMod = AutoAdmin.DEFAULT_DAMEGE_MOD;
- float numberOfPlayers = AutoAdmin.DEFAULT_OTHER_PLAYERS_NEEDED;
- float maxWarningDamege = AutoAdmin.DEFAULT_MAX_WARNING_DAMEGE;
- float safe_temp;
- float range_temp;
- float damegeMod_temp;
- float numberOfPlayers_temp;
- float maxWarningDamege_temp;
- if (float.TryParse(variableSplit[0], out safe_temp))
- {
- if (safe_temp > 0)
- {
- //Debug.Log("safe: " + safe_temp);
- safe = safe_temp;
- }
- }
- if (float.TryParse(variableSplit[1], out range_temp))
- {
- if (range_temp > safe)
- {
- //Debug.Log("range: " + range_temp);
- range = range_temp;
- }
- }
- if (float.TryParse(variableSplit[2], out damegeMod_temp))
- {
- if (damegeMod_temp >= 0)
- {
- //Debug.Log("damegeMod: " + damegeMod_temp);
- damegeMod = damegeMod_temp;
- }
- }
- if (float.TryParse(variableSplit[3], out numberOfPlayers_temp))
- {
- if (numberOfPlayers_temp >= 0)
- {
- //Debug.Log("numPlayers: " + numberOfPlayers_temp);
- numberOfPlayers = numberOfPlayers_temp;
- }
- }
- if (float.TryParse(variableSplit[4], out maxWarningDamege_temp))
- {
- if (maxWarningDamege_temp >= 0)
- {
- //Debug.Log("maxDMG: " + maxWarningDamege_temp);
- maxWarningDamege = maxWarningDamege_temp;
- }
- }
- AutoAdmin.classInfomation[variableClass] = new float[] { safe, range, damegeMod, numberOfPlayers, maxWarningDamege };
- //Debug.Log("done");
- }
- }
- }
- public struct playerStruct
- {
- public FactionCountry _playerFaction;
- public PlayerClass _playerClass;
- public int _uniformId;
- public GameObject _playerObject;
- public shotStruct shotInfo;
- }
- public struct shotStruct
- {
- public float _timeRemaining;
- public float _distance;
- }
- public struct joinStruct
- {
- public ulong _steamId;
- public string _name;
- public string _regimentTag;
- public bool _isBot;
- }
- }
Add Comment
Please, Sign In to add comment