Esempio n. 1
0
        private void OnPlayerDeath(UnturnedPlayer player, EDeathCause cause, ELimb limb, CSteamID murderer)
        {
            List <ItemJar> droppedInventory = new List <ItemJar>();

            UnityEngine.Vector3 deathlocation = player.Position + new UnityEngine.Vector3(0, (float)0.60, 0);

            moveInventoryItems(player, droppedInventory);
            if (Instance.Configuration.Instance.StoreClothes)
            {
                removeClothing(player, droppedInventory);
            }

            // use the specified unturned storage asset
            Barricade deathBag = new Barricade(Instance.Configuration.Instance.DeathBagId);

            UnityEngine.Transform barricadeTransform = new UnityEngine.GameObject().transform;
            barricadeTransform.localPosition = deathlocation;

            // create the physical bag to be dropped into the scene
            InteractableStorage deathBagStorage = BarricadeManager.dropBarricade(deathBag, barricadeTransform, deathlocation, 0, 0, 0, 0, 0).GetComponent <InteractableStorage>();

            foreach (ItemJar itemjar in droppedInventory)
            {
                // add the inventory into the bag
                deathBagStorage.items.tryAddItem(itemjar.item);
            }

            TaskDispatcher.QueueOnMainThread(() =>
            {
                DamageTool.damage(deathBagStorage.transform, false, 100000, 1, out EPlayerKill kill);
            }, (float)Instance.Configuration.Instance.Delay);
        }
Esempio n. 2
0
        public static void Prefix(byte amount, Vector3 newRagdoll, EDeathCause newCause, ELimb newLimb, CSteamID newKiller, ref EPlayerKill kill, bool trackKill, ERagdollEffect newRagdollEffect, bool canCauseBleeding, PlayerLife __instance)
        {
            Player ply = __instance.channel.owner.player;
            if (ply is null) return;

            if (amount >= ply.life.health)
            {
                Transform deathboxTransform = BarricadeManager.dropBarricade(new Barricade(1283),ply.transform, ply.transform.position, 0f, 0f, 0f, (ulong) ply.channel.owner.playerID.steamID, 0UL);
                byte x;
                byte y;
                ushort plant;
                ushort index;
                BarricadeRegion region;

                if (!BarricadeManager.tryGetInfo(deathboxTransform, out x, out y, out plant, out index, out region)) return;

                InteractableStorage storage = deathboxTransform.GetComponent<InteractableStorage>();
                storage.items.resize(10, 10);

                for (byte page = 0; page < 6; page++)
                {
                    for (byte i = 0; i < ply.inventory.items[page].getItemCount(); i++)
                    {
                        ItemJar item = ply.inventory.items[page].getItem(i);
                        storage.items.tryAddItem(item.item);
                    }
                }
                TTTPlayer.ClearInventoryUnsafe(__instance.channel.owner); // Clears clothing to prevent players aqquiring detective vest ect.
            }
        }
        public void SummonContainer(PlayerClothing clothing, ushort id)
        {
            var transform = BarricadeManager.dropBarricade(new Barricade(id), null, BarricadeLocation.ToVector3(), 0, 0, 0, 0, 0)
                            .GetComponent <InteractableMannequin>();

            if (!Plugin.Instance.Configuration.Instance.ClearClothing)
            {
                transform.clothes.visualShirt    = clothing.shirt;
                transform.clothes.visualPants    = clothing.pants;
                transform.clothes.visualHat      = clothing.hat;
                transform.clothes.visualBackpack = clothing.backpack;
                transform.clothes.visualVest     = clothing.vest;
                transform.clothes.visualMask     = clothing.mask;
                transform.clothes.visualGlasses  = clothing.glasses;
            }

            transform.rebuildState();
            BarricadeManager.tryGetInfo(transform.transform, out byte x, out byte y, out ushort plant, out ushort index, out var region, out var drop);
            InstanceId = drop.instanceID;
        }
