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 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 Dictionary<int, playerStruct> playerIdDictionary = new Dictionary<int, playerStruct>();
- // Class -> [safe zone, warning zone, damege mod,minimumotherPlayersNeeded]
- public static Dictionary<PlayerClass, float[]> classInfomation = new Dictionary<PlayerClass, float[]>()
- {
- { PlayerClass.ArmyLineInfantry, new float[]{3,8,1,2} },
- { PlayerClass.NavalMarine, new float[]{3,8,1,2} },
- { PlayerClass.NavalCaptain, new float[]{3,8,1,2} },
- { PlayerClass.NavalSailor, new float[]{3,8,1,2} },
- { PlayerClass.NavalSailor2, new float[]{3,8,1,2} },
- { PlayerClass.ArmyInfantryOfficer, new float[]{3,8,1,2} },
- { PlayerClass.CoastGuard, new float[]{3,8,1,2} },
- { PlayerClass.Carpenter, new float[]{3,8,1,2} },
- { PlayerClass.Surgeon, new float[]{3,8,1,2} },
- { PlayerClass.Rifleman, new float[]{3,8,1, 2} },
- { PlayerClass.LightInfantry, new float[]{3,8,1, 2} },
- { PlayerClass.FlagBearer, new float[]{3,8,1, 2} },
- { PlayerClass.Customs, new float[]{3,8,1,2} },
- { PlayerClass.Drummer, new float[]{3,8,1,2} },
- { PlayerClass.Fifer, new float[]{3,8,1,2} },
- { PlayerClass.Guard, new float[]{3,8,1,2} },
- { PlayerClass.Violinist, new float[]{3,8,1, 2} },
- { PlayerClass.Grenadier, new float[]{3,8,1,2} },
- { PlayerClass.Bagpiper, new float[]{3,8,1,2} },
- { PlayerClass.Cannoneer, new float[]{3,8,1,2} },
- { PlayerClass.Rocketeer, new float[]{3,8,1,2} },
- { PlayerClass.Sapper, new float[]{3,8,1,2} },
- { PlayerClass.Hussar, new float[]{3,8,1,2} },
- { PlayerClass.CuirassierDragoon, new float[]{3,8,1, 2 } }
- };
- //METHODS
- public static void playerSpawned(int playerId, FactionCountry playerFaction, PlayerClass playerClass, int uniformId, GameObject playerObject, ulong steamId, string playerName)
- {
- playerStruct temp = new playerStruct()
- {
- _playerFaction = playerFaction,
- _playerClass = playerClass,
- _uniformId = uniformId,
- _playerObject = playerObject,
- _steamId = steamId,
- _playerName = playerName
- };
- //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];
- FOL_Detector(playerId, sZone, dZone, damegeMod, playersNeeded);
- }
- public static void FOL_Detector(int playerId, float safe_zone, float max_warning_distance,float damege_mod,int numberOfPlayersNeeded)
- {
- 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);
- foreach (var hitCollider in hitColliders)
- {
- if (hitCollider.gameObject.layer == 11) //player layer
- {
- float dist = Vector3.Distance(hitCollider.gameObject.transform.position, playerIdDictionary[playerId]._playerObject.transform.position);
- 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
- 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(100 / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
- }
- else
- {
- damege = (int)Mathf.Floor(damege_mod * (1 - playersInSafeZone / numberOfPlayersNeeded) * Mathf.Max(100 / (max_warning_distance - safe_zone) * (closestD - safe_zone), 0));
- }
- slapPlayer(playerId, damege, reason);
- return;
- }
- //kill
- string slayReason = "you fired beyond the slap zone thus slain. Make sure to be shouldered when firing";
- slayPlayer(playerId, slayReason);
- //AutoAdmin.f1MenuInputField.onEndEdit.Invoke("function ended");
- }
- 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 struct playerStruct
- {
- public FactionCountry _playerFaction;
- public PlayerClass _playerClass;
- public int _uniformId;
- public GameObject _playerObject;
- public ulong _steamId;
- public string _playerName;
- }
- }
Add Comment
Please, Sign In to add comment