public static void sms_cmd(Player player, string input, string message) { Character sender = player.GetCharacter(); var targetitems = InventoryManager.DoesInventoryHaveItem(sender, typeof(Phone)); if (targetitems.Length == 0) { API.Shared.SendChatMessageToPlayer(player, "You don't have a phone."); return; } var senderphone = (Phone)targetitems[0]; if (senderphone.IsOn == false) { API.Shared.SendChatMessageToPlayer(player, "Your phone is turned off."); return; } if (IsDigitsOnly(input)) // this is if player puts a number { if (!DoesNumberExist(input)) { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. (Phone number is not registered.)"); return; } var character = GetPlayerWithNumber(input); if (character != null) { var charphone = InventoryManager.DoesInventoryHaveItem <Phone>(character)[0]; if (!charphone.IsOn) { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. That number is switched off. Please try again later."); return; } API.Shared.TriggerClientEvent(character.Player, "phone_incomingMessage", charphone.HasContactWithNumber(senderphone.PhoneNumber) ? charphone.Contacts.Find(pc => pc.Number == senderphone.PhoneNumber).Name : senderphone.PhoneNumber, message); API.Shared.SendChatMessageToPlayer(character.Player, Color.Sms, "You've received an SMS."); ChatManager.RoleplayMessage(character, "'s phone vibrates..", ChatManager.RoleplayMe); } else { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. (Phone number is not online.)"); return; } string toMsg; if (senderphone.HasContactWithNumber(input)) { toMsg = "SMS to " + senderphone.Contacts.Find(pc => pc.Number == input).Name + ": " + message; } else { toMsg = "SMS to " + input + ": " + message; } API.Shared.SendChatMessageToPlayer(sender.Player, Color.Sms, toMsg); ChatManager.AmeLabelMessage(player, "presses a few buttons on their phone, sending a message.", 4000); Phone.LogMessage(senderphone.PhoneNumber, input, message); API.Shared.TriggerClientEvent(player, "phone_messageSent"); } else { if (!senderphone.HasContactWithName(input)) { API.Shared.SendChatMessageToPlayer(player, Color.White, "You do not have a contact with the name: " + input); return; } var contact = senderphone.Contacts.Find(pc => string.Equals(pc.Name, input, StringComparison.OrdinalIgnoreCase)); if (!DoesNumberExist(contact.Number)) { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. (Phone number is not registered.)"); return; } var character = GetPlayerWithNumber(contact.Number); if (character != null) { var charphone = InventoryManager.DoesInventoryHaveItem <Phone>(character)[0]; if (!charphone.IsOn) { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. That number is switched off. Please try again later."); return; } API.Shared.TriggerClientEvent(character.Player, "phone_incomingMessage", charphone.HasContactWithNumber(senderphone.PhoneNumber) ? charphone.Contacts.Find(pc => pc.Number == senderphone.PhoneNumber).Name : senderphone.PhoneNumber, message); API.Shared.SendChatMessageToPlayer(character.Player, Color.Sms, "You've received an SMS."); ChatManager.RoleplayMessage(character, "'s phone vibrates..", ChatManager.RoleplayMe); var toMsg = "SMS to " + contact.Name + ": " + message; API.Shared.SendChatMessageToPlayer(sender.Player, Color.Sms, toMsg); ChatManager.AmeLabelMessage(player, "presses a few buttons on their phone, sending a message.", 4000); Phone.LogMessage(senderphone.PhoneNumber, contact.Number, message); API.Shared.TriggerClientEvent(player, "phone_messageSent"); } else { API.Shared.SendChatMessageToPlayer(player, Color.White, "The text message failed to send. ((Phone number is not online.))"); } } }
public void call_cmd(Player player, string input) { Character sender = player.GetCharacter(); var targetitems = InventoryManager.DoesInventoryHaveItem(sender, typeof(Phone)); if (targetitems.Length == 0) { NAPI.Chat.SendChatMessageToPlayer(player, "You don't have a phone."); return; } var senderphone = (Phone)targetitems[0]; if (senderphone.IsOn == false) { NAPI.Chat.SendChatMessageToPlayer(player, "Your phone is turned off."); return; } if (IsDigitsOnly(input)) { if (input.Equals("911", StringComparison.OrdinalIgnoreCase)) { ChatManager.AmeLabelMessage(player, "takes out their phone and presses a few numbers..", 4000); sender.Calling911 = true; NAPI.Chat.SendChatMessageToPlayer(player, Color.Grey, "911 Operator says: Los Santos Police Department, what is the nature of your emergency?"); NAPI.ClientEvent.TriggerClientEvent(player, "phone_calling", "LSPD", input); return; } if (!DoesNumberExist(input)) { NAPI.Chat.SendChatMessageToPlayer(player, Color.White, "The call failed to connect. (Phone number is not registered.)"); return; } var character = GetPlayerWithNumber(input); if (character == null) { NAPI.Chat.SendChatMessageToPlayer(player, Color.White, "The call failed to connect. ((No one online found with that phone number))"); return; } var charphone = InventoryManager.DoesInventoryHaveItem <Phone>(character)[0]; if (charphone.IsOn == false) { NAPI.Chat.SendChatMessageToPlayer(player, Color.Yellow, "The number you are trying to reach is currently unavailable."); return; } if (character.BeingCalledBy != Character.None || character.CallingPlayer != Character.None || character.InCallWith != Character.None) { NAPI.Chat.SendChatMessageToPlayer(player, Color.Yellow, "The line you're trying to call is busy."); return; } ChatManager.AmeLabelMessage(player, "takes out their phone and presses a few numbers..", 4000); NAPI.Chat.SendChatMessageToPlayer(character.Player, "Incoming call from " + senderphone.PhoneNumber + "..."); ChatManager.RoleplayMessage(character, "'s phone starts to ring...", ChatManager.RoleplayMe); sender.CallingPlayer = character; character.BeingCalledBy = sender; var contact = senderphone.Contacts.Find(pc => pc.Number == input); var targetContact = charphone.Contacts.Find(pc => pc.Number == senderphone.PhoneNumber); NAPI.ClientEvent.TriggerClientEvent(player, "phone_calling", contact?.Name ?? "Unknown", input); NAPI.ClientEvent.TriggerClientEvent(character.Player, "phone_incoming-call", targetContact?.Name ?? "Unknown", senderphone.PhoneNumber); sender.CallingTimer = new System.Threading.Timer(OnCallSemiEnd, new[] { character, sender }, 30000, -1); } else { if (!senderphone.HasContactWithName(input)) { NAPI.Chat.SendChatMessageToPlayer(player, Color.White, "You do not have a contact with the name: " + input); return; } var contact = senderphone.Contacts.Find(pc => string.Equals(pc.Name, input, StringComparison.OrdinalIgnoreCase)); var character = GetPlayerWithNumber(contact.Number); if (character == null) { NAPI.Chat.SendChatMessageToPlayer(player, Color.White, "The call failed to connect. ((No one online found with that phone number))"); return; } var charphone = InventoryManager.DoesInventoryHaveItem <Phone>(character)[0]; if (charphone.IsOn == false) { NAPI.Chat.SendChatMessageToPlayer(player, Color.Yellow, "The number you are trying to reach is currently unavailable."); return; } if (character.BeingCalledBy != Character.None || character.CallingPlayer != Character.None || character.InCallWith != Character.None) { NAPI.Chat.SendChatMessageToPlayer(player, Color.Yellow, "The line you're trying to call is busy."); return; } ChatManager.AmeLabelMessage(player, "takes out their phone and presses a few numbers..", 4000); NAPI.Chat.SendChatMessageToPlayer(character.Player, "Incoming call from" + senderphone + "..."); ChatManager.RoleplayMessage(character, "'s phone starts to ring...", ChatManager.RoleplayMe); sender.CallingPlayer = character; character.BeingCalledBy = sender; NAPI.ClientEvent.TriggerClientEvent(player, "phone_calling", contact.Name, contact.Number); var targetContact = charphone.Contacts.Find(pc => pc.Number == senderphone.PhoneNumber); NAPI.ClientEvent.TriggerClientEvent(character.Player, "phone_incoming-call", targetContact?.Name ?? "Unknown", senderphone.PhoneNumber); //Function to hangup after 30 seconds with no answer. sender.CallingTimer = new System.Threading.Timer(OnCallSemiEnd, new[] { character, sender }, 30000, -1); } }