Esempio n. 4
0
 // Token: 0x060033A2 RID: 13218 RVA: 0x0014EFC8 File Offset: 0x0014D3C8
 private void OnCollisionEnter(Collision collision)
 {
     if (this.isExploded)
     {
         return;
     }
     if (collision.collider.isTrigger)
     {
         return;
     }
     this.isExploded = true;
     if (Provider.isServer)
     {
         Transform transform = BarricadeManager.dropBarricade(new Barricade(1374), null, base.transform.position, 0f, 0f, 0f, 0UL, 0UL);
         if (transform != null)
         {
             InteractableStorage component = transform.GetComponent <InteractableStorage>();
             component.despawnWhenDestroyed = true;
             if (component != null && component.items != null)
             {
                 int i = 0;
                 while (i < 8)
                 {
                     ushort num = SpawnTableTool.resolve(this.id);
                     if (num == 0)
                     {
                         break;
                     }
                     if (!component.items.tryAddItem(new Item(num, EItemOrigin.ADMIN), false))
                     {
                         i++;
                     }
                 }
                 component.items.onStateUpdated();
             }
         }
         transform.gameObject.AddComponent <CarepackageDestroy>();
         EffectManager.sendEffectReliable(120, EffectManager.INSANE, base.transform.position);
     }
     UnityEngine.Object.Destroy(base.gameObject);
 }
Esempio n. 5
0
        private void OnCollisionEnter(Collision collision)
        {
            if (isExploded)
            {
                return;
            }

            if (collision.collider.isTrigger)
            {
                return;
            }

            isExploded = true;

            Transform t = BarricadeManager.dropBarricade(new Barricade(1374), null, base.transform.position, 0f, 0f, 0f, 0UL, 0UL);

            if (t == null)
            {
                return;
            }

            InteractableStorage component = transform.GetComponent <InteractableStorage>();

            component.despawnWhenDestroyed = true;
            if (component.items != null)
            {
                foreach (AirdropItem ai in AirdropManager.GetAirdropItems(type))
                {
                    for (int i = 0; i < ai.amount; i++)
                    {
                        component.items.tryAddItem(new Item((ushort)ai.id, EItemOrigin.ADMIN, (byte)ai.durability), false);
                    }
                }

                component.items.onStateUpdated();
            }

            EffectManager.sendEffectReliable((ushort)AirdropPlugin.Conf.AirdropEffectId, EffectManager.INSANE, transform.position);
        }
        private static void GiveBox(UnturnedPlayer player, string steamID, string boxName)
        {
            Block  block = Functions.ReadBlock(Plugin.Instance.pathTemp + $@"\{steamID}\{boxName}.dat", 0);
            ushort id    = block.readUInt16();
            ushort he    = block.readUInt16();

            //Vector3 point = block.readSingleVector3();
            block.readSingleVector3();
            float   x       = (player.Player.look.aim.forward.x - player.Position.x < 5) ? player.Player.look.aim.forward.x : player.Position.x + 4;
            float   y       = (player.Player.look.aim.forward.y - player.Position.y < 5) ? player.Player.look.aim.forward.y : player.Position.y + 4;
            float   z       = (player.Player.look.aim.forward.z - player.Position.z < 5) ? player.Player.look.aim.forward.z : player.Position.z + 4;
            Vector3 point   = new Vector3(x, y, z);
            float   angle_x = block.readByte();
            float   angle_y = block.readByte();
            float   angle_z = block.readByte();
            ulong   owner   = block.readUInt64();
            ulong   group   = block.readUInt64();

            byte[]             state     = block.readByteArray();
            Asset              asset1    = Assets.find(EAssetType.ITEM, id);
            ItemBarricadeAsset asset2    = asset1 as ItemBarricadeAsset;
            Barricade          barricade = new Barricade(id, he, state, asset2);

            //Transform hit = BarricadeTool.getBarricade(region.parent, 100, owner, group, point, Quaternion.Euler((float)((int)angle_x * 2), (float)((int)angle_y * 2), (float)((int)angle_z * 2)), id, state, asset2);

            BarricadeManager.dropBarricade(barricade, null, player.Position, angle_x, angle_y, angle_z, owner, group);
            //block.writeUInt16(bdata.barricade.id);
            //block.writeUInt16(bdata.barricade.health);
            //block.writeSingleVector3(bdata.point);
            //block.writeByte(bdata.angle_x);
            //block.writeByte(bdata.angle_y);
            //block.writeByte(bdata.angle_z);
            //block.writeUInt64(bdata.owner);
            //block.writeUInt64(bdata.group);
            //block.writeByteArray(bdata.barricade.state);

            System.Console.WriteLine("box was spawned!");
        }
        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());
            }
        }