sscanf Problem

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 Breadfish :)


    Mal wieder ein kleines Problem...
    Wenn ich ingame /haus eingebe, dann kommen die optionen (wie gewollt)
    wenn ich dann /haus erstellen eingebe, dann kommt wieder eine Fehlermeldung, undzwar das man den Preis vergessen hat. (auch wie gewollt)
    Wenn man aber /haus erstellen 500 eingibt, dann kommt die Fehlermeldung, das man den preis vergessen haben soll, trotzdem und es wird kein haus erstellt...


    Hier der Code:
    //------------------------------------/haus-----------------------------------//
    dcmd_haus(playerid,params[])
    {
    new option[25];
    if(sscanf(params,"s",option))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus [erstellen]");
    {
    if(strfind(option,"erstellen",true) == 0)
    {
    new Float:x,Float:y,Float:z,preis;
    if(sscanf(params,"i",preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus erstellen [Preis]");
    GetPlayerPos(playerid,x,y,z);
    CreateHaus(x,y,z,preis,"Keiner",0);
    return true;
    }
    }
    return 1;
    }


    Jemand ne idee, warum der die 2te sscanf abfrage nicht erkennt oderso?

    Mit freundlichen Grüßen,
    Cr4sh


  • dcmd_haus(playerid,params[])
    {
    new option[25], preis;
    if(sscanf(params,"sd",option, preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus [text] [miete]");
    {
    if(strcmp(option,"erstellen",true) == 0)
    {
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    CreateHaus(x,y,z,preis,"Keiner",0);
    return true;
    }
    }
    return 1;
    }

  • zeig mal den kompletten Befehl her... so wie Vincent P. es gezeigt hat ist es aber richtig...

    Mit freundlichen Grüßen
    Developer
    Go/Python Developer | ehm. Webdeveloper | Fachinformatiker Anwendungsentwicklung
    Arbeitet in einem cloudigen Umfeld bei einem der größten deutschen Rechenzentrumsbetreibern

  • Versuchs so:
    //------------------------------------/haus-----------------------------------//
    dcmd_haus(playerid,params[])
    {
    new option[25],preis;
    if(sscanf(params,"s[25]i",option,preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus [erstellen] [preis]");
    {
    if(strfind(option,"erstellen",true) == 0)
    {
    if(preis <1)return SendClientMessage(playerid,COLOR_WHITE,"Der Preis muss mindestens 1 $ betragen!");
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    CreateHaus(x,y,z,preis,"Keiner",0);
    return true;
    }
    }
    return 1;
    }

  • Hier mal der komplette Befehl..


    //------------------------------------/haus-----------------------------------//
    dcmd_haus(playerid,params[])
    {
    new option[25];
    if(sscanf(params,"s",option))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus [text] [miete]");
    {
    if(strfind(option,"text",true) == 0)
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]) && strcmp(HausInfo[haus][Haus_Besitzer],SpielerName(playerid),false) == 0)
    {
    new pfad[50],msg[128];
    if(sscanf(params,"s",msg))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus text [Dein Text]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_Set(pfad,"Text",msg);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    if(strfind(option,"miete",true) == 0)
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]) && strcmp(HausInfo[haus][Haus_Besitzer],SpielerName(playerid),false) == 0)
    {
    new pfad[50],miete;
    if(sscanf(params,"i",miete))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus miete [Deine Miete 100$ +]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_IntSet(pfad,"Miete",miete);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    if(strfind(option,"test",true) == 0)
    {
    SendClientMessage(playerid,COLOR_WHITE,"Kann das überhaupt gehen?");
    }
    if(strfind(option,"erstellen",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    new Float:x,Float:y,Float:z,preis;
    if(sscanf(params,"i",preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus erstellen [Preis]");
    GetPlayerPos(playerid,x,y,z);
    CreateHaus(x,y,z,preis,"Keiner",0);
    return true;
    }
    }
    if(strfind(option,"löschen",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]))
    {
    new pfad[50],msg[50],msg2[75];
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    format(msg,sizeof(msg),"ehemaliger Besitzer: %s",HausInfo[haus][Haus_Besitzer]);
    format(msg2,sizeof(msg2),"Du hast das Haus mit der ID [%i] erfolgreich gelöscht.",haus);
    dini_Remove(pfad);
    KillHaus(haus);
    SendClientMessage(playerid,COLOR_BLUE,msg2);
    SendClientMessage(playerid,COLOR_BLUE,msg);
    return true;
    }
    }
    }
    }
    if(strfind(option,"clearung",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]))
    {
    new pfad[50],preis;
    if(sscanf(params,"i",preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus clearung [neuer Preis]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_Set(pfad,"Besitzer","Keiner");
    dini_IntSet(pfad,"Preis",preis);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    }
    }
    return 1;
    }

    Mit freundlichen Grüßen,
    Cr4sh


  • Versuch es so:
    dcmd_haus(playerid,params[])
    {
    new option[25];
    if(sscanf(params,"s[25]",option))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus [text]");
    {
    if(strfind(option,"text",true) == 0)
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]) && strcmp(HausInfo[haus][Haus_Besitzer],SpielerName(playerid),false) == 0)
    {
    new pfad[50],msg[128];
    if(sscanf(params,"s[25]s[128]",option,msg))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus text [Dein Text]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_Set(pfad,"Text",msg);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    if(strfind(option,"miete",true) == 0)
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]) && strcmp(HausInfo[haus][Haus_Besitzer],SpielerName(playerid),false) == 0)
    {
    new pfad[50],miete;
    if(sscanf(params,"s[25]i",option,miete))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus miete [Deine Miete 100$ +]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_IntSet(pfad,"Miete",miete);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    if(strfind(option,"test",true) == 0)
    {
    SendClientMessage(playerid,COLOR_WHITE,"Kann das überhaupt gehen?");
    }
    if(strfind(option,"erstellen",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    new Float:x,Float:y,Float:z,preis;
    if(sscanf(params,"s[25]i",option,preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus erstellen [Preis]");
    GetPlayerPos(playerid,x,y,z);
    CreateHaus(x,y,z,preis,"Keiner",0);
    return true;
    }
    }
    if(strfind(option,"löschen",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]))
    {
    new pfad[50],msg[50],msg2[75];
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    format(msg,sizeof(msg),"ehemaliger Besitzer: %s",HausInfo[haus][Haus_Besitzer]);
    format(msg2,sizeof(msg2),"Du hast das Haus mit der ID [%i] erfolgreich gelöscht.",haus);
    dini_Remove(pfad);
    KillHaus(haus);
    SendClientMessage(playerid,COLOR_BLUE,msg2);
    SendClientMessage(playerid,COLOR_BLUE,msg);
    return true;
    }
    }
    }
    }
    if(strfind(option,"clearung",true) == 0)
    {
    if(IsPlayerAnAdmin(playerid,5))
    {
    for(new haus;haus<MAX_HAUS;haus++)
    {
    if(IsPlayerInRangeOfPoint(playerid,5,HausInfo[haus][Haus_X],HausInfo[haus][Haus_Y],HausInfo[haus][Haus_Z]))
    {
    new pfad[50],preis;
    if(sscanf(params,"s[25]i",option,preis))return SendClientMessage(playerid,COLOR_WHITE,"Benutze: /haus clearung [neuer Preis]");
    format(pfad,sizeof(pfad),"/Häuser/%d.txt",haus);
    dini_Set(pfad,"Besitzer","Keiner");
    dini_IntSet(pfad,"Preis",preis);
    KillHaus(haus);
    LoadHaus(haus);
    return true;
    }
    }
    }
    }
    }
    return 1;
    }


    Was noch gehen würde das du die Option aus den String löscht und dann wieder eine alten Abfragen einsetzt...

  • Okay danke.


    Ich bin keiner der das einfach kopiert also um sicherzugehen, dass ich alle übernommen habe:
    du hast nur in jede sscanf abfrage die option eingebaut, oder?

    Mit freundlichen Grüßen,
    Cr4sh


  • Wenn ich jetzt /haus [option] eingebe, dann kommt immer die fehlermeldung..aber ich hab grad ne idee :)
    die mal ausprobieren^^


    Okay, wenn auch ein bisschen umständlich, aber ich habe das problem gelöst :)
    Danke an alle Poster! :thumbup:

    Mit freundlichen Grüßen,
    Cr4sh


    Einmal editiert, zuletzt von Cr4sh ()