SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 22/01/2019, 10:56 PM   #1
EmilLykke
Huge Clucker
 
EmilLykke's Avatar
 
Join Date: Aug 2013
Posts: 210
Reputation: 30
Default Problem with inputtext value from factions dialog

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);
                }
            }
        }
__________________
EmilLykke is offline   Reply With Quote
Old 23/01/2019, 01:14 PM   #2
Chyakka
Big Clucker
 
Join Date: Jul 2015
Location: England
Posts: 61
Reputation: 10
Default Re: Problem with inputtext value from factions dialog

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.
Chyakka is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inputtext, textdraws, dialog, real problem. Inuro Scripting Help 2 11/07/2018 05:54 PM
/factions dialog crouch010 Scripting Help 5 07/04/2014 10:52 PM
Dialog inputtext problem Mystique Scripting Help 1 21/02/2013 05:57 PM
dialog inputtext problem. Jack_Leslie Scripting Help 7 07/09/2011 10:30 AM
dialog problem with inputtext legodude Help Archive 3 10/04/2010 04:12 PM


All times are GMT. The time now is 12:54 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.