Esempio n. 1
0
        public async void PlayerInit(Player player)
        {
            API.setPlayerNametag(player.Client, player.Username.Roleplay());
            API.setPlayerName(player.Client, player.Username.Roleplay());
            API.setPlayerHealth(player.Client, (int)player.Health);
            API.setPlayerArmor(player.Client, (int)player.Armour);
            API.setEntityDimension(player.Client, player.Dimension);

            player.IsInInterior = (player.Dimension > 0);
            if (player.IsInInterior)
            {
                player.PropertyIn = PropertyManager.Properties.FirstOrDefault(p => p.Dimension == player.Dimension);
            }

            Skin playerSkin = await SkinRepository.GetSkinById(player.Skin);

            API.setPlayerSkin(player.Client, (PedHash)playerSkin.Model);

            List <SkinVariations> skinVars = playerSkin.Variations();

            player.ChatIndicatorLabel       = API.createTextLabel("typing...", player.Client.position, 50, 0.35f, false, player.Dimension);
            player.ChatIndicatorLabel.color = new Color(0, 0, 0, 0);
            player.ChatIndicatorLabel.attachTo(player.Client, null, new Vector3(0, 0, 0.9f), new Vector3());

            for (int i = 0; i < 12; i++)
            {
                API.setPlayerClothes(player.Client, i, skinVars[i].Drawable, skinVars[i].Texture);
            }

            player.IsLogged = true;

            player.MasterAccount.ActiveConnectionLog.PlayerId = player.Id;
            ConnectionLogRepository.UpdateAsync(player.MasterAccount.ActiveConnectionLog);

            if (player.FactionId > 0)
            {
                player.Faction = Faction.FactionData.Single(f => f.Id == player.FactionId);
            }

            player.Weapons = await WeaponRepository.GetAllWeaponsByPlayerIdAsync(player.Id);

            foreach (Weapon w in player.Weapons)
            {
                API.givePlayerWeapon(player.Client, w.Model, w.Ammo, false, false);
            }

            player.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(player.Id);

            player.PopulateWeaponSkills();

            await player.LoadPlayerVehicles();

            foreach (Inventory i in player.Inventory)
            {
                if (i.IsPhone())
                {
                    Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(i.Value));

                    if (p.IsPrimary)
                    {
                        player.PrimaryPhone = p;
                        if (p.PoweredOn)
                        {
                            if (p.BatteryLevel > 3)
                            {
                                p.TurnOn(player.Client);
                            }
                            else
                            {
                                p.TurnOff(player.Client);
                            }
                        }
                        else
                        {
                            p.TurnOff(player.Client);
                        }
                        break;
                    }
                }
            }

            player.InEvent = PlayerEvent.None;

            player.Client.freeze(false);
            player.Client.ToggleCursorLock(false);
            player.Client.transparency = 255;
            API.sendNativeToAllPlayers(Hash.SET_CURRENT_PED_WEAPON, player.Client, (int)WeaponHash.Unarmed, true);

            Player.PlayerData.Add(player.Client, player);

            if (player.LastPosition != new Vector3(0, 0, 0))
            {
                player.Client.position = player.LastPosition;
            }

            API.triggerClientEvent(player.Client, "hasLoggedIn",
                                   ((char)player.MasterAccount.KeyCursor).ToString(),
                                   ((char)player.MasterAccount.KeyInventory).ToString(),
                                   ((char)player.MasterAccount.KeyInteract).ToString());

            API.triggerClientEvent(player.Client, "executeSkillTimer");
            API.triggerClientEvent(player.Client, "loadScoreboard");
            API.triggerClientEvent(player.Client, "initInteractionMenu");

            API.sendNativeToPlayer(player.Client, Hash.SET_CAM_AFFECTS_AIMING, player.Client, true);

            //API.sendNativeToPlayer(player.Client, Hash.SET_PED_CAN_BE_SHOT_IN_VEHICLE, player.Client, true);
            player.Client.invincible = true;

            for (int i = 0; i < 12; i++)
            {
                API.exported.doormanager.refreshDoorState(i);
            }

            UpdateNatives(player);

            PrisonManager.LoadPrisonSentenceForPlayer(player);
            OnPlayerLoggedIn(player);
        }
Esempio n. 2
0
        private async void CompleteCharCreation(Client sender)
        {
            Master master = Master.MasterData.Single(me => me.Client == sender);

            if (master.CreatingCharacter == null)
            {
                return;
            }
            Player newChar = new Player
            {
                Username        = master.CreatingCharacter.Username.Replace(" ", "_"),
                Level           = 0,
                Health          = 100,
                Armour          = 0,
                FactionId       = 0,
                FactionRank     = 0,
                WeaponSkillData = "0,0,0,0,0,0,0,0",
                DateOfBirth     = master.CreatingCharacter.DateOfBirth,
                Gender          = master.CreatingCharacter.Gender,
                MasterAccount   = master,
                MasterId        = master.Id,
                Dimension       = 0,
                TestDriveBan    = false,
                Client          = sender,
                LastPosition    = new Vector3(-697.0174, 5803.262, 17.33096),
                LastRotation    = new Vector3(0, 0, 63.30323)
            };

            List <int> AvailableSkins = new List <int>();

            AvailableSkins = GetAvailableSkins(master);
            int[] compIds     = new int[12];
            int[] textureIds  = new int[12];
            int[] drawableIds = new int[12];

            for (int i = 0; i < 12; i++)
            {
                textureIds[i]  = API.fetchNativeFromPlayer <int>(sender, Hash.GET_PED_TEXTURE_VARIATION, sender, i);
                drawableIds[i] = API.fetchNativeFromPlayer <int>(sender, Hash.GET_PED_DRAWABLE_VARIATION, sender, i);
            }

            Skin newSkin = new Skin
            {
                Model       = AvailableSkins[master.CreatingCharacter.CurrentSkinIndex],
                TextureIds  = string.Join(",", textureIds),
                DrawableIds = string.Join(",", drawableIds),
                OwnerId     = PlayerRepository.AddNewPlayer(newChar)
            };

            Master.MasterData.Single(me => me.Client == sender).Players =
                await PlayerRepository.GetAllPlayerDataByMasterAccount(master);

            Master.MasterData.Single(me => me.Client == sender).CreatingCharacter = null;

            newChar.Skin = SkinRepository.AddNewSkin(newSkin);

            PlayerRepository.UpdateAsync(newChar);

            PlayerInit(newChar);
            sender.FadeOutIn(200, 1300);
            API.triggerClientEvent(sender, "onCharCreated");
        }