Strcmp issue [Giving reputations]
#1

Hello there, my script supports STRCMP not ZCMD, how to convert this dialogs to it, (dialogid and other stuff):

pawn Код:
switch(dialogid)
    {
        case DIALOG_MAIN:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: ShowPlayerDialog(playerid, DIALOG_NEW_OBJECT, DIALOG_STYLE_INPUT, "Insert the object model", "\n\n\n\n\n\n\n\n\n\n", "Continue", "Cancel");
                    case 1: ShowPlayerDialog(playerid, DIALOG_DELETE_OBJECT, DIALOG_STYLE_INPUT, "Insert the edition id:", "\n\n\n\n\n\n\n\n\n\n", "Delete", "Cancel");
                    case 2:
                    {
                        CancelEdit(playerid);
                        SelectObject(playerid);
                        ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Selective mode enabled.", "Close", "");
                        return 1;
                    }
                    case 3:
                    {
                        new substr[MAX_OBJECT_NAME + 8 + 100], list[sizeof substr * 20];
                        for(new i = 0; i < 20; i++)
                        {
                            if(GetSVarTypeEx(playerid, OBJECT_MODEL, i))
                            {
                                format(substr, sizeof substr, "- Object ID {00afdb}%d {FFFFFF}Model: {00afdb}%d{FFFFFF} Nominated: {00afdb}%s{FFFFFF}\n", GetSVarIntEx(playerid, OBJECT_ID, i), GetSVarIntEx(playerid, OBJECT_MODEL, i), GetSVarStringEx(playerid, OBJECT_NAME, i));
                                strcat(list, substr, sizeof list);
                            }
                        }
                        SetPVarInt(playerid, "Page", 0);
                        ShowPlayerDialog(playerid, DIALOG_OBJECTS, DIALOG_STYLE_LIST, "Editions:", list, "Select", "Advance");
                        return 1;
                    }
                    case 4: ShowPlayerDialog(playerid, DIALOG_MODEL_SEARCH, DIALOG_STYLE_INPUT, "Models", "\n\n\n\n\n\n\n\n\n\n", "Search", "Close");
                    case 5: ShowPlayerDialog(playerid, DIALOG_OPEN_MAP, DIALOG_STYLE_INPUT, "Insert the map name", "\n\n\n\n\n\n\n\n\n\n", "Open", "Cancel");
                    case 6: ShowPlayerDialog(playerid, DIALOG_MAP_NAME, DIALOG_STYLE_INPUT, "Insert the map name", "\n\n\n\n\n\n\n\n\n\n", "Continue", "Cancel");
                    case 7: ShowPlayerDialog(playerid, DIALOG_CONFIRM_CLOSE, DIALOG_STYLE_MSGBOX, "Confirmation", "All changes will be lost, are you sure?", "Close", "Cancel");
                    case 8: ShowPlayerDialog(playerid, DIALOG_CONFIG, DIALOG_STYLE_LIST, "Editor Configuration", "See Labels\nWeather\nTime\nGravity(For admins)", "Change", "Cancel");
                }
            }
        }
        case DIALOG_OBJECTS:
        {
            if(response)
            {
                if(GetPVarInt(playerid, "Page")>1)
                {
                    new edition = GetPVarInt(playerid, "Page") + listitem;
                    if(edition > MAX_EDITIONS)
                    {
                        ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "There is no more object pages.", "Close", "");
                        return 1;
                    }
                    SelectObjectEx(playerid, edition);
                    DeletePVar(playerid, "Page");
                    return 1;
                }
                else SelectObjectEx(playerid, listitem);
            }
            else
            {
                new substr[MAX_OBJECT_NAME + 8 + 100], list[sizeof substr * 20];
                SetPVarInt(playerid, "Page", GetPVarInt(playerid, "Page")+20);
                for(new i = GetPVarInt(playerid, "Page"); i < GetPVarInt(playerid, "Page") + 20; i++)
                {
                    if(GetSVarTypeEx(playerid, OBJECT_MODEL, i))
                    {
                        format(substr, sizeof substr, "- Object ID {00afdb}%d {FFFFFF}Model: {00afdb}%d{FFFFFF} Nominated: {00afdb}%s{FFFFFF}\n", GetSVarIntEx(playerid, OBJECT_ID, i), GetSVarIntEx(playerid, OBJECT_MODEL, i), GetSVarStringEx(playerid, OBJECT_NAME, i));
                        strcat(list, substr, sizeof list);
                    }
                }
                ShowPlayerDialog(playerid, DIALOG_OBJECTS, DIALOG_STYLE_LIST, "Editions:", list, "Select", "Advance");
            }
        }
        case DIALOG_CONFIG:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: // Labels
                    {
                        SetPVarInt(playerid, "SeeLabels", GetPVarInt(playerid, "SeeLabels") ? 0 : 1);
                        SetPlayerLabelsActive(playerid, GetPVarInt(playerid, "SeeLabels"));
                    }
                    case 1: // Weather
                    {
                        ShowPlayerDialog(playerid, DIALOG_WEATHER, DIALOG_STYLE_INPUT, "Insert the weather(integer)", "\t", "Insert", "Cancel");
                    }
                    case 2: // Time
                    {
                        ShowPlayerDialog(playerid, DIALOG_TIME, DIALOG_STYLE_INPUT, "Insert the time(hour)", "\t", "Insert", "Cancel");
                    }
                    case 3: // Gravity
                    {
                        ShowPlayerDialog(playerid, DIALOG_GRAVITY, DIALOG_STYLE_INPUT, "Insert the gravity(float)", "\t", "Insert", "Cancel");
                    }
                }
            }
        }
        case DIALOG_WEATHER: if(strlen(inputtext)) SetPlayerWeather(playerid, strval(inputtext));
        case DIALOG_TIME:    if(strlen(inputtext)) SetPlayerTime(playerid, strval(inputtext), 0);
        case DIALOG_GRAVITY: if(strlen(inputtext) && IsPlayerAdmin(playerid)) SetGravity(floatstr(inputtext));
        case DIALOG_MAP_NAME:
        {
            if(response && strlen(inputtext) > 1)
            {
                ShowPlayerDialog(playerid, DIALOG_CHOICE_TYPE, DIALOG_STYLE_LIST, "Chose the map type", "- Global Objects\n- Per Player Objects", "Continue", "Cancel");
                SetPVarString(playerid, "Filename", inputtext);
                return 1;
            }
        }
        case DIALOG_CHOICE_TYPE:
        {
            if(response)
            {
                new pvar[64];
                GetPVarString(playerid, "Filename", pvar, sizeof pvar);
                SetPVarInt(playerid, "ObjectType", listitem);
                CallLocalFunction("OnDialogResponse", "dddds", playerid, DIALOG_SAVE_MAP, 1, 0, pvar);
                return 1;
            }
        }
        case DIALOG_CONFIRM_REPLACEMENT:
        {
            if(response)
            {
                new pvar[64];
                GetPVarString(playerid, "Filename", pvar, sizeof pvar);
                fremove(pvar);
                if(!fexist(pvar)) CallLocalFunction("OnDialogResponse", "dddds", playerid, DIALOG_SAVE_MAP, 1, 0, pvar);
                DeletePVar(playerid, "Filename");
                return 1;
            }
        }
        case DIALOG_CONFIRM_CLOSE:
        {
            if(response)
            {
                CancelEdit(playerid);

                ResetPlayerMapData(playerid);
                ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Map closed.", "Close", "");
            }
        }
        case DIALOG_NEW_OBJECT:
        {
            if(response && IsNumeric(inputtext) && strval(inputtext) > 611)
            {
                SetPVarInt(playerid, "new_object_model", strval(inputtext));
                ShowPlayerDialog(playerid, DIALOG_CREATE_OBJECT, DIALOG_STYLE_INPUT, "-", "Type the object description(or not)", "Continue", "Cancel");
            }
        }
        case DIALOG_CREATE_OBJECT:
        {
            if(response)
            {
                new model, object, Float:Pos[6];

                model = GetPVarInt(playerid, "new_object_model");
                GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
                GetXYInFrontOfPlayer(playerid, Pos[0], Pos[1], 3.0);

                object = CreatePlayerObject(playerid, model, Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
                for(new i = 0; i < MAX_EDITIONS; i++)
                {
                    if(!GetSVarTypeEx(playerid, OBJECT_MODEL, i))
                    {
                        SetPlayerMapData(playerid, object, i, model, inputtext, Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
                        EditPlayerObject(playerid, object);
                        DeletePVar(playerid, "new_object_model");
                        return 1;
                    }
                }
                DeletePVar(playerid, "new_object_model");
                return ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "You already have the maximum objects amount allowed!", "Close", "");
            }
        }
        case DIALOG_DELETE_OBJECT:
        {
            if(response && IsNumeric(inputtext))
            {
                new deleted = strval(inputtext);
                if(GetSVarIntEx(playerid, OBJECT_MODEL, deleted))
                {
                    new str[84];
                    format(str, sizeof str, "The edition ID[%d] was deleted.", deleted);
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", str, "Close", "");
                    DestroyPlayerObject(playerid, GetSVarIntEx(playerid, OBJECT_ID, deleted));
                    DeletePlayer3DTextLabel(playerid, PlayerText3D:GetSVarIntEx(playerid, LABEL_ID, deleted));
                    DeleteSVarEx(playerid, OBJECT_MODEL, deleted);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Unable to delete this edition ID.", "Close", "");
                }
                return 1;
            }
        }
        case DIALOG_SIMPLE_MESSAGE:
        {
            ReSelectObject(playerid);
            return 1;
        }
        case DIALOG_EDIT_OR_DELETE:
        {
            if(response)
            {
                SelectObjectEx(playerid, GetPVarInt(playerid, "Selected"));
                DeletePVar(playerid, "Selected");
                return 1;
            }
            else
            {
                new str[84];
                format(str, sizeof str, "The edition ID[%d] was deleted.", GetPVarInt(playerid, "Selected"));
                ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", str, "Close", "");
                DestroyPlayerObject(playerid, GetSVarIntEx(playerid, OBJECT_ID, GetPVarInt(playerid, "Selected")));
                DeletePlayer3DTextLabel(playerid, PlayerText3D:GetSVarIntEx(playerid, LABEL_ID, GetPVarInt(playerid, "Selected")));
                DeleteSVarEx(playerid, OBJECT_MODEL, GetPVarInt(playerid, "Selected"));
                DeletePVar(playerid, "Selected");
                return 1;
            }
        }
        case DIALOG_MODEL_SEARCH:
        {
            if(response)
            {
                new i, iMatches, szBuffer[MAX_OBJECT_NAME], szID[6], szDialog[128 + (MAX_MODEL_SEARCH_MATCHES) + (MAX_OBJECT_NAME * MAX_MODEL_SEARCH_MATCHES) ];
                for ( i = 0; i < sizeof( g_ModelNames ); i++ )
                {
                    strunpack(szBuffer, g_ModelNames[i][e_szName], MAX_OBJECT_NAME);

                    if(strfind(szBuffer, inputtext, true) != -1)
                    {
                        valstr( szID, g_ModelNames[i][e_iID]);

                        strcat(szDialog, szID);
                        strcat(szDialog, "\t- ");
                        strcat(szDialog, szBuffer);
                        strcat(szDialog, "\n");

                        ++iMatches;
                    }

                    if(iMatches >= MAX_MODEL_SEARCH_MATCHES)
                    {
                        strcat( szDialog, "\nMore matches were found; the list is cut off after " #MAX_MODEL_SEARCH_MATCHES ".");
                        break;
                    }
                }

                if (iMatches == 0)
                {
                    strcat(szDialog, "\nNo matches were found for \"");
                    strcat(szDialog, inputtext);
                    strcat(szDialog, "\".\n");
                }

                for (i = 0; i < MAX_MODEL_SEARCH_MATCHES - iMatches; i++)
                    strcat(szDialog, "\n");

                strcat(szDialog, "\n");
                ShowPlayerDialog(playerid, DIALOG_MODEL_SEARCH, DIALOG_STYLE_INPUT, "Models", szDialog, "Search", "Close" );
            }
        }
        case DIALOG_SAVE_MAP:
        {
            if(response && strlen(inputtext) > 1)
            {
                new str[164], File:file;
                if(strlen(inputtext) > 64)
                {
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "The inputed text is too much long.", "Close", "");
                    return 1;
                }
                format(str, sizeof str, "%s.pwn", inputtext);
                if(fexist(str))
                {
                    SetPVarString(playerid, "Filename", str);
                    return ShowPlayerDialog(playerid, DIALOG_CONFIRM_REPLACEMENT, DIALOG_STYLE_MSGBOX, "File replacement", "The file already exists!", "Replace", "Cancel");
                }
                file = fopen(str, io_write);
                if(file)
                {
                    new fstring[84];
                    switch(GetPVarInt(playerid, "ObjectType"))
                    {
                        case 0: fstring = "CreateObject(%d, %f, %f, %f, %f, %f, %f);//%s\r\n";
                        case 1: fstring = "CreatePlayerObject(playerid, %d, %f, %f, %f, %f, %f, %f);//%s\r\n";
                    }
                    for(new i = 0; i < MAX_EDITIONS; i++)
                    {
                        if(GetSVarTypeEx(playerid, OBJECT_MODEL, i))
                        {
                            format
                            (
                                 str,
                                 sizeof str,
                                 fstring,
                                 GetSVarIntEx    (playerid,  OBJECT_MODEL, i),
                                 GetSVarFloatEx  (playerid,  OBJECT_X,     i),
                                 GetSVarFloatEx  (playerid,  OBJECT_Y,     i),
                                 GetSVarFloatEx  (playerid,  OBJECT_Z,     i),
                                 GetSVarFloatEx  (playerid,  OBJECT_RX,    i),
                                 GetSVarFloatEx  (playerid,  OBJECT_RY,    i),
                                 GetSVarFloatEx  (playerid,  OBJECT_RZ,    i),
                                 GetSVarStringEx (playerid,  OBJECT_NAME,  i)
                            );
                            fwrite(file, str);
                        }
                    }
                    fclose(file);
                    DeletePVar(playerid, "ObjectType");
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Your map was saved with success.", "Close", "");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Fail, a problem happened at create the file.", "Close", "");
                }
            }
            return 1;
        }
        case DIALOG_OPEN_MAP:
        {
            if(response)
            {
                new filename[70];
                if(strlen(inputtext) > 64)
                {
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "The map name is too much long.", "Close", "");
                    return 1;
                }
                format(filename, sizeof filename, "%s.pwn", inputtext);
                if(!fexist(filename))
                {
                    ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "This map doesn't exists in \"scriptfiles\" folder.\n\nType the map name {FF4040}without{FFFFFF} file extension. Only {FF4040}.pwn{FFFFFF} is acceptable.", "Close", "");
                    return 1;
                }
               
                new File:file,
                object, model, idx, freeedition, i = -1,
                Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ,
                str[128], tmp[64];

                ResetPlayerMapData(playerid);
                file = fopen(filename, io_read);

                while(fread(file, str))
                {
                    i++;
                    RemoveSpaces(str);
                    new cutend = strfind(str, "CreateObject(");
                    freeedition = GetPlayerFreeEdition(playerid);
                    if(freeedition == -1)
                    {
                        ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "You do not have a free edition ID.", "Close", "");
                        fclose(file);
                        return 1;
                    }
                    if(cutend != -1)
                    {
                        strdel(str, 0, cutend + 13);
                    }
                    else
                    {
                        cutend = strfind(str, "CreatePlayerObject(");
                        if(cutend != -1)
                        {
                            strdel(str, 0, cutend + 28);
                        }
                        else
                        {
                            format(str, sizeof str, "- Unacceptable file line(%d), maybe it's not an object.", i+1);
                            SendClientMessage(playerid, 0x00afdbAA, str);
                            str[0] = '\0';
                            idx = 0;
                            continue;
                        }
                    }
                    tmp = strtok(str, idx);
                    model = strval(tmp);
                    tmp = strtok(str, idx);
                    X = floatstr(tmp);
                    tmp = strtok(str, idx);
                    Y = floatstr(tmp);
                    tmp = strtok(str, idx);
                    Z = floatstr(tmp);
                    tmp = strtok(str, idx);
                    RX = floatstr(tmp);
                    tmp = strtok(str, idx);
                    RY = floatstr(tmp);
                    tmp = strtok(str, idx);
                    RZ = floatstr(tmp);
                    object = CreatePlayerObject(playerid, model, X, Y, Z, RX, RY, RZ);
                    SetPlayerMapData(playerid, object, freeedition, model, "no name", X, Y, Z, RX, RY, RZ);
                    str[0] = '\0';
                    idx = 0;
                }
                fclose(file);
                DeletePVar(playerid, "Mode");
                ShowPlayerDialog(playerid, DIALOG_SIMPLE_MESSAGE, DIALOG_STYLE_MSGBOX, "-", "Map loaded.", "Close", "");
                return 1;
            }
        }
Reply


Messages In This Thread
Strcmp issue [Giving reputations] - by Stanford - 20.04.2013, 12:49
Re: Strcmp issue [Giving reputations] - by HurtLocker - 20.04.2013, 12:54
Re: Strcmp issue [Giving reputations] - by Stanford - 20.04.2013, 12:55
Re: Strcmp issue [Giving reputations] - by Avi Raj - 20.04.2013, 13:00
Re: Strcmp issue [Giving reputations] - by Stanford - 20.04.2013, 13:07
Re: Strcmp issue [Giving reputations] - by Stanford - 20.04.2013, 13:17
Re: Strcmp issue [Giving reputations] - by MattyG - 20.04.2013, 14:23

Forum Jump:


Users browsing this thread: 3 Guest(s)