Splitting chat lines
#1

I've found other topics on how to split lines barely, but it doesn't match what i want, it's always different and they dont explain it, so i have no idea how to edit it to fit into my script...

Basically what i want is that if a player makes a too long chat line, instead of cutting it off, then sending another message with the rest of the message.

Ethically:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ..-
-.. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

(But without making 3 lines or more, max 2.)

This is some of my OnPlayerText (I dont think the rest is required.)
pawn Code:
public OnPlayerText(playerid, text[])
{
    if(USE_ANTI_SPAM == true)
    {
        if(pMuted[playerid] == true)
        {
            SendClientMessage(playerid, COLOR_RED, "{539600}[ANTI-CHEAT]{74D400} You have been muted for spamming the chat.");
            return 0;
        }
        new AnimR = random(1);
        if(AnimR == 0 && !IsPlayerInAnyVehicle(playerid) || !gPlayerUsingLoopingAnim[playerid] || !IsPlayerCuffed(playerid))
        //if(gPlayerUsingLoopingAnim[playerid]) return;
        //if(IsPlayerCuffed(playerid)) return;
        {
            ApplyAnimation(playerid, "PED", "IDLE_CHAT", 4.0, 1, 0, 0, 1, 1);
            SetTimerEx("SpeakAnim", strlen(text)*200, false, "i", playerid);
        }
        else if(AnimR == 1 && !IsPlayerInAnyVehicle(playerid))
        {
            ApplyAnimation(playerid, "PED", "Idle_Chat_02", 4.0, 1, 0, 0, 1, 1);
            SetTimerEx("SpeakAnim", strlen(text)*100, false, "i", playerid);
        }
        /*new Length = strlen(text);
        new aTime = Length*400;
        //ApplyAnimation(playerid,"PED","factalk",4.1,0, 0, 0, 0, aTime);
        ApplyAnimation(playerid, "PED", "IDLE_CHAT",4.1,0,0,0,1,aTime);*/

        //--
        pLineCount[playerid]++;
        SetTimerEx("LineCountReset", 2000, 0, "i", playerid);
        if(pLineCount[playerid] >= MAX_MESSAGES)
        {
            pMuted[playerid] = true;
            SetTimerEx("Unmute", 20000, 0, "i", playerid);
        }
    }
    //if (IsAfterLifing[playerid] == 1) { return 0; }
    if(PlayerInfo[playerid][pMute] == 1)
    {
        SendClientMessage(playerid, COLOR_GREY, "You cannot speak, you have been muted.");
        return 0;
    }
    // Anti Adv
    if(AntiAdv(playerid, text)) return 0;
    // The Rest
    new string[128];
    // Normal Calling
    if(BeingCalled[playerid] == 2 || Calling[playerid] == 2 || Call911[playerid])
    {
        if(strlen(PlayerInfo[playerid][pAccent])) format(string, sizeof(string), "[Cellphone] [%s Accent]: %s", PlayerInfo[playerid][pAccent], text);
        else format(string, sizeof(string), "[Cellphone]: %s", text);
        SendCopMessage(COLOR_RADAR, string);
        SendRCSDMessage(COLOR_RADAR, string);
        SendFBIMessage(COLOR_RADAR, string);
        SendSWATMessage(COLOR_RADAR, string);
        if(!Call911[playerid])
        {
            if(BeingCalled[playerid] == 2) SendClientMessage(Caller[playerid], COLOR_YELLOW, string);
            else if(Calling[playerid] == 2) SendClientMessage(Called[playerid], COLOR_YELLOW, string);
        }
    }
    else if(Live[playerid])
    {
        if(IsNewsVehicle(GetPlayerVehicleID(playerid)))
        {
            format(string, sizeof(string), "** (Live News): %s: %s", RPN(playerid), text);
            SendClientMessageToAll(COLOR_LIGHTGREEN, string);
        }
    }
    else
    {
        if(strlen(PlayerInfo[playerid][pAccent])) format(string, sizeof(string), "%s [%s Accent] says: %s", RPN(playerid), PlayerInfo[playerid][pAccent], text);
        else format(string, sizeof(string), "%s says: %s", RPN(playerid), text);
        SetPlayerChatBubble(playerid,string,COLOR_WHITE,15.0,4000);
Reply
#2

Bump.
Reply
#3

It is not difficult, it is simple, you should learn how to use strings, strmid, strdel and strlen. Here is an example.

pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>


public OnPlayerText(playerid, text[])
{
    new chat_text[144];
    format(chat_text, sizeof(chat_text), "%s(%d): %s", Name(playerid), playerid, text);
   
    if(strlen(chat_text) < 72) // 1/2
    {
        SendClientMessageToAll(-1, chat_text);
    }
    else if(strlen(chat_text) > 72) // +1/2
    {
        new chat_line[2][73];
        strmid(chat_line[0], chat_text, 0, 72, 72);
        SendClientMessageToAll(-1, chat_line[0]);
        strmid(chat_line[1], chat_text, 73, 144, 72);
        SendClientMessageToAll(-1, chat_line[1]);
        strdel(chat_text, 0, 144);
        return false;
    }
    return true;
}

stock Name(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, 24);
    return name;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)