public override void Execute(CommandQueue queue, CommandEntry entry) { bool enable = BooleanTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal; EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.UFM_AIDisabled = !enable; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "AI for a zombie " + (enable ? "enabled!" : "disabled!")); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.UFM_AIDisabled = !enable; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "AI for an animal " + (enable ? "enabled!" : "disabled!")); } return; } queue.HandleError(entry, "That entity doesn't have AI!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { player.Internal.player.gameObject.AddComponent<LaunchComponent>().LaunchPlayer(loc.ToVector3()); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully launched player " + TagParser.Escape(player.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.gameObject.AddComponent<LaunchComponent>().Launch(loc.ToVector3()); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully launched zombie " + TagParser.Escape(zombie.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.gameObject.AddComponent<LaunchComponent>().Launch(loc.ToVector3()); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully launched animal " + TagParser.Escape(animal.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ItemEntityTag item; if (entity.TryGetItem(out item)) { // TODO: Find some way to teleport items, barricades, etc without voiding the InstanceID? } queue.HandleError(entry, "That entity can't be launched!"); } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to launch entity: " + ex.ToString()); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1)); if (item == null) { queue.HandleError(entry, "Invalid item!"); return; } byte amount = 1; if (entry.Arguments.Count > 2) { amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2)); } if (ItemTool.tryForceGiveItem(player.Internal.player, item.Internal.id, amount)) { if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully gave a " + TagParser.Escape(item.Internal.name) + "!"); } } else { queue.HandleError(entry, "Failed to give item (is the inventory full?)!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { TemplateObject cb = entry.GetArgumentObject(queue, 0); if (cb.ToString() == "\0CALLBACK") { return; } if (entry.InnerCommandBlock == null) { queue.HandleError(entry, "Invalid or missing command block!"); return; } ListTag mode = ListTag.For(cb); List<ItemStack> items = new List<ItemStack>(); for (int i = 1; i < entry.Arguments.Count; i++) { ItemTag required = ItemTag.For(TheServer, entry.GetArgumentObject(queue, i)); if (required == null) { queue.HandleError(entry, "Invalid required item!"); return; } items.Add(required.Internal); } TheServer.Recipes.AddRecipe(RecipeRegistry.ModeFor(mode), entry.InnerCommandBlock, entry.BlockStart, items.ToArray()); queue.CurrentEntry.Index = entry.BlockEnd + 2; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Added recipe!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { ListTag players = ListTag.For(entry.GetArgument(queue, 0)); TemplateObject tcolor = entry.GetArgumentObject(queue, 1); ColorTag color = ColorTag.For(tcolor); if (color == null) { queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString())); return; } string tchatter = entry.GetArgument(queue, 2); PlayerTag chatter = PlayerTag.For(tchatter); if (chatter == null) { queue.HandleError(entry, "Invalid chatting player: " + TagParser.Escape(tchatter)); return; } string message = entry.GetArgument(queue, 3); foreach (TemplateObject tplayer in players.ListEntries) { PlayerTag player = PlayerTag.For(tplayer.ToString()); if (player == null) { queue.HandleError(entry, "Invalid player: " + TagParser.Escape(tplayer.ToString())); continue; } ChatManager.manager.channel.send("tellChat", player.Internal.playerID.steamID, ESteamPacket.UPDATE_UNRELIABLE_BUFFER, chatter.Internal.playerID.steamID, (byte)0 /* TODO: Configurable mode? */, color.Internal, message); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully sent a message."); } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } player.Internal.player.life.askWarm((uint)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully adjusted the warmth level of a player!"); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to adjust player's warmth level: " + ex.ToString()); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { IntegerTag itag = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)); uint ti = (uint)itag.Internal; SDG.Unturned.LightingManager.time = ti; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "World time set to " + ti + "!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal <= 0) { queue.HandleError(entry, "Must provide a number that is greater than 0!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { Zombie inZomb = zombie.Internal; inZomb.maxHealth = (ushort)num.Internal; if (inZomb.health > inZomb.maxHealth) { inZomb.health = inZomb.maxHealth; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully set health of a zombie to " + inZomb.maxHealth + "!"); } return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { GameObject playerObj = player.Internal.player.gameObject; UFMHealthController controller = playerObj.GetComponent<UFMHealthController>(); if (controller == null) { controller = playerObj.AddComponent<UFMHealthController>(); } controller.maxHealth = (uint)num.Internal; PlayerLife life = player.Internal.player.life; byte curr = life.health; controller.health = curr >= controller.maxHealth ? controller.maxHealth : curr; life._health = controller.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully set max health of a player to " + controller.maxHealth + "!"); } return; } queue.HandleError(entry, "That entity can't be healed!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.target.position = loc.ToVector3(); zombie.Internal.seeker.canMove = true; zombie.Internal.seeker.canSearch = true; zombie.Internal.path = EZombiePath.RUSH; // TODO: Option for this? if (!zombie.Internal.isTicking) { zombie.Internal.isTicking = true; ZombieManager.tickingZombies.Add(zombie.Internal); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully started a zombie walking to " + TagParser.Escape(loc.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.target = loc.ToVector3(); if (!animal.Internal.isTicking) { animal.Internal.isTicking = true; AnimalManager.tickingAnimals.Add(animal.Internal); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully started an animal walking to " + TagParser.Escape(loc.ToString()) + "!"); } return; } queue.HandleError(entry, "That entity can't be made to walk!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } string targetAssetType = entry.GetArgument(queue, 0).ToLower(); EffectAssetTag effectType = EffectAssetTag.For(targetAssetType); if (effectType == null) { queue.HandleError(entry, "Invalid effect type!"); return; } EffectManager.sendEffect(effectType.Internal.id, EffectManager.INSANE, loc.ToVector3()); // TODO: radius option instead of always 512 units (INSANE)! if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Played effect " + TagParser.Escape(effectType.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } int amount = (int)num.Internal; PlayerLife life = player.Internal.player.life; if (amount >= 0) { life.askBreath((byte)amount); } else { life.askSuffocate((byte)-amount); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully adjusted the oxygen level of a player!"); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to adjust player's oxygen level: " + ex.ToString()); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } int amount = (int)num.Internal; PlayerLife life = player.Internal.player.life; if (amount >= 0) { life.askEat((byte)amount); } else { life.askStarve((byte)-amount); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully adjusted the food level of a player!"); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to adjust player's food level: " + ex.ToString()); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } EPlayerKill kill; // for use with "out EPlayerKill" parameters PlayerTag player; if (entity.TryGetPlayer(out player)) { PlayerLife life = player.Internal.player.life; life.askDamage(life.health, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { while (!zombie.Internal.isDead) { zombie.Internal.askDamage((byte)zombie.Internal.health, Vector3.zero, out kill); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed a zombie!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { while (!animal.Internal.isDead) { animal.Internal.askDamage((byte)animal.Internal.health, Vector3.zero, out kill); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed an animal!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager? barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a barricade!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { // TODO: Use ResourceManager? resource.Internal.askDamage(resource.Internal.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a resource!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { // TODO: Use StructureManager? structure.InternalData.structure.askDamage(structure.InternalData.structure.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a structure!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askDamage(vehicle.Internal.health, false); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a vehicle!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal < 0) { queue.HandleError(entry, "Must provide a non-negative number!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { UFMHealthController healthController = player.Internal.player.gameObject.GetComponent <UFMHealthController>(); uint amount = (uint)num.Internal; if (healthController != null) { healthController.Heal(amount); amount = (uint)(((double)amount / healthController.maxHealth) * 100.0); } PlayerLife life = player.Internal.player.life; life._health = healthController.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); if (entry.ShouldShowGood(queue)) { uint finalHealth = healthController != null ? healthController.health : life.health; entry.Good(queue, "Successfully healed a player to a new health value of " + finalHealth + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { Zombie inZomb = zombie.Internal; inZomb.health += (ushort)num.Internal; if (inZomb.health > inZomb.maxHealth) { inZomb.health = inZomb.maxHealth; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a zombie to a new health value of " + inZomb.health + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { Animal inAnimal = animal.Internal; inAnimal.health += (ushort)num.Internal; if (inAnimal.health > inAnimal.asset.health) { inAnimal.health = inAnimal.asset.health; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed an animal to a new health value of " + inAnimal.health + "!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { Barricade inBarricade = barricade.InternalData.barricade; inBarricade.health += (ushort)num.Internal; ushort max = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, inBarricade.id)).health; if (inBarricade.health > max) { inBarricade.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a barricade to a new health value of " + inBarricade.health + "!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { ResourceSpawnpoint inResource = resource.Internal; inResource.health += (ushort)num.Internal; ushort max = ((ResourceAsset)Assets.find(EAssetType.RESOURCE, inResource.id)).health; if (inResource.health > max) { inResource.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a resource to a new health value of " + inResource.health + "!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { Structure inStructure = structure.InternalData.structure; inStructure.health += (ushort)num.Internal; ushort max = ((ItemStructureAsset)Assets.find(EAssetType.ITEM, inStructure.id)).health; if (inStructure.health > max) { inStructure.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a structure to a new health value of " + inStructure.health + "!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askRepair((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a vehicle to a new health value of " + vehicle.Internal.health + "!"); } return; } queue.HandleError(entry, "That entity can't be healed!"); } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, ("Failed to heal entity: " + ex.ToString())); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal < 0) { queue.HandleError(entry, "Must provide a non-negative number!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } EPlayerKill kill; // for use with "out EPlayerKill" parameters PlayerTag player; if (entity.TryGetPlayer(out player)) { PlayerLife life = player.Internal.player.life; UFMHealthController healthController = player.Internal.player.GetComponent <UFMHealthController>(); uint health = healthController != null ? healthController.health : life.health; if (num.Internal >= health) { uint amount = (uint)num.Internal; if (healthController != null) { healthController.health = 0; } if (amount >= byte.MaxValue) // TODO: better handling { life._health = 0; amount = 1; } life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null); } else { uint amount = (uint)num.Internal; if (healthController != null) { healthController.Damage((uint)num.Internal); } life._health = healthController.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { uint xp; zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { uint xp; animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager? barricade.InternalData.barricade.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { // TODO: Use ResourceManager? resource.Internal.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { // TODO: Use StructureManager? structure.InternalData.structure.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askDamage((ushort)num.Internal, false); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to damage entity: " + ex.ToString()); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { TemplateObject spawned = null; LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } string targetAssetType = entry.GetArgument(queue, 0).ToLowerFast(); EntityType etype = EntityType.ValueOf(targetAssetType); if (etype == null) { queue.HandleError(entry, "Invalid entity type!"); return; } if (etype.Type == EntityAssetType.ZOMBIE) { Vector3 vec3 = loc.ToVector3(); byte reg = 0; // TODO: Optionally specifiable float closest = float.MaxValue; for (int r = 0; r < LevelZombies.zombies.Length; r++) { for (int i = 0; i < LevelZombies.zombies[r].Count; i++) { float dist = (LevelZombies.zombies[r][i].point - vec3).sqrMagnitude; if (dist < closest) { closest = dist; reg = (byte)r; } } } ZombieManager.manager.addZombie(reg, 0, 0, 0, 0, 0, 0, 0, 0, vec3, 0, false); Zombie zombie = ZombieManager.regions[reg].zombies[ZombieManager.regions[reg].zombies.Count - 1]; // TODO: Make this actually work! (See complaints file!) /* foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) { ZombieManager.manager.channel.openWrite(); ZombieManager.manager.channel.write(reg); ZombieManager.manager.channel.write((ushort)1); ZombieManager.manager.channel.write(new object[] { zombie.type, (byte)zombie.speciality, zombie.shirt, zombie.pants, zombie.hat, zombie.gear, zombie.move, zombie.idle, zombie.transform.position, MeasurementTool.angleToByte(zombie.transform.rotation.eulerAngles.y), zombie.isDead }); ZombieManager.manager.channel.closeWrite("tellZombies", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); } */ if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a zombie at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); } spawned = new ZombieTag(zombie); } else if (etype.Type == EntityAssetType.ANIMAL) { AnimalAssetTag asset = AnimalAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid animal type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO AnimalManager.manager.addAnimal(asset.Internal.id, loc.ToVector3(), 0, false); Animal animal = AnimalManager.animals[AnimalManager.animals.Count - 1]; foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) { AnimalManager.manager.channel.openWrite(); AnimalManager.manager.channel.write((ushort)1); AnimalManager.manager.channel.write(new object[] { animal.id, animal.transform.position, MeasurementTool.angleToByte(animal.transform.rotation.eulerAngles.y), animal.isDead }); AnimalManager.manager.channel.closeWrite("tellAnimals", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (" + animal.gameObject.GetInstanceID() + ")"); } spawned = new AnimalTag(animal); } else if (etype.Type == EntityAssetType.VEHICLE) { VehicleAssetTag asset = VehicleAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid vehicle type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO VehicleManager.spawnVehicle(asset.Internal.id, loc.ToVector3(), Quaternion.identity); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the vehicle entity! } else if (etype.Type == EntityAssetType.WORLD_OBJECT) { WorldObjectAssetTag asset = WorldObjectAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid world object type!"); return; } LevelObjects.addObject(loc.ToVector3(), Quaternion.identity, asset.Internal.id); // TODO: Network! entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) +"! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); // TODO: Get the world entity! } else if (etype.Type == EntityAssetType.ITEM) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid item type!"); return; } byte x; byte y; if (Regions.tryGetCoordinate(loc.ToVector3(), out x, out y)) { Item item = new Item(asset.Internal.id, 1, asset.Internal.quality); ItemData data = new ItemData(item, ++ItemManager.instanceCount, loc.ToVector3(), Dedicator.isDedicated); ItemManager.regions[x, y].items.Add(data); ItemModelTracker.Track(data, loc.ToVector3()); ItemManager.manager.channel.send("tellItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, item.id, item.amount, item.quality, item.state, loc.ToVector3() }); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the item entity! } else { queue.HandleError(entry, "Trying to spawn item outside any valid item regions!"); } } else if (etype.Type == EntityAssetType.BARRICADE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("barricade_".Length)); if (asset == null || !(asset.Internal is ItemBarricadeAsset)) { queue.HandleError(entry, "Invalid item barricade type!"); return; } Barricade barric = new Barricade(asset.Internal.id); BarricadeManager.dropBarricade(barric, null, loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else if (etype.Type == EntityAssetType.STRUCTURE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("structure_".Length)); if (asset == null || !(asset.Internal is ItemStructureAsset)) { queue.HandleError(entry, "Invalid item structure type!"); return; } StructureManager.dropStructure(new Structure(asset.Internal.id), loc.ToVector3(), 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else { queue.HandleError(entry, "Invalid or unspawnable entity type!"); return; } if (spawned != null) { queue.SetVariable("spawned", spawned); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to spawn entity: " + ex.ToString()); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 2) { ShowUsage(queue, entry); return; } ListTag players = ListTag.For(entry.GetArgumentObject(queue, 0)); ListTag items = ListTag.For(entry.GetArgumentObject(queue, 1)); List<ItemStack> itemlist = new List<ItemStack>(); for (int i = 0; i < items.ListEntries.Count; i++) { ItemTag item = ItemTag.For(TheServer, items.ListEntries[i]); if (item == null) { queue.HandleError(entry, "Invalid item!"); return; } itemlist.Add(item.Internal); } List<PlayerEntity> playerlist = new List<PlayerEntity>(); for (int i = 0; i < players.ListEntries.Count; i++) { PlayerTag player = PlayerTag.For(TheServer, players.ListEntries[i]); if (player == null) { queue.HandleError(entry, "Invalid player: " + TagParser.Escape(items.ListEntries[i].ToString())); return; } playerlist.Add(player.Internal); } foreach (PlayerEntity player in playerlist) { foreach (ItemStack item in itemlist) { player.Items.GiveItem(item); } } if (entry.ShouldShowGood(queue)) { entry.Good(queue, itemlist.Count + " item(s) given to " + playerlist.Count + " player(s)!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 2)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } bool award = entry.GetArgument(queue, 1) == "award"; if (num.Internal > 0) { PlayerSkills skills = player.Internal.player.skills; if (award) { skills._experience += (uint)num.Internal; } else { skills._experience -= (uint)num.Internal; } skills.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { skills.experience }); } else { queue.HandleError(entry, "Amount must be positive!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully " + (award ? "awarded experience to" : "took experience from") + " a player!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { player.Internal.player.sendTeleport(loc.ToVector3(), 0); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported a player to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.transform.position = loc.ToVector3(); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported a zombie to " + TagParser.Escape(loc.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.transform.position = loc.ToVector3(); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported an animal to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ItemEntityTag item; if (entity.TryGetItem(out item)) { // TODO: Find some way to teleport items, barricades, etc without voiding the InstanceID? /* Transform transform = item.Internal.transform.parent; byte x; byte y; if (Regions.tryGetCoordinate(transform.position, out x, out y)) { ItemRegion region = ItemManager.regions[x, y]; for (byte i = 0; i < region.models.Count; i+) { if (region.models[i] == transform) { ItemManager.regions[x, y].items.RemoveAt(i); ItemModelTracker.Untrack(x, y, i); ItemManager.manager.channel.send("tellTakeItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, loc.ToVector3() }); // Then respawn item at new location break; } } } */ } queue.HandleError(entry, "That entity can't be teleported!"); } catch (Exception ex) // TODO: Necessity of this? { queue.HandleError(entry, "Failed to teleport entity: " + ex.ToString()); } }
/// <summary>Executes the run command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">The command details to be ran.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { string fname = entry.GetArgument(queue, 0).ToLowerFast(); ScriptRanPreEventArgs args = new() { ScriptName = fname }; RunfileCommand rcmd = entry.Command as RunfileCommand; if (rcmd.OnScriptRanPreEvent != null) { rcmd.OnScriptRanPreEvent.Fire(args); } if (args.Cancelled) { entry.BadOutput(queue, "Script running cancelled via the ScriptRanPreEvent."); if (entry.WaitFor && queue.WaitingOn == entry) { queue.WaitingOn = null; } return; } CommandScript script = queue.Engine.GetScriptFile(args.ScriptName, out string status); if (script != null) { ScriptRanEventArgs args2 = new() { Script = script }; if (rcmd.OnScriptRanEvent != null) { rcmd.OnScriptRanEvent.Fire(args2); } if (args2.Cancelled) { entry.BadOutput(queue, "Script running cancelled via the ScriptRanEvent."); if (entry.WaitFor && queue.WaitingOn == entry) { queue.WaitingOn = null; } return; } if (script == null) { entry.BadOutput(queue, "Script running nullified via the ScriptRanEvent."); if (entry.WaitFor && queue.WaitingOn == entry) { queue.WaitingOn = null; } return; } script = args2.Script; if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Running '" + TextStyle.Separate + fname + TextStyle.Base + "'..."); } Dictionary <string, TemplateObject> vars = new(); queue.Engine.ExecuteScript(script, ref vars, out CommandQueue nqueue); if (entry.WaitFor && queue.WaitingOn == entry) { if (!nqueue.Running) { queue.WaitingOn = null; } else { EntryFinisher fin = new() { Entry = entry, Queue = queue }; nqueue.Complete += fin.Complete; } } ScriptRanPostEventArgs args4 = new() { Script = script }; if (rcmd.OnScriptRanPostEvent != null) { rcmd.OnScriptRanPostEvent.Fire(args4); } // TODO: queue.SetVariable("run_variables", new MapTag(nqueue.LowestVariables)); // TODO: use the ^= syntax here. } else { queue.HandleError(entry, "Cannot run script '" + TextStyle.Separate + fname + TextStyle.Base + "': " + status + "!"); if (entry.WaitFor && queue.WaitingOn == entry) { queue.WaitingOn = null; } } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) // TODO: Kick? { Provider.kick(player.Internal.playerID.steamID, "Removed forcibly."); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) // TODO: Remove! { zombie.Internal.health = 0; ZombieManager.sendZombieDead(zombie.Internal, new Vector3(9999, 9999, -9999)); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a zombie!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.health = 0; AnimalManager.sendAnimalDead(animal.Internal, new Vector3(9999, 9999, -9999)); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed an animal!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager magic to remove properly? barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a barricade!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) // TODO: Remove! { // TODO: Use ResourceManager magic to remove properly? resource.Internal.askDamage(resource.Internal.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a resource!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) // TODO: Remove! { // TODO: Use StructureManager magic to remove properly? structure.InternalData.structure.askDamage(structure.InternalData.structure.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a structure!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) // TODO: Remove! { vehicle.Internal.health = 0; VehicleManager.sendVehicleExploded(vehicle.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a vehicle!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal < 0) { queue.HandleError(entry, "Must provide a non-negative number!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } EPlayerKill kill; // for use with "out EPlayerKill" parameters PlayerTag player; if (entity.TryGetPlayer(out player)) { PlayerLife life = player.Internal.player.life; UFMHealthController healthController = player.Internal.player.GetComponent<UFMHealthController>(); uint health = healthController != null ? healthController.health : life.health; if (num.Internal >= health) { uint amount = (uint)num.Internal; if (healthController != null) { healthController.health = 0; } if (amount >= byte.MaxValue) // TODO: better handling { life._health = 0; amount = 1; } life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null); } else { uint amount = (uint)num.Internal; if (healthController != null) { healthController.Damage((uint)num.Internal); } life._health = healthController.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager? barricade.InternalData.barricade.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { // TODO: Use ResourceManager? resource.Internal.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { // TODO: Use StructureManager? structure.InternalData.structure.askDamage((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askDamage((ushort)num.Internal, false); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to damage entity: " + ex.ToString()); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { player.Internal.player.sendTeleport(loc.ToVector3(), 0); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported a player to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { zombie.Internal.transform.position = loc.ToVector3(); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported a zombie to " + TagParser.Escape(loc.ToString()) + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.transform.position = loc.ToVector3(); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully teleported an animal to " + TagParser.Escape(loc.ToString()) + "!"); } return; } ItemEntityTag item; if (entity.TryGetItem(out item)) { // TODO: Find some way to teleport items, barricades, etc without voiding the InstanceID? /* * Transform transform = item.Internal.transform.parent; * byte x; * byte y; * if (Regions.tryGetCoordinate(transform.position, out x, out y)) * { * ItemRegion region = ItemManager.regions[x, y]; * for (byte i = 0; i < region.models.Count; i+) * { * if (region.models[i] == transform) * { * ItemManager.regions[x, y].items.RemoveAt(i); * ItemModelTracker.Untrack(x, y, i); * ItemManager.manager.channel.send("tellTakeItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] * { * x, * y, * loc.ToVector3() * }); * // Then respawn item at new location * break; * } * } * } */ } queue.HandleError(entry, "That entity can't be teleported!"); } catch (Exception ex) // TODO: Necessity of this? { queue.HandleError(entry, "Failed to teleport entity: " + ex.ToString()); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) // TODO: Kick? { Provider.kick(player.Internal.playerID.steamID, "Removed forcibly."); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) // TODO: Remove! { zombie.Internal.health = 0; ZombieManager.sendZombieDead(zombie.Internal, new Vector3(9999, 9999, -9999)); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a zombie!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { animal.Internal.health = 0; AnimalManager.sendAnimalDead(animal.Internal, new Vector3(9999, 9999, -9999)); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed an animal!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager magic to remove properly? barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a barricade!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) // TODO: Remove! { // TODO: Use ResourceManager magic to remove properly? resource.Internal.askDamage(resource.Internal.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a resource!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) // TODO: Remove! { // TODO: Use StructureManager magic to remove properly? structure.InternalData.structure.askDamage(structure.InternalData.structure.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a structure!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) // TODO: Remove! { vehicle.Internal.health = 0; VehicleManager.sendVehicleExploded(vehicle.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully removed a vehicle!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); }
/// <summary>Executes the command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { if (entry.IsCallback) { return; } string type = entry.GetArgument(queue, 0).ToLowerFast(); string eventname = entry.GetArgument(queue, 1).ToLowerFast(); if (type == "clear" && eventname == "all") { foreach (KeyValuePair <string, ScriptEvent> evt in queue.Engine.Events) { evt.Value.Clear(); } if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Cleared all events."); } return; } if (!queue.Engine.Events.TryGetValue(eventname, out ScriptEvent theEvent)) { queue.HandleError(entry, "Unknown event '" + TextStyle.Separate + eventname + TextStyle.Base + "'."); return; } if (type == "clear") { theEvent.Clear(); if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Cleared event '" + TextStyle.Separate + eventname + TextStyle.Base + "' of all handlers."); } } else if (type == "remove") { if (entry.Arguments.Length < 3) { ShowUsage(queue, entry); return; } string name = entry.GetArgument(queue, 2).ToLowerFast(); bool success = theEvent.RemoveEventHandler(name); if (success) { if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Removed event handler '" + TextStyle.Separate + name + TextStyle.Base + "'."); } } else { if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false) { if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Unknown event handler '" + TextStyle.Separate + name + TextStyle.Base + "'."); } } else { queue.HandleError(entry, "Unknown event handler '" + TextStyle.Separate + name + TextStyle.Base + "'."); } } } else if (type == "add") { if (entry.Arguments.Length < 3) { ShowUsage(queue, entry); return; } string name = entry.GetArgument(queue, 2).ToLowerFast(); if (entry.InnerCommandBlock == null) { queue.HandleError(entry, "Event command invalid: No block follows!"); return; } if (theEvent.HasHandler(name)) { if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false) { if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Handler '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!"); } } else { queue.HandleError(entry, "Handler '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!"); } } double priority = 0; if (entry.Arguments.Length > 3) { priority = NumberTag.For(entry.GetArgumentObject(queue, 3), queue.Error).Internal; } List <CommandEntry> entries = new(entry.InnerCommandBlock.Length + 2); MapTag expectedContext = new(); expectedContext.Internal.Add("context", entry.System.TagTypes.Type_Map.TagForm); entries.Add(entry.System.TheRequireCommand.GenerateEntry(expectedContext, entry.ScriptName, entry.ScriptLine)); entries.AddRange(entry.InnerCommandBlock); CommandScript script = new(theEvent.Name + "__handler__" + name, CommandScript.TYPE_NAME_EVENT, entries.ToArray(), entry.System, entry.BlockStart, DebugMode.MINIMAL); theEvent.RegisterEventHandler(priority, script, name); entry.GoodOutput(queue, "Handler '" + TextStyle.Separate + name + "" + TextStyle.Base + "' defined for event '" + TextStyle.Separate + theEvent.Name + TextStyle.Base + "'."); } else { ShowUsage(queue, entry); } }
/// <summary>Executes the command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { TemplateObject obj = entry.GetArgumentObject(queue, 0); FunctionTag function = FunctionTag.CreateFor(obj, queue.GetTagData()); if (function == null) { queue.HandleError(entry, "Cannot call function '" + TextStyle.Separate + obj.ToString() + TextStyle.Base + "': it does not exist!"); return; } CommandScript script = function.Internal; if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "Calling '" + function.GetDebugString() + TextStyle.Base + "'..."); } CompiledCommandRunnable runnable = script.Compiled.ReferenceCompiledRunnable.Duplicate(); if (runnable.Entry.Entries.Length > 0) { Dictionary <string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup; foreach (string var in entry.NamedArguments.Keys) { if (!var.StartsWithNull()) { if (varlookup.TryGetValue(var, out SingleCILVariable varx)) { // TODO: Type verification! runnable.Entry.GetSetter(varx.Index).Invoke(runnable, entry.GetNamedArgumentObject(queue, var)); } } } } if (entry.NamedArguments.ContainsKey(CommandEntry.SAVE_NAME_ARG_ID)) { bool sgood = entry.ShouldShowGood(queue); string vname = entry.NamedArguments[CommandEntry.SAVE_NAME_ARG_ID].ToString(); if (sgood) { entry.GoodOutput(queue, "Noticing variable track for " + vname + "."); } CompiledCommandRunnable curRunnable = queue.CurrentRunnable; if (!entry.VarLookup.TryGetValue(vname, out SingleCILVariable locVar)) { queue.HandleError(entry, "Invalid save-to variable: " + vname + "!"); return; } runnable.Callback = () => { // TODO: Fix! /*if (runnable.Entry.Entries.Length > 0) * { * MapTag mt = new MapTag(); * Dictionary<string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup; * foreach (SingleCILVariable vara in varlookup.Values) * { * if (runnable.LocalVariables[vara.Index].Internal != null) * { * mt.Internal.Add(vara.Name, runnable.LocalVariables[vara.Index].Internal); * } * } * curRunnable.LocalVariables[locVar.Index].Internal = mt; * }*/ if (sgood) { entry.GoodOutput(queue, "Call complete."); } }; } queue.RunningStack.Push(runnable); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { TemplateObject spawned = null; LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } string targetAssetType = entry.GetArgument(queue, 0).ToLowerFast(); EntityType etype = EntityType.ValueOf(targetAssetType); if (etype == null) { queue.HandleError(entry, "Invalid entity type!"); return; } if (etype.Type == EntityAssetType.ZOMBIE) { Vector3 vec3 = loc.ToVector3(); byte reg = 0; // TODO: Optionally specifiable float closest = float.MaxValue; for (int r = 0; r < LevelZombies.zombies.Length; r++) { for (int i = 0; i < LevelZombies.zombies[r].Count; i++) { float dist = (LevelZombies.zombies[r][i].point - vec3).sqrMagnitude; if (dist < closest) { closest = dist; reg = (byte)r; } } } ZombieManager.manager.addZombie(reg, 0, 0, 0, 0, 0, 0, 0, 0, vec3, 0, false); Zombie zombie = ZombieManager.regions[reg].zombies[ZombieManager.regions[reg].zombies.Count - 1]; // TODO: Make this actually work! (See complaints file!) /* * foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) * { * ZombieManager.manager.channel.openWrite(); * ZombieManager.manager.channel.write(reg); * ZombieManager.manager.channel.write((ushort)1); * ZombieManager.manager.channel.write(new object[] * { * zombie.type, * (byte)zombie.speciality, * zombie.shirt, * zombie.pants, * zombie.hat, * zombie.gear, * zombie.move, * zombie.idle, * zombie.transform.position, * MeasurementTool.angleToByte(zombie.transform.rotation.eulerAngles.y), * zombie.isDead * }); * ZombieManager.manager.channel.closeWrite("tellZombies", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); * } */ if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a zombie at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); } spawned = new ZombieTag(zombie); } else if (etype.Type == EntityAssetType.ANIMAL) { AnimalAssetTag asset = AnimalAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid animal type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO AnimalManager.manager.addAnimal(asset.Internal.id, loc.ToVector3(), 0, false); Animal animal = AnimalManager.animals[AnimalManager.animals.Count - 1]; foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) { AnimalManager.manager.channel.openWrite(); AnimalManager.manager.channel.write((ushort)1); AnimalManager.manager.channel.write(new object[] { animal.id, animal.transform.position, MeasurementTool.angleToByte(animal.transform.rotation.eulerAngles.y), animal.isDead }); AnimalManager.manager.channel.closeWrite("tellAnimals", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (" + animal.gameObject.GetInstanceID() + ")"); } spawned = new AnimalTag(animal); } else if (etype.Type == EntityAssetType.VEHICLE) { VehicleAssetTag asset = VehicleAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid vehicle type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO VehicleManager.spawnVehicle(asset.Internal.id, loc.ToVector3(), Quaternion.identity); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the vehicle entity! } else if (etype.Type == EntityAssetType.WORLD_OBJECT) { WorldObjectAssetTag asset = WorldObjectAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid world object type!"); return; } LevelObjects.addObject(loc.ToVector3(), Quaternion.identity, Vector3.one, asset.Internal.id, asset.Internal.name, asset.Internal.GUID, ELevelObjectPlacementOrigin.MANUAL); // TODO: Network! entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); // TODO: Get the world entity! } else if (etype.Type == EntityAssetType.ITEM) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid item type!"); return; } byte x; byte y; if (Regions.tryGetCoordinate(loc.ToVector3(), out x, out y)) { Item item = new Item(asset.Internal.id, 1, asset.Internal.quality); ItemData data = new ItemData(item, ++ItemManager.instanceCount, loc.ToVector3(), Dedicator.isDedicated); ItemManager.regions[x, y].items.Add(data); ItemModelTracker.Track(data, loc.ToVector3()); ItemManager.manager.channel.send("tellItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, item.id, item.amount, item.quality, item.state, loc.ToVector3() }); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the item entity! } else { queue.HandleError(entry, "Trying to spawn item outside any valid item regions!"); } } else if (etype.Type == EntityAssetType.BARRICADE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("barricade_".Length)); if (asset == null || !(asset.Internal is ItemBarricadeAsset)) { queue.HandleError(entry, "Invalid item barricade type!"); return; } Barricade barric = new Barricade(asset.Internal.id); BarricadeManager.dropBarricade(barric, null, loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else if (etype.Type == EntityAssetType.STRUCTURE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("structure_".Length)); if (asset == null || !(asset.Internal is ItemStructureAsset)) { queue.HandleError(entry, "Invalid item structure type!"); return; } StructureManager.dropStructure(new Structure(asset.Internal.id), loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else { queue.HandleError(entry, "Invalid or unspawnable entity type!"); return; } if (spawned != null) { queue.SetVariable("spawned", spawned); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to spawn entity: " + ex.ToString()); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } EPlayerKill kill; // for use with "out EPlayerKill" parameters PlayerTag player; if (entity.TryGetPlayer(out player)) { PlayerLife life = player.Internal.player.life; life.askDamage(life.health, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { while (!zombie.Internal.isDead) { uint xp; zombie.Internal.askDamage((byte)zombie.Internal.health, Vector3.zero, out kill, out xp); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed a zombie!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { while (!animal.Internal.isDead) { uint xp; animal.Internal.askDamage((byte)animal.Internal.health, Vector3.zero, out kill, out xp); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully killed an animal!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { // TODO: Use BarricadeManager? barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a barricade!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { // TODO: Use ResourceManager? resource.Internal.askDamage(resource.Internal.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a resource!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { // TODO: Use StructureManager? structure.InternalData.structure.askDamage(structure.InternalData.structure.health); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a structure!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askDamage(vehicle.Internal.health, false); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully destroyed a vehicle!"); } return; } queue.HandleError(entry, "That entity can't be damaged!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { string animation = entry.GetArgument(queue, 1).ToUpperInvariant(); EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { try { player.Internal.player.animator.sendGesture((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation), true); //player.Internal.player.animator.askGesture(player.Internal.playerID.steamID, (byte)((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation))); } catch (ArgumentException) { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { int ind = animation.IndexOf('_'); string after = animation.Substring(ind + 1); animation = animation.Substring(0, ind); if (animation == "STARTLE") { ZombieManager.sendZombieStartle(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else if (animation == "STUN") { ZombieManager.sendZombieStun(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else if (animation == "ATTACK") { ZombieManager.sendZombieAttack(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated an animal!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { if (animation == "STARTLE") { AnimalManager.sendAnimalStartle(animal.Internal); } else if (animation == "PANIC") { AnimalManager.sendAnimalPanic(animal.Internal); } else if (animation == "ATTACK") { AnimalManager.sendAnimalAttack(animal.Internal); } else { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated an animal!"); } return; } queue.HandleError(entry, "That entity can't be animated!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal < 0) { queue.HandleError(entry, "Must provide a non-negative number!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { UFMHealthController healthController = player.Internal.player.gameObject.GetComponent<UFMHealthController>(); uint amount = (uint)num.Internal; if (healthController != null) { healthController.Heal(amount); amount = (uint)(((double)amount / healthController.maxHealth) * 100.0); } PlayerLife life = player.Internal.player.life; life._health = healthController.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); if (entry.ShouldShowGood(queue)) { uint finalHealth = healthController != null ? healthController.health : life.health; entry.Good(queue, "Successfully healed a player to a new health value of " + finalHealth + "!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { Zombie inZomb = zombie.Internal; inZomb.health += (ushort)num.Internal; if (inZomb.health > inZomb.maxHealth) { inZomb.health = inZomb.maxHealth; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a zombie to a new health value of " + inZomb.health + "!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { Animal inAnimal = animal.Internal; inAnimal.health += (ushort)num.Internal; if (inAnimal.health > inAnimal.asset.health) { inAnimal.health = inAnimal.asset.health; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed an animal to a new health value of " + inAnimal.health + "!"); } return; } BarricadeTag barricade; if (entity.TryGetBarricade(out barricade)) { Barricade inBarricade = barricade.InternalData.barricade; inBarricade.health += (ushort)num.Internal; ushort max = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, inBarricade.id)).health; if (inBarricade.health > max) { inBarricade.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a barricade to a new health value of " + inBarricade.health + "!"); } return; } ResourceTag resource; if (entity.TryGetResource(out resource)) { ResourceSpawnpoint inResource = resource.Internal; inResource.health += (ushort)num.Internal; ushort max = ((ResourceAsset)Assets.find(EAssetType.RESOURCE, inResource.id)).health; if (inResource.health > max) { inResource.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a resource to a new health value of " + inResource.health + "!"); } return; } StructureTag structure; if (entity.TryGetStructure(out structure)) { Structure inStructure = structure.InternalData.structure; inStructure.health += (ushort)num.Internal; ushort max = ((ItemStructureAsset)Assets.find(EAssetType.ITEM, inStructure.id)).health; if (inStructure.health > max) { inStructure.health = max; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a structure to a new health value of " + inStructure.health + "!"); } return; } VehicleTag vehicle; if (entity.TryGetVehicle(out vehicle)) { vehicle.Internal.askRepair((ushort)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully healed a vehicle to a new health value of " + vehicle.Internal.health + "!"); } return; } queue.HandleError(entry, "That entity can't be healed!"); } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, ("Failed to heal entity: " + ex.ToString())); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1)); if (item == null) { queue.HandleError(entry, "Invalid item!"); return; } byte amount = 1; if (entry.Arguments.Count > 2) { amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2)); } PlayerInventory inventory = player.Internal.player.inventory; byte remainingAmount = amount; InventorySearch search; while (remainingAmount > 0 && (search = inventory.has(item.Internal.id)) != null) // TODO: Less awkward code!? { if (search.jar.item.amount <= remainingAmount) { inventory.removeItem(search.page, inventory.getIndex(search.page, search.jar.x, search.jar.y)); remainingAmount -= search.jar.item.amount; } else { inventory.sendUpdateAmount(search.page, search.jar.x, search.jar.y, (byte)(search.jar.item.amount - remainingAmount)); remainingAmount = 0; } } if (remainingAmount == 0) { if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully took " + amount + " " + TagParser.Escape(item.Internal.name) + "!"); } } else if (remainingAmount < amount) { if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully took " + (amount - remainingAmount) + " " + TagParser.Escape(item.Internal.name) + "! (" + remainingAmount + " more not found!)"); } } else { queue.HandleError(entry, "Failed to take item (does the inventory contain any?)!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments[0].ToString() == "\0CALLBACK") { return; } if (entry.Arguments.Count < 3) { ShowUsage(queue, entry); return; } bool servermode = entry.GetArgument(queue, 0).ToLowerFast() == "server"; string name = entry.GetArgument(queue, 1).ToLowerFast(); string help = entry.GetArgument(queue, 2); if (entry.InnerCommandBlock == null) { queue.HandleError(entry, "Event command invalid: No block follows!"); return; } // NOTE: Commands are compiled! CommandScript script = new CommandScript("ut_command_" + name, entry.InnerCommandBlock, entry.BlockStart, queue.CurrentEntry.Types, true) { Debug = DebugMode.MINIMAL }; UnturnedCustomCommand ucc = new UnturnedCustomCommand(name, help, script); if (servermode) { Commander.commands.Insert(1, ucc); } else { UnturnedFreneticMod.Instance.PlayerCommands.Add(ucc); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Registered command!"); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { string animation = entry.GetArgument(queue, 1).ToUpperInvariant(); EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { try { player.Internal.player.animator.sendGesture((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation), true); //player.Internal.player.animator.askGesture(player.Internal.playerID.steamID, (byte)((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation))); } catch (ArgumentException) { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated a player!"); } return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { int ind = animation.IndexOf('_'); string after = animation.Substring(ind + 1); animation = animation.Substring(0, ind); if (animation == "STARTLE") { ZombieManager.sendZombieStartle(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else if (animation == "STUN") { ZombieManager.sendZombieStun(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else if (animation == "ATTACK") { ZombieManager.sendZombieAttack(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal); } else { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated an animal!"); } return; } AnimalTag animal; if (entity.TryGetAnimal(out animal)) { if (animation == "STARTLE") { AnimalManager.sendAnimalStartle(animal.Internal); } else if (animation == "PANIC") { AnimalManager.sendAnimalPanic(animal.Internal); } else if (animation == "ATTACK") { AnimalManager.sendAnimalAttack(animal.Internal); } else { queue.HandleError(entry, "Invalid animation specified!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Animated an animal!"); } return; } queue.HandleError(entry, "That entity can't be animated!"); }
public override void Execute(CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); bool primary = entry.GetArgument(queue, 1) == "primary"; bool start = BooleanTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal; if (player.Internal.player.equipment.useable == null) { entry.Bad(queue, "Failed to use item, holding nothing."); return; } if (primary) { if (start) { player.Internal.player.equipment.useable.startPrimary(); } else { player.Internal.player.equipment.useable.stopPrimary(); } } else { if (start) { player.Internal.player.equipment.useable.startSecondary(); } else { player.Internal.player.equipment.useable.stopSecondary(); } } player.Internal.player.equipment.useable.tick(); player.Internal.player.equipment.useable.tock(player.Internal.player.input.clock); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Player is " + (start ? "now" : "no longer") + " using the " + (primary ? "primary" : "secondary") + " mode on their held item!"); } }