Megaphon befehl will nicht funktionieren

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Huhu liebe Community,
    Ich habe mich eben mal rangesetzt einen Megaphon befehl für die Cops und Newsreporter zu machen, doch leider funktioniert er nicht so wie ich will.


    if(!strcmp(strget(cmdtext,0),"/news")) // Der Befehl
    {
    if(gTeam[playerid] == TEAM_REPORTER)
    {
    new string[128], News[128], name[MAX_PLAYER_NAME];
    News = strget(cmdtext,2);
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "Newsreporter %s : %s",name, News);
    SendClientMessageToAll(COLOR_ORANGE, string);
    }
    return 1;
    }


    Das ist der Befehl, es steht zwar an alle da "Newsreporter Blabla:" aber nicht der Text den man danach noch zu schreibt, könnt ihr mir vielleich helfen? hab schon viele sachen ausprobiert, und themen dazu find ich leider auch keine.


    Lg
    Bob


    //EDIT: Zwei Rechtschreibfehler behoben.

    Einmal editiert, zuletzt von BoB :) ()

  • Probiere es mal so


    if(!strcmp(strget(cmdtext,0),"/news")) // Der Befehl
    {
    if(gTeam[playerid] == TEAM_REPORTER)
    {
    new name1[MAX_PLAYER_NAME];
    new nachricht,string[128];
    GetPlayerName(playerid,name1,sizeof(name1));
    if(sscanf(params,"s",nachricht))return SendClientMessage(playerid, COLOR_GRAD2,"/news [TEXT]");
    format(string,sizeof(string),"[Newsreporter]%s:%s",name1,nachricht);
    SendClientMessageToAll(COLOR_ORANGE, string);
    }
    return 1;
    }


    sscanf


    stock sscanf(sstring[], format[], {Float,_}:...)
    {
    #if defined isnull
    if (isnull(sstring))
    #else
    if (sstring[0] == 0 || (sstring[0] == 1 && sstring[1] == 0))
    #endif
    {
    return format[0];
    }
    #pragma tabsize 4
    new
    formatPos = 0,
    sstringPos = 0,
    paramPos = 2,
    paramCount = numargs(),
    delim = ' ';
    while (sstring[sstringPos] && sstring[sstringPos] <= ' ')
    {
    sstringPos++;
    }
    while (paramPos < paramCount && sstring[sstringPos])
    {
    switch (format[formatPos++])
    {
    case '\0':
    {
    return 0;
    }
    case 'i', 'd':
    {
    new
    neg = 1,
    num = 0,
    ch = sstring[sstringPos];
    if (ch == '-')
    {
    neg = -1;
    ch = sstring[++sstringPos];
    }
    do
    {
    sstringPos++;
    if ('0' <= ch <= '9')
    {
    num = (num * 10) + (ch - '0');
    }
    else
    {
    return -1;
    }
    }
    while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
    setarg(paramPos, 0, num * neg);
    }
    case 'h', 'x':
    {
    new
    num = 0,
    ch = sstring[sstringPos];
    do
    {
    sstringPos++;
    switch (ch)
    {
    case 'x', 'X':
    {
    num = 0;
    continue;
    }
    case '0' .. '9':
    {
    num = (num << 4) | (ch - '0');
    }
    case 'a' .. 'f':
    {
    num = (num << 4) | (ch - ('a' - 10));
    }
    case 'A' .. 'F':
    {
    num = (num << 4) | (ch - ('A' - 10));
    }
    default:
    {
    return -1;
    }
    }
    }
    while ((ch = sstring[sstringPos]) > ' ' && ch != delim);
    setarg(paramPos, 0, num);
    }
    case 'c':
    {
    setarg(paramPos, 0, sstring[sstringPos++]);
    }
    case 'f':
    {


    new changestr[16], changepos = 0, strpos = sstringPos;
    while(changepos < 16 && sstring[strpos] && sstring[strpos] != delim)
    {
    changestr[changepos++] = sstring[strpos++];
    }
    changestr[changepos] = '\0';
    setarg(paramPos,0,_:floatstr(changestr));
    }
    case 'p':
    {
    delim = format[formatPos++];
    continue;
    }
    case '\'':
    {
    new
    end = formatPos - 1,
    ch;
    while ((ch = format[++end]) && ch != '\'') {}
    if (!ch)
    {
    return -1;
    }
    format[end] = '\0';
    if ((ch = strfind(sstring, format[formatPos], false, sstringPos)) == -1)
    {
    if (format[end + 1])
    {
    return -1;
    }
    return 0;
    }
    format[end] = '\'';
    sstringPos = ch + (end - formatPos);
    formatPos = end + 1;
    }
    case 'u':
    {
    new
    end = sstringPos - 1,
    id = 0,
    bool:num = true,
    ch;
    while ((ch = sstring[++end]) && ch != delim)
    {
    if (num)
    {
    if ('0' <= ch <= '9')
    {
    id = (id * 10) + (ch - '0');
    }
    else
    {
    num = false;
    }
    }
    }
    if (num && IsPlayerConnected(id))
    {
    setarg(paramPos, 0, id);
    }
    else
    {
    #if !defined foreach
    #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
    #define __SSCANF_FOREACH__
    #endif
    sstring[end] = '\0';
    num = false;
    new
    name[MAX_PLAYER_NAME];
    id = end - sstringPos;
    foreach (Player, playerid)
    {
    GetPlayerName(playerid, name, sizeof (name));
    if (!strcmp(name, sstring[sstringPos], true, id))
    {
    setarg(paramPos, 0, playerid);
    num = true;
    break;
    }
    }
    if (!num)
    {
    setarg(paramPos, 0, INVALID_PLAYER_ID);
    }
    sstring[end] = ch;
    #if defined __SSCANF_FOREACH__
    #undef foreach
    #undef __SSCANF_FOREACH__
    #endif
    }
    sstringPos = end;
    }
    case 's', 'z':
    {
    new
    i = 0,
    ch;
    if (format[formatPos])
    {
    while ((ch = sstring[sstringPos++]) && ch != delim)
    {
    setarg(paramPos, i++, ch);
    }
    if (!i)
    {
    return -1;
    }
    }
    else
    {
    while ((ch = sstring[sstringPos++]))
    {
    setarg(paramPos, i++, ch);
    }
    }
    sstringPos--;
    setarg(paramPos, i, '\0');
    }
    default:
    {
    continue;
    }
    }
    while (sstring[sstringPos] && sstring[sstringPos] != delim && sstring[sstringPos] > ' ')
    {
    sstringPos++;
    }
    while (sstring[sstringPos] && (sstring[sstringPos] == delim || sstring[sstringPos] <= ' '))
    {
    sstringPos++;
    }
    paramPos++;
    }
    do
    {
    if ((delim = format[formatPos++]) > ' ')
    {
    if (delim == '\'')
    {
    while ((delim = format[formatPos++]) && delim != '\'') {}
    }
    else if (delim != 'z')
    {
    return delim;
    }
    }
    }
    while (delim > ' ');
    return 0;
    }

  • oh fuck jo des is weil ich ocmd benutze..


    Hier is der cmd nur als ocmd


    ocmd.inc



    ocmd:news(playerid,params[])
    {
    if(gTeam[playerid] == TEAM_REPORTER)
    {
    new name1[MAX_PLAYER_NAME];
    new nachricht,string[128];
    GetPlayerName(playerid,name1,sizeof(name1));
    if(sscanf(params,"s",nachricht))return SendClientMessage(playerid, COLOR_GRAD2,"/news [TEXT]");
    format(string,sizeof(string),"[Newsreporter]%s:%s",name1,nachricht);
    SendClientMessageToAll(COLOR_ORANGE, string);
    }
    return 1;
    }

    Einmal editiert, zuletzt von xuNsHiNe ()

  • Danke hat geholfen, nun komm noch ein warning.


    C:\Users\Patrick\Desktop\San Andreas Server\gamemodes\Patricksreallife.pwn(4778) : warning 203: symbol is never used: "news"


    LG
    Bob


    //EDIT: Hab es gerade inGame ausgetestet, funktioniert leider nicht, liegt wohl am Warning.

  • Drück Strg+F und such nach news
    Und wenn du nen new news findest machste den weg.^^

  • Der Befehl würde schon funktionieren aber du musst beachten:


  • if(!strcmp(strget(cmdtext,0),"/news")) // Der Befehl
    {
    if(gTeam[playerid] == TEAM_REPORTER)
    {
    new name1[MAX_PLAYER_NAME];
    new nachricht[128],string[128];
    GetPlayerName(playerid,name1,sizeof(name1));
    if(sscanf(cmdtext,"s",nachricht))return SendClientMessage(playerid, COLOR_GRAD2,"/news [TEXT]");
    format(string,sizeof(string),"[Newsreporter]%s:%s",name1,nachricht);
    SendClientMessageToAll(COLOR_ORANGE, string);
    }
    return 1;
    }


    wobei ich die nutzung von zcmd besser find :D

  • danke für den Befehl :)


    Ja die sache ist ich hab mich nun schon so daran gewöhnt, und wollt erstma alles wichtige soweit lernen, bevor ich mich da dransetz,


    Also bei mir siehts so aus ich gebe ein


    /news Hallo


    dann steht dort:


    Newsreporter Bob: /news Hallo


    Ich muss sagen ich hab "COLOR GRAD2" in Rot umgeändert kann es daran liegen?, weil ich GRAD2 oben nicht definiert habe.


    LG
    Bob


    EDIT:

    Zitat

    ?? Noch eine Frage: verwendest du das Sscanf Plugin?

    Ja habe ich drinnen :)