Example #1
0
        private static void RandomItem(ClientInfo _cInfo, bool _announce)
        {
            string    _randomItem = list.RandomObject();
            ItemValue _itemValue  = ItemClass.GetItem(_randomItem, false);

            _itemValue = new ItemValue(_itemValue.type, false);
            EntityPlayer _player  = GameManager.Instance.World.Players.dict[_cInfo.entityId];
            int          _quality = 1;

            if (_itemValue.HasQuality)
            {
                _quality           = random.Next(1, 7);
                _itemValue.Quality = _quality;
            }
            int[] _counts;
            if (dict.TryGetValue(_randomItem, out _counts))
            {
                int       _count    = random.Next(_counts[0], _counts[1] + 1);
                ItemStack _itemDrop = new ItemStack(_itemValue, _count);
                ItemValue itemValue;
                itemValue = new ItemValue(ItemClass.GetItem(_randomItem).type, _quality, _quality, false);
                World world      = GameManager.Instance.World;
                var   entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                {
                    entityClass     = EntityClass.FromString("item"),
                    id              = EntityFactory.nextEntityID++,
                    itemStack       = new ItemStack(itemValue, _count),
                    pos             = world.Players.dict[_cInfo.entityId].position,
                    rot             = new Vector3(20f, 0f, 20f),
                    lifetime        = 60f,
                    belongsPlayerId = _cInfo.entityId
                });
                world.SpawnEntityInWorld(entityItem);
                _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId));
                world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed);
                string _phrase7;
                if (!Phrases.Dict.TryGetValue(7, out _phrase7))
                {
                    _phrase7 = " received {ItemCount} {ItemName} from gimme.";
                }
                _phrase7 = _phrase7.Replace("{ItemCount}", _count.ToString());
                string _name;
                if (dict1.TryGetValue(_randomItem, out _name))
                {
                    _phrase7 = _phrase7.Replace("{ItemName}", _name);
                }
                if (_announce)
                {
                    ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _phrase7 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Global, null);
                }
                else
                {
                    ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _phrase7 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                }
                string _sql;
                if (Wallet.IsEnabled && Command_Cost >= 1)
                {
                    Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
                }
                _sql = string.Format("UPDATE Players SET last_gimme = '{0}' WHERE steamid = '{1}'", DateTime.Now.ToString(), _cInfo.playerId);
                SQL.FastQuery(_sql);
            }
        }
Example #2
0
 public static void GiveAnimals(ClientInfo _cInfo, bool _announce)
 {
     if (Animal_List.Length > 0)
     {
         string[] _animalList = { };
         if (Animal_List.Contains(","))
         {
             if (Animal_List.Contains(" "))
             {
                 Animal_List.Replace(" ", "");
             }
             _animalList = Animal_List.Split(',').ToArray();
         }
         else if (Animal_List.Contains(" "))
         {
             _animalList = Animal_List.Split(' ').ToArray();
         }
         int minRad = 0;
         int maxRad = 0;
         if (Maximum_Spawn_Radius < Minimum_Spawn_Radius)
         {
             minRad = 40;
             maxRad = 60;
         }
         else
         {
             minRad = Minimum_Spawn_Radius;
             maxRad = Maximum_Spawn_Radius;
         }
         List <string> _animalId = new List <string>();
         foreach (string i in _animalList)
         {
             _animalId.Add(i);
         }
         int _r = rnd.Next(_animalId.Count);
         int _newId;
         int.TryParse(_animalId[_r], out _newId);
         int _nextRadius = rnd.Next(minRad, maxRad + 1);
         Dictionary <int, EntityClass> .KeyCollection entityTypesCollection = EntityClass.list.Dict.Keys;
         int counter = 1;
         foreach (int i in entityTypesCollection)
         {
             EntityClass eClass = EntityClass.list[i];
             if (!eClass.bAllowUserInstantiate)
             {
                 continue;
             }
             if (_newId == counter)
             {
                 SdtdConsole.Instance.ExecuteSync(string.Format("ser {0} {1} @ {2}", _cInfo.entityId, _nextRadius, _newId), (ClientInfo)null);
             }
             counter++;
         }
         string _phrase715;
         if (!Phrases.Dict.TryGetValue(715, out _phrase715))
         {
             _phrase715 = " you have tracked down an animal to within {Radius} metres.";
         }
         _phrase715 = _phrase715.Replace("{Radius}", _nextRadius.ToString());
         if (_announce)
         {
             ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _phrase715 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Global, null);
         }
         else
         {
             ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + _phrase715 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
         }
         string _sql;
         if (Wallet.IsEnabled && Command_Cost >= 1)
         {
             Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
         }
         _sql = string.Format("UPDATE Players SET lastAnimals = '{0}' WHERE steamid = '{1}'", DateTime.Now, _cInfo.playerId);
         SQL.FastQuery(_sql, "Animals");
     }
     else
     {
         ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + ", animal list is empty. Contact an administrator.[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
     }
 }
Example #3
0
 private static bool GameMessage(ClientInfo _cInfo, EnumGameMessages _type, string _msg, string _mainName, bool _localizeMain, string _secondaryName, bool _localizeSecondary)
 {
     try
     {
         if (_type == EnumGameMessages.EntityWasKilled && _cInfo != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId))
         {
             EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId];
             if (_player != null)
             {
                 if (DeathSpot.IsEnabled)
                 {
                     DeathSpot.PlayerKilled(_player);
                 }
                 if (!string.IsNullOrEmpty(_secondaryName) && !string.IsNullOrEmpty(_mainName) && _mainName != _secondaryName)
                 {
                     ClientInfo _cInfo2 = ConsoleHelper.ParseParamIdOrName(_secondaryName);
                     if (_cInfo2 != null && GameManager.Instance.World.Players.dict.ContainsKey(_cInfo2.entityId))
                     {
                         EntityPlayer _player2 = GameManager.Instance.World.Players.dict[_cInfo2.entityId];
                         if (_player2 != null)
                         {
                             if (Bounties.IsEnabled)
                             {
                                 Bounties.PlayerKilled(_player, _player2, _cInfo, _cInfo2);
                             }
                             if (Wallet.IsEnabled)
                             {
                                 if (Wallet.PVP && Wallet.Player_Kills > 0)
                                 {
                                     Wallet.AddCoinsToWallet(_cInfo2.playerId, Wallet.Player_Kills);
                                 }
                                 else if (Wallet.Player_Kills > 0)
                                 {
                                     Wallet.SubtractCoinsFromWallet(_cInfo2.playerId, Wallet.Player_Kills);
                                 }
                             }
                             if (KillNotice.IsEnabled && _player2.IsAlive())
                             {
                                 string _holdingItem = _player2.inventory.holdingItem.GetItemName();
                                 if (!string.IsNullOrEmpty(_holdingItem))
                                 {
                                     ItemValue _itemValue = ItemClass.GetItem(_holdingItem, true);
                                     if (_itemValue.type != ItemValue.None.type)
                                     {
                                         KillNotice.Exec(_cInfo, _player, _cInfo2, _player2, _holdingItem);
                                         return(false);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in API.GameMessage: {0}", e.Message));
     }
     return(true);
 }
Example #4
0
 private static void RandomZombie(ClientInfo _cInfo)
 {
     if (Zombie_Id != "")
     {
         if (Zombie_Id.Contains(","))
         {
             string[] _zombieIds = Zombie_Id.Split(',');
             int      _count     = random.Next(1, _zombieIds.Length + 1);
             string   _zId       = _zombieIds[_count];
             if (int.TryParse(_zId, out int _zombieId))
             {
                 Log.Out(string.Format("[SERVERTOOLS] Spawned an entity for {0}'s gimme", _cInfo.playerName));
                 SdtdConsole.Instance.ExecuteSync(string.Format("ser {0} 10 @ {1}", _cInfo.playerId, _zombieId), null);
                 string _phrase807;
                 if (!Phrases.Dict.TryGetValue(807, out _phrase807))
                 {
                     _phrase807 = "OH NO! How did that get in there? You have received a zombie.";
                 }
                 ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase807 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                 if (Wallet.IsEnabled && Command_Cost >= 1)
                 {
                     Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
                 }
                 PersistentContainer.Instance.Players[_cInfo.playerId].LastGimme = DateTime.Now;
                 PersistentContainer.Instance.Save();
             }
             else
             {
                 RandomItem(_cInfo);
             }
         }
         else
         {
             if (int.TryParse(Zombie_Id, out int _zombieId))
             {
                 Log.Out(string.Format("[SERVERTOOLS] Spawned an entity for {0}'s gimme", _cInfo.playerName));
                 SdtdConsole.Instance.ExecuteSync(string.Format("ser {0} 10 @ {1}", _cInfo.playerId, _zombieId), null);
                 string _phrase807;
                 if (!Phrases.Dict.TryGetValue(807, out _phrase807))
                 {
                     _phrase807 = "OH NO! How did that get in there? You have received a zombie.";
                 }
                 ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase807 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                 if (Wallet.IsEnabled && Command_Cost >= 1)
                 {
                     Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
                 }
                 PersistentContainer.Instance.Players[_cInfo.playerId].LastGimme = DateTime.Now;
                 PersistentContainer.Instance.Save();
             }
             else
             {
                 RandomItem(_cInfo);
             }
         }
     }
     else
     {
         RandomItem(_cInfo);
     }
 }
Example #5
0
 private static void RandomItem(ClientInfo _cInfo)
 {
     try
     {
         string    _randomItem = list.RandomObject();
         ItemValue _itemValue  = new ItemValue(ItemClass.GetItem(_randomItem, false).type, false);
         int[]     _itemData;
         if (Dict.TryGetValue(_randomItem, out _itemData))
         {
             int _count = 0;
             if (_itemData[0] > _itemData[1])
             {
                 _count = random.Next(_itemData[1], _itemData[0] + 1);
             }
             else
             {
                 _count = random.Next(_itemData[0], _itemData[1] + 1);
             }
             if (_itemValue.HasQuality && _itemData[2] > 0 && _itemData[3] >= _itemData[2])
             {
                 _itemValue.Quality = random.Next(_itemData[2], _itemData[3] + 1);
             }
             var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
             {
                 entityClass     = EntityClass.FromString("item"),
                 id              = EntityFactory.nextEntityID++,
                 itemStack       = new ItemStack(_itemValue, _count),
                 pos             = GameManager.Instance.World.Players.dict[_cInfo.entityId].position,
                 rot             = new Vector3(20f, 0f, 20f),
                 lifetime        = 60f,
                 belongsPlayerId = _cInfo.entityId
             });
             GameManager.Instance.World.SpawnEntityInWorld(entityItem);
             _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackageEntityCollect>().Setup(entityItem.entityId, _cInfo.entityId));
             GameManager.Instance.World.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Despawned);
             string _phrase7;
             if (!Phrases.Dict.TryGetValue(7, out _phrase7))
             {
                 _phrase7 = "Received {ItemCount} {ItemName} from gimme.";
             }
             _phrase7 = _phrase7.Replace("{ItemCount}", _count.ToString());
             if (Dict1.TryGetValue(_randomItem, out string _name) && _name != "")
             {
                 _phrase7 = _phrase7.Replace("{ItemName}", _name);
             }
             else
             {
                 _phrase7 = _phrase7.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name);
             }
             ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase7 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
             if (Wallet.IsEnabled && Command_Cost >= 1)
             {
                 Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
             }
             PersistentContainer.Instance.Players[_cInfo.playerId].LastGimme = DateTime.Now;
             PersistentContainer.Instance.Save();
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Gimme.RandomItem: {0}", e.Message));
     }
 }
Example #6
0
 public static void MarketTele(ClientInfo _cInfo)
 {
     if (Market.Market_Position != "0,0,0" || Market.Market_Position != "0 0 0" || Market.Market_Position != "")
     {
         EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId];
         if (_player != null)
         {
             if (!Market.MarketPlayers.Contains(_cInfo.entityId))
             {
                 if (Player_Check)
                 {
                     if (Teleportation.PCheck(_cInfo, _player))
                     {
                         return;
                     }
                 }
                 if (Zombie_Check)
                 {
                     if (Teleportation.ZCheck(_cInfo, _player))
                     {
                         return;
                     }
                 }
                 if (!Teleportation.Teleporting.Contains(_cInfo.entityId))
                 {
                     Teleportation.Teleporting.Add(_cInfo.entityId);
                 }
                 int x, y, z;
                 if (Return)
                 {
                     Vector3 _position = _player.GetPosition();
                     x = (int)_position.x;
                     y = (int)_position.y;
                     z = (int)_position.z;
                     string _mposition = x + "," + y + "," + z;
                     MarketPlayers.Add(_cInfo.entityId);
                     PersistentContainer.Instance.Players[_cInfo.playerId].MarketReturnPos = _mposition;
                     Phrases.Dict.TryGetValue(252, out string _phrase252);
                     _phrase252 = _phrase252.Replace("{CommandPrivate}", ChatHook.Command_Private);
                     _phrase252 = _phrase252.Replace("{Command51}", Command51);
                     ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase252 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                 }
                 string[] _cords = Market.Market_Position.Split(',').ToArray();
                 if (int.TryParse(_cords[0], out int _x))
                 {
                     if (int.TryParse(_cords[1], out int _y))
                     {
                         if (int.TryParse(_cords[2], out int _z))
                         {
                             _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackageTeleportPlayer>().Setup(new Vector3(_x, _y, _z), null, false));
                             if (Wallet.IsEnabled && Command_Cost >= 1)
                             {
                                 Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
                             }
                             PersistentContainer.Instance.Players[_cInfo.playerId].LastMarket = DateTime.Now;
                         }
                     }
                 }
             }
             else
             {
                 Phrases.Dict.TryGetValue(250, out string _phrase250);
                 ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase250 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
             }
         }
     }
     else
     {
         Phrases.Dict.TryGetValue(254, out string _phrase254);
         ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase254 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
     }
 }
Example #7
0
 public static void GiveAnimals(ClientInfo _cInfo)
 {
     if (Animal_List.Length > 0)
     {
         string[] _animalList = { };
         if (Animal_List.Contains(","))
         {
             if (Animal_List.Contains(" "))
             {
                 Animal_List.Replace(" ", "");
             }
             _animalList = Animal_List.Split(',').ToArray();
         }
         else if (Animal_List.Contains(" "))
         {
             _animalList = Animal_List.Split(' ').ToArray();
         }
         int minRad = 0;
         int maxRad = 0;
         if (Maximum_Spawn_Radius < Minimum_Spawn_Radius)
         {
             minRad = 40;
             maxRad = 60;
         }
         else
         {
             minRad = Minimum_Spawn_Radius;
             maxRad = Maximum_Spawn_Radius;
         }
         List <string> _animalId = new List <string>();
         foreach (string i in _animalList)
         {
             _animalId.Add(i);
         }
         int _r = rnd.Next(_animalId.Count);
         int _newId;
         int.TryParse(_animalId[_r], out _newId);
         int _nextRadius = rnd.Next(minRad, maxRad + 1);
         Dictionary <int, EntityClass> .KeyCollection entityTypesCollection = EntityClass.list.Dict.Keys;
         int counter = 1;
         foreach (int i in entityTypesCollection)
         {
             EntityClass eClass = EntityClass.list[i];
             if (!eClass.bAllowUserInstantiate)
             {
                 continue;
             }
             if (_newId == counter)
             {
                 SdtdConsole.Instance.ExecuteSync(string.Format("ser {0} {1} @ {2}", _cInfo.entityId, _nextRadius, _newId), (ClientInfo)null);
             }
             counter++;
         }
         Phrases.Dict.TryGetValue(393, out string _phrase393);
         _phrase393 = _phrase393.Replace("{Radius}", _nextRadius.ToString());
         ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase393 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         if (Wallet.IsEnabled && Command_Cost >= 1)
         {
             Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
         }
         PersistentContainer.Instance.Players[_cInfo.playerId].LastAnimal = DateTime.Now;
     }
     else
     {
         Phrases.Dict.TryGetValue(394, out string _phrase394);
         ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase394 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
     }
 }
        public static void TeleVehicle(ClientInfo _cInfo, Entity _player, int _vehicle)
        {
            int _vehicleId = 0;

            if (_vehicle == 1)
            {
                _vehicleId = PersistentContainer.Instance.Players[_cInfo.playerId].BikeId;
            }
            else if (_vehicle == 2)
            {
                _vehicleId = PersistentContainer.Instance.Players[_cInfo.playerId].MiniBikeId;
            }
            else if (_vehicle == 3)
            {
                _vehicleId = PersistentContainer.Instance.Players[_cInfo.playerId].MotorBikeId;
            }
            else if (_vehicle == 4)
            {
                _vehicleId = PersistentContainer.Instance.Players[_cInfo.playerId].JeepId;
            }
            else if (_vehicle == 5)
            {
                _vehicleId = PersistentContainer.Instance.Players[_cInfo.playerId].GyroId;
            }
            if (_vehicleId != 0)
            {
                List <Entity> Entities = GameManager.Instance.World.Entities.list;
                for (int i = 0; i < Entities.Count; i++)
                {
                    Entity _entity = Entities[i];
                    if (!_entity.IsClientControlled())
                    {
                        if (_entity.entityId == _vehicleId)
                        {
                            if ((_player.position.x - _entity.position.x) * (_player.position.x - _entity.position.x) + (_player.position.z - _entity.position.z) * (_player.position.z - _entity.position.z) <= Distance * Distance)
                            {
                                if (_entity.AttachedToEntity == false)
                                {
                                    _entity.SetPosition(_player.position);
                                    if (Wallet.IsEnabled && Command_Cost >= 1)
                                    {
                                        Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
                                    }
                                    if (_vehicle == 1)
                                    {
                                        PersistentContainer.Instance.Players[_cInfo.playerId].LastBike = DateTime.Now;
                                    }
                                    if (_vehicle == 2)
                                    {
                                        PersistentContainer.Instance.Players[_cInfo.playerId].LastMiniBike = DateTime.Now;
                                    }
                                    if (_vehicle == 3)
                                    {
                                        PersistentContainer.Instance.Players[_cInfo.playerId].LastMotorBike = DateTime.Now;
                                    }
                                    if (_vehicle == 4)
                                    {
                                        PersistentContainer.Instance.Players[_cInfo.playerId].LastJeep = DateTime.Now;
                                    }
                                    if (_vehicle == 5)
                                    {
                                        PersistentContainer.Instance.Players[_cInfo.playerId].LastGyro = DateTime.Now;
                                    }
                                    PersistentContainer.Instance.Save();
                                    Phrases.Dict.TryGetValue(493, out string _phrase493);
                                    ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase493 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                                    return;
                                }
                                else
                                {
                                    Phrases.Dict.TryGetValue(496, out string _phrase496);
                                    ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase496 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                                    return;
                                }
                            }
                        }
                    }
                }
                Phrases.Dict.TryGetValue(495, out string _phrase495);
                ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase495 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
            }
            else
            {
                Phrases.Dict.TryGetValue(494, out string _phrase494);
                ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase494 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
            }
        }