void Update() { MoveX = Input.GetAxisRaw("Horizontal") * speed; InputX = Input.GetAxisRaw("Horizontal"); MoveZ = Input.GetAxisRaw("Vertical") * speed; Vector3 direction = new Vector3(MoveX, 0, MoveZ); timeCount += 1; //移動制限 transform.localPosition = PlayerLimit.ClampPosition(transform.localPosition); if (Input.GetKey(KeyCode.D) || InputX >= 0.8) { //Debug.Log("D"); zRotate = Mathf.Clamp(zRotate - adRotate * Time.frameCount, -40, 40); transform.eulerAngles = new Vector3(0, 0, zRotate); } else if (Input.GetKey(KeyCode.A) || InputX <= -0.8) { //Debug.Log("A"); zRotate = Mathf.Clamp(zRotate + adRotate * Time.frameCount, -40, 40); transform.eulerAngles = new Vector3(0, 0, zRotate); } else { zRotate = Mathf.Clamp(0, 0, 0); transform.eulerAngles = new Vector3(0, 0, zRotate); } }
void OnEntitySpawned(BaseNetworkable entity) { if (entity == null) { return; } if (!entity is BaseEntity) { return; } BaseEntity ent = (BaseEntity)entity; BasePlayer player = BasePlayer.FindByID(ent.OwnerID); if (ent == null || player == null) { return; } if (Cfg.MaxLimits.Any(x => x.Key == entity.ShortPrefabName)) { if (!data.Limits.Any(x => x.Id == player.userID)) { PlayerLimit.Create(player, ent); } else { PlayerLimit.Modify(player, ent); } } }
public static void Modify(BasePlayer player, BaseEntity entity) { if (data.Limits.Any(x => x.Id == player.userID)) { PlayerLimit info = data.Limits.Find(x => x.Id == player.userID) ?? null; if (!info.limit.Any(x => x.Name == entity.ShortPrefabName)) { info.limit.Add(new Entities() { Count = 1, Name = entity.ShortPrefabName }); } else { Entities playerEnt = info.limit.Find(x => x.Name == entity.ShortPrefabName) ?? null; if (Cfg.MaxLimits.Any(x => x.Key == playerEnt.Name)) { if (playerEnt.Count == Cfg.MaxLimits[playerEnt.Name]) { player.ChatMessage(LangMsg("MAX_ENTITIES")); var item = ItemManager.CreateByName(entity.ShortPrefabName.Replace("_", "."), 1); if (entity.ShortPrefabName.Contains("sleeping")) { item = ItemManager.CreateByName("sleepingbag"); } if (entity.ShortPrefabName == "small_stash_deployed") { item = ItemManager.CreateByName("stash.small"); } player.inventory.GiveItem(item, player.inventory.containerBelt); player.Command(string.Concat(new object[4] { (object)"note.inv ", (object)item.info.itemid, (object)" ", (object)"1" })); //player.Command("note.inv", (object)item.info.itemid, (object)item.amount, (object)item.name.); entity.KillMessage(); return; } playerEnt.Count += 1; return; } } } }
void EntityDestroyed(BaseEntity entity) { if (entity == null) { return; } if (Cfg.MaxLimits.Any(x => x.Key == entity.ShortPrefabName)) { PlayerLimit info = data.Limits.Find(x => x.Id == entity.OwnerID) ?? null; Entities PlayerEnts = info.limit.Find(x => x.Name == entity.ShortPrefabName) ?? null; if (info == null || PlayerEnts == null || PlayerEnts.Count == 0) { return; } PlayerEnts.Count -= 1; } }
void cmdWipe(BasePlayer player, string cmd, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "entitylimit.admin")) { player.ChatMessage(LangMsg("NO_PERMISSION", player.UserIDString)); return; } if (args.Length == 0) { player.ChatMessage(LangMsg("CMD_WIPE_SYNTAX", player.UserIDString)); return; } if (args[0] == "all") { data.Limits.Clear(); SaveData(); player.ChatMessage(LangMsg("REMOVED_ALL_LIMITS", player.UserIDString)); } else { BasePlayer target = BasePlayer.Find(args[0]); if (target == null) { player.ChatMessage(LangMsg("PLAYER_NOT_FOUND", player.UserIDString)); return; } PlayerLimit info = data.Limits.Find(x => x.Id == target.userID); if (info == null) { player.ChatMessage("This player doesn't have any saved entities"); return; } data.Limits.Remove(info); player.ChatMessage(string.Format(LangMsg("REMOVED_LIMITS_PLAYER", player.UserIDString), target.displayName)); SaveData(); } }