Example #1
0
        [ServerEvent(Event.ChatMessage)] // TODO: review cancel events
        public void OnChatMessage(Client player, string msg)
        {
            if (msg.StartsWith('/'))
            {
                if (msg.EndsWith("login") || msg.EndsWith("register"))
                {
                    return;
                }
            }

            Account   account   = player.GetAccount();
            Character character = player.GetCharacter();

            if (account == null || character == null || account.IsLoggedIn == false)
            {
                //e.Cancel = true;
                return;
            }

            if (character.IsRagged)
            {
                NAPI.Chat.SendChatMessageToPlayer(player, "You are ragged.");
                //e.Cancel = true;
                return;
            }

            if (NAPI.Data.HasEntityData(player, "MegaphoneStatus"))
            {
                if (NAPI.Data.GetEntityData(player, "MegaphoneStatus") == true)
                {
                    msg = "~y~[MEGAPHONE] " + character.rp_name() + " says: " + msg;
                    NearbyMessage(player, 30, msg);
                    //e.Cancel = true;
                    LogManager.Log(LogManager.LogTypes.ICchat,
                                   "[MEGAPHONE] " + character.CharacterName + $"[{account.AccountName}]" + " says: " + msg);
                    return;
                }
            }

            if (NAPI.Data.HasEntityData(player, "MicStatus"))
            {
                if (NAPI.Data.GetEntityData(player, "MicStatus") == true)
                {
                    msg = "~p~ [BROADCAST] " + character.rp_name() + " : " + msg;
                    BroadcastMessage(msg);
                    NearbyMessage(player, 30, msg);
                    //e.Cancel = true;
                    LogManager.Log(LogManager.LogTypes.ICchat, "[BROADCAST] " + character.CharacterName + $"[{account.AccountName}]" + " says: " + msg);
                    return;
                }
            }

            //Phone
            if (account.AdminDuty == false && character.InCallWith != Character.None)
            {
                Character talkingTo = character.InCallWith;
                string    phonemsg;
                var       charitems   = InventoryManager.DoesInventoryHaveItem(character, typeof(Phone));
                var       targetitems = InventoryManager.DoesInventoryHaveItem(character, typeof(Phone));
                var       charphone   = (Phone)charitems[0];
                var       targetphone = (Phone)targetitems[0];
                var       newmsg      = "[Phone]" + character.rp_name() + " says: " + msg;
                ChatManager.NearbyMessage(player, 15, newmsg, Color.Grey);
                if (targetphone.HasContactWithNumber(charphone.PhoneNumber))
                {
                    phonemsg = "[" + targetphone.Contacts.Find(pc => pc.Number == charphone.PhoneNumber).Name + "]" +
                               character.rp_name() + " says: " + msg;
                }
                else
                {
                    phonemsg = "[" + charphone.PhoneNumber + "]" + character.rp_name() + " says: " + msg;
                }
                NAPI.Chat.SendChatMessageToPlayer(talkingTo.Client, Color.Grey, phonemsg);
                //e.Cancel = true;
                //e.Reason = "Phone";
                LogManager.Log(LogManager.LogTypes.Phone, $"[Phone] {character.CharacterName}[{account.AccountName}] To {talkingTo.CharacterName}[{talkingTo.Client.SocialClubName}]: {msg}");
                return;
            }
            else if (account.AdminDuty == false && character.Calling911 == true)
            {
                //API.GetZoneName(player.Position);

                var charitems = InventoryManager.DoesInventoryHaveItem(character, typeof(Phone));
                var charphone = (Phone)charitems[0];

                Mdc.Add911Call(charphone.PhoneNumber, msg, "Los Santos");

                var newmsg = "[Phone]" + character.rp_name() + " says: " + msg;
                ChatManager.NearbyMessage(player, 15, newmsg, Color.Grey);

                NAPI.Chat.SendChatMessageToPlayer(player, Color.Grey, "911 Operator says: Thank you for reporting your emergency, a unit will be dispatched shortly.");
                PhoneManager.h_cmd(player);
                group_manager.lspd.Lspd.SendToCops(player, $"~r~911: #{charphone.PhoneNumber} reported a crime: {msg}");
                //e.Cancel = true;
                //e.Reason = "Phone";
                LogManager.Log(LogManager.LogTypes.Phone, $"[Phone] {character.CharacterName}[{account.AccountName}] To LSPD(911): {msg}");
                return;
            }

            if (account.AdminDuty == false)
            {
                msg = character.rp_name() + " says: " + msg;
                NearbyMessage(player, 15, msg);
                LogManager.Log(LogManager.LogTypes.ICchat, $"{character.CharacterName}[{account.AccountName}] says: {msg}");
                //e.Cancel = true;
            }
            else
            {
                b_cmd(player, msg);

                //Not sure where to log this so just why not both lmao
                LogManager.Log(LogManager.LogTypes.ICchat, $"((Admin {account.AdminName} says: {msg}))");
                LogManager.Log(LogManager.LogTypes.OOCchat, $"((Admin {account.AdminName} says: {msg}))");

                //e.Cancel = true;
            }
        }