Announce Help
#1

can someone code me for announce ?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=174322

No idea if the one in there will work but use search if you want to find some more.
Reply
#3

Quote:
Originally Posted by doreto
View Post
can someone code me for announce ?
Here's one basic:
pawn Code:
if(strcmp(cmd, "/announce", true) == 0)
    {
                new cmd[128], idx;
                cmd = strtok(cmdtext, idx);
                new tmp[256],tmp2[256];
                #pragma unused tmp
                #pragma unused tmp2
            #pragma unused idx
        new name[MAX_PLAYER_NAME],string[128];
        GetPlayerName(playerid,name,sizeof(name));
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, 0x00FF40FF, "USAGE: /announce <text>");
        format(string,sizeof(string),"%s: %s",name,cmdtext[10]);
        GameTextForAll(string,2000,5);
        return 1;
                stock strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

    }
Reply
#4

Quote:
Originally Posted by blackwave
View Post
Here's one basic:
pawn Code:
if(strcmp(cmd, "/announce", true) == 0)
    {
                new cmd[128], idx;
                cmd = strtok(cmdtext, idx);
                new tmp[256],tmp2[256];
                #pragma unused tmp
                #pragma unused tmp2
            #pragma unused idx
        new name[MAX_PLAYER_NAME],string[128];
        GetPlayerName(playerid,name,sizeof(name));
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, 0x00FF40FF, "USAGE: /announce <text>");
        format(string,sizeof(string),"%s: %s",name,cmdtext[10]);
        GameTextForAll(string,2000,5);
        return 1;
                stock strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

    }
lol full wich errors
Reply
#5

pawn Code:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(announce, 8, cmdtext);
    return 0;
}
dcmd_announce(playerid,params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, 0x21DD00FF,"USAGE: /announce [Text]");
    return GameTextForAll(params,4000,3);
}
Reply
#6

Quote:
Originally Posted by doreto
View Post
lol full wich errors
Put:
pawn Code:
if(strcmp(cmd, "/announce", true) == 0)
    {
                new cmd[128], idx;
                cmd = strtok(cmdtext, idx);
                new tmp[256],tmp2[256];
                #pragma unused tmp
                #pragma unused tmp2
            #pragma unused idx
        new name[MAX_PLAYER_NAME],string[128];
        GetPlayerName(playerid,name,sizeof(name));
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, 0x00FF40FF, "USAGE: /announce <text>");
        format(string,sizeof(string),"%s: %s",name,cmdtext[10]);
        GameTextForAll(string,2000,5);
        return 1;
    }
OnPlayerCommandText inside


Put:
pawn Code:
stock strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Anywhere else, except on a callback inside

My result:
Code:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase
Reply
#7

Well zcmd n dcmd's faster.

pawn Code:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(announce, 8, cmdtext);
    return 0;
}
dcmd_announce(playerid,params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, 0x21DD00FF,"USAGE: /announce [Text]");
    return GameTextForAll(params,4000,3);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)