More Efficient way of Global Chat?
#1

I'm trying to make an efficient /ooc command but right now, I'm stuck using strtok, and with this, it cuts off the first word of whatever you type.

I want to use sscanf but I can't figure out how to make it work where its independent of what they type. For example, if I make it
pawn Code:
sscanf(params, "s", chat)
but the first character they type in is a number, it wont work, and I don't want to limit them to only starting with letters.

Thanks in advance for help, feel free to ask for any clarifications, I could have just rambled uncontrollably
Reply
#2

Post your /ooc command.
Reply
#3

I couldn't figure one out, so I took this from Raven's and (tried) to mod it for zcmd

pawn Code:
CMD:o(playerid, params[])
{
    new tmp[30], idx,length = strlen(params), Name[24], string[160];
    tmp = strtok(params, idx);
    GetPlayerName(playerid, Name, sizeof(Name));
    while ((idx < length) && (params[idx] <= ' '))
    {
        idx++;
    }
    new offset = idx;
    new result[128];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
        result[idx - offset] = params[idx];
        idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
        SendClientMessage(playerid, COLOR_RED, "[Server] Usage: /o [OOC chat]");
        return 1;
    }
    format(string, sizeof(string),"(( %s[%i]: %s ))", Name, playerid, result);
    SendClientMessageToAll(COLOR_NEUTRALBLUE, string);
    return 1;
}
Reply
#4

pawn Code:
CMD:o(playerid, params[])
{
    new Name[24], string[160];
    GetPlayerName(playerid, Name, sizeof(Name));
    new result[128];
    if(sscanf(params, "s", result)) return SendClientMessage(playerid, COLOR_RED, "[Server] Usage: /o [OOC chat]");
    format(string, sizeof(string),"(( %s[%i]: %s ))", Name, playerid, result);
    SendClientMessageToAll(COLOR_NEUTRALBLUE, string);
    return 1;
}
Reply
#5

Yeah, I knew about that, but this won't work if the first character is a number, right? I don't want to have to limit this.
Reply
#6

It should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)