Frage zu DCMD und Strcmp

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
  • Hallo


    Ich habe hier ein Codestück, weiss jedoch nicht, wohin ich das einauen muss, da ich momentan nur DCMD kenne.


    if(strcmp(cmd, "/f", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = cmdtext[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "Hinweis: /f [Text]");
    return true;
    }
    if (PlayerInfo[playerid][pTeam] != 0)
    {
    if(PlayerInfo[playerid][pMember] != 0)
    {
    format(string, sizeof(string), " Fraktion %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pMember], COLOR_YELLOW, sstring);
    return 1;
    }
    if(PlayerInfo[playerid][pLeader] != 0)
    {
    format(string, sizeof(string), " Fraktion (Leader) %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pLeader], COLOR_YELLOW, sstring);
    return 1;
    }
    }
    else
    {
    SendClientMessage(playerid, COLOR_RED, "Du bist in keiner Fraktion");
    }
    }
    return true;
    }



    MfG dUDALUS

  • Hallo


    Bei mir sieht es so aus:


    public OnPlayerCommandText(playerid, cmdtext[])
    {
    dcmd(givelic,7,cmdtext);
    dcmd(s,1,cmdtext);
    dcmd(pay,3,cmdtext);
    dcmd(job,3,cmdtext);
    dcmd(buylotto,8,cmdtext);
    dcmd(wtime,5,cmdtext);
    dcmd(tanken,6,cmdtext);
    dcmd(opfer,5,cmdtext);
    dcmd(auftrag,7,cmdtext);
    dcmd(resetskin,9,cmdtext);
    dcmd(gate,4,cmdtext);
    dcmd(member,6,cmdtext);
    dcmd(leave,5,cmdtext);
    dcmd(take,4,cmdtext);
    dcmd(lizenzen,8,cmdtext);
    dcmd(showlizenz,10,cmdtext);
    dcmd(lizenz,6,cmdtext);
    dcmd(start,5,cmdtext);
    dcmd(stop,4,cmdtext);
    dcmd(ann,3,cmdtext);
    dcmd(clearwanted,11,cmdtext);
    dcmd(sms,3,cmdtext);
    dcmd(makesupport,11,cmdtext);
    dcmd(cancel,6,cmdtext);
    dcmd(accept,6,cmdtext);
    dcmd(ticket,6,cmdtext);
    dcmd(check,5,cmdtext);
    dcmd(buylevel,8,cmdtext);
    dcmd(duty,4,cmdtext);
    dcmd(durchsuchen,11,cmdtext);
    dcmd(wanteds,7,cmdtext);
    dcmd(verhaften,9,cmdtext);
    dcmd(fahnden,7,cmdtext);
    dcmd(einsperren,10,cmdtext);
    dcmd(megafon,7,cmdtext);
    dcmd(rnachricht,10,cmdtext);
    dcmd(tazer,5,cmdtext);
    dcmd(sperre,6,cmdtext);
    dcmd(enter,5,cmdtext);
    dcmd(exit,4,cmdtext);
    dcmd(q,1,cmdtext);
    dcmd(invite,6,cmdtext);
    dcmd(uninvite,8,cmdtext);
    dcmd(leaderhelp,10,cmdtext);
    dcmd(adminhelp,9,cmdtext);
    dcmd(admins,6,cmdtext);
    dcmd(clear,5,cmdtext);
    dcmd(veh,3,cmdtext);
    dcmd(vehid,5,cmdtext);
    dcmd(lehrer,6,cmdtext);
    dcmd(stats,5,cmdtext);
    dcmd(essen,5,cmdtext);
    dcmd(waffen,6,cmdtext);
    dcmd(sexshop,7,cmdtext);
    dcmd(help,4,cmdtext);
    dcmd(bankhelp,8,cmdtext);
    dcmd(atmeinzahlen,12,cmdtext);
    dcmd(atmabheben,10,cmdtext);
    dcmd(atmtransferieren,16,cmdtext);
    dcmd(makeleader,10,cmdtext);
    dcmd(heilen,6,cmdtext);
    dcmd(reparieren,10,cmdtext);
    dcmd(ban,3,cmdtext);
    dcmd(kick,4,cmdtext);
    dcmd(o,1,cmdtext);
    dcmd(chatlock,8,cmdtext);
    dcmd(chatunlock,10,cmdtext);
    dcmd(makeadmin,9,cmdtext);
    dcmd(goto,4,cmdtext);
    dcmd(gethere,7,cmdtext);
    dcmd(setstat,7,cmdtext);
    dcmd(slap,4,cmdtext);
    dcmd(freeze,6,cmdtext);
    dcmd(mute,4,cmdtext);
    dcmd(geldlos,7,cmdtext);
    dcmd(delveh,6,cmdtext);
    dcmd(report,6,cmdtext);
    dcmd(a,1,cmdtext);
    dcmd(ad,2,cmdtext);
    dcmd(givegun,7,cmdtext);
    dcmd(givemoney,9,cmdtext);
    dcmd(fixveh,6,cmdtext);
    dcmd(setint,6,cmdtext);
    dcmd(tv,2,cmdtext);
    dcmd(tvoff,5,cmdtext);
    dcmd(mapport,7,cmdtext);
    dcmd(unmapport,9,cmdtext);
    dcmd(banip,5,cmdtext);
    dcmd(unbanip,7,cmdtext);
    dcmd(kickall,7,cmdtext);
    dcmd(healall,7,cmdtext);
    dcmd(einzahlen,9,cmdtext);
    dcmd(abheben,7,cmdtext);
    dcmd(transferieren,13,cmdtext);
    dcmd(giverank,8,cmdtext);
    dcmd(register,8,cmdtext);
    dcmd(login,5,cmdtext);
    dcmd(gotocar,7,cmdtext);
    dcmd(getcar,6,cmdtext);

    if(strcmp(cmd, "/f", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = cmdtext[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "Hinweis: /f [Text]");
    return true;
    }
    if (PlayerInfo[playerid][pTeam] != 0)
    {
    if(PlayerInfo[playerid][pMember] != 0)
    {
    format(string, sizeof(string), " Fraktion %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pMember], COLOR_YELLOW, sstring);
    return 1;
    }
    if(PlayerInfo[playerid][pLeader] != 0)
    {
    format(string, sizeof(string), " Fraktion (Leader) %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pLeader], COLOR_YELLOW, sstring);
    return 1;
    }
    }
    else
    {
    SendClientMessage(playerid, COLOR_RED, "Du bist in keiner Fraktion");
    }
    }
    return true;
    }
    }


    C:\Users\X\Desktop\dudalus124.pwn(2327) : warning 217: loose indentation
    C:\Users\X\Desktop\dudalus124.pwn(2327) : error 017: undefined symbol "cmd"
    C:\Users\X\Desktop\dudalus124.pwn(2331) : error 017: undefined symbol "sendername"
    C:\Users\X\Desktop\dudalus124.pwn(2331) : error 017: undefined symbol "sendername"
    C:\Users\X\Desktop\dudalus124.pwn(2331) : error 029: invalid expression, assumed zero
    C:\Users\X\Desktop\dudalus124.pwn(2331) : fatal error 107: too many error messages on one line


    Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase



    5 Errors.


    Bin grade etwas ratlos^^


    MfG dUDALUS


    Edit: Möchte mich für die Formatierung entschuldigen.

  • if(strcmp(cmdtext, "/f", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = cmdtext[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "Hinweis: /f [Text]");
    return true;
    }
    if (PlayerInfo[playerid][pTeam] != 0)
    {
    if(PlayerInfo[playerid][pMember] != 0)
    {
    format(string, sizeof(string), " Fraktion %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pMember], COLOR_YELLOW, sstring);
    return 1;
    }
    if(PlayerInfo[playerid][pLeader] != 0)
    {
    format(string, sizeof(string), " Fraktion (Leader) %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pLeader], COLOR_YELLOW, sstring);
    return 1;
    }
    }
    else
    {
    SendClientMessage(playerid, COLOR_RED, "Du bist in keiner Fraktion");
    }
    }
    return true;
    }
    }
    Versuchs mal so.

  • Hallo


    Ohne die new bekomme ich Fehler, wenn ich sie jedoch dazuschreibe, geht ingame der /f garnicht, da der Server den Command nicht kennt. Könntest du mir schnell helfen ?


    new string[256];
    new sstring[256];
    new cmd[256];
    new sendername[MAX_PLAYER_NAME];
    new idx;
    if(strcmp(cmdtext, "/f", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = cmdtext[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "Hinweis: /f [Text]");
    return true;
    }
    if (PlayerInfo[playerid][pTeam] != 0)
    {
    if(PlayerInfo[playerid][pMember] != 0)
    {
    format(string, sizeof(string), " Fraktion %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pMember], COLOR_YELLOW, sstring);
    return 1;
    }
    if(PlayerInfo[playerid][pLeader] != 0)
    {
    format(string, sizeof(string), " Fraktion (Leader) %s: %s. )) ", sendername, string);
    SendFamilyMessage(PlayerInfo[playerid][pLeader], COLOR_YELLOW, sstring);
    return 1;
    }
    }
    else
    {
    SendClientMessage(playerid, COLOR_RED, "Du bist in keiner Fraktion");
    }
    }
    return true;
    }
    }


    C:\Users\X\Desktop\dudalus124.pwn(2338) : warning 219: local variable "sendername" shadows a variable at a preceding level
    C:\Users\X\Desktop\dudalus124.pwn(2332) : warning 204: symbol is assigned a value that is never used: "sendername"
    C:\Users\X\Desktop\dudalus124.pwn(2331) : warning 204: symbol is assigned a value that is never used: "cmd"
    C:\Users\X\Desktop\dudalus124.pwn(2331 -- 2380) : warning 209: function "JB_OnPlayerCommandText" should return a value
    C:\Users\X\Desktop\dudalus124.pwn(9087) : warning 217: loose indentation
    C:\Users\X\Desktop\dudalus124.pwn(9563) : warning 202: number of arguments does not match definition
    Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase



    6 Warnings.


    Funktioniert so nicht. Ich habe die nicht benötigten new`s mal drinnengelassen


    MfG dUDALUS