Problem with inputtext value from factions dialog
#1

I have a /frespawn system, that prompts a dialog for any administrator, for him to select that faction. After he chooses the faction, he's listed with either respawning every vehicle, or just a single ID.

My idea is, the "FactionSelected = listitem;" doesn't work. It doesn't understand the FactionID of the faction chosen. It doesn't understand what listitem is... Why is this? Can it be used somehow else? Enums are used for the factions, so if you make something up as a solution, I'll try to translate it to mine. The codes are in separate files.

Below is the code:

pawn Code:
YCMD:frespawn(playerid, params[]) {
    new vehicleid, text[12];
    if(PlayerInfo[playerid][pAdminlevel] > 0)
    {
        if(GetPVarInt(playerid, "StaffLogin") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You must be logged into the staff panel to access administration commands. (/stafflogin)");
        {
            format(gVar3000, sizeof(gVar3000), "%s", EOS);
            for(new i=0; i<sizeof(FactionInfo); i++) {
                if(!isnull(FactionInfo[i][fName])) {
                    if(isnull(gVar3000)) {
                        format(gVar3000, sizeof(gVar3000), "%s", FactionInfo[i][fName]);
                    } else {
                        format(gVar3000, sizeof(gVar3000), "%s\n%s", gVar3000, FactionInfo[i][fName]);
                    }
                }
            }
            format(gVar3000, sizeof(gVar3000), "%s", gVar3000);
            ShowPlayerDialogEx(playerid, DIALOG_FRESPAWN, DIALOG_STYLE_LIST, "{FF9900}Faction Respawn", gVar3000, "Select", "Cancel");
            format(gVar3000, sizeof(gVar3000), "%s", EOS);
        }
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not authorized to use this command.");
    return 1;
}
pawn Code:
switch(dialogid)
    {
       
        case DIALOG_FRESPAWN:
        {
            if(response)
            {
               
                FactionSelected = listitem;
                print("%s %d", FactionSelected, FactionSelected);
                {
                    ShowPlayerDialogEx(playerid, DIALOG_FRESPAWN_SELECT, DIALOG_STYLE_LIST, "{FF9900}Faction Respawn", "Frespawn all\nRespawn ID", "Select", "Cancel");
                }
            }
        }
        case DIALOG_FRESPAWN_SELECT:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0:
                    {
                        for(new v = GetVehiclePoolSize(); v > 0; v--)
                        {
                            if(VehicleInfo[v][vFaction] != 0 && FactionSelected)
                            {
                                SetVehicleToRespawn(v);
                            }
                        }
                    }
                    case 1:
                    {
                        ShowPlayerDialogEx(playerid, DIALOG_FRESPAWN_SELECT_ID, DIALOG_STYLE_INPUT, "{FF9900}Faction Respawn", "Enter a vehicle ID below to respawn it.", "Select", "Cancel");
                    }
                }
            }
        }
        case DIALOG_FRESPAWN_SELECT_ID:
        {
            if(response)
            {
                new inputtextint = strval(inputtext);
                if(VehicleInfo[FactionSelected][vFaction] == inputtextint)
                {
                    SetVehicleToRespawn(inputtextint);
                }
            }
        }
Reply
#2

Well the issue is you check
Code:
if(!isnull(FactionInfo[i][fName])) {
While this is completely valid it means that your listitem can very easily be different to the ID of the 'faction' you're trying to respawn the vehicles for, it can also rise inconsisties as listitem starts at 0 and if you load your factions from an sql database that uses auto increment for the id it might start at 1.

A messy, but functional, solution to this is adding the ID of the faction in your format:

Code:
if(isnull(gVar3000)) {
                        format(gVar3000, sizeof(gVar3000), "[%d] %s", FactionInfo[i][fID], FactionInfo[i][fName]);
                    } else {
                        format(gVar3000, sizeof(gVar3000), "%s\n[%d] %s", gVar3000, FactionInfo[i][fID], FactionInfo[i][fName]);
                    }
By having the ID present in the string you can then utilize strmid to get the ID on the dialog response, like so:
Code:
new stpos = strfind(inputtext, "[");
		new fpos = strfind(inputtext, "]");
		new id[4];
		strmid(id, inputtext, stpos+1, fpos);
		FactionSelected = strval(id);
You may have to slightly adjust that logic if inputtext on list dialogs isn't the contents of the dialog on the line but I'm quite sure it is.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)