On and OFF toggle for a DIALOG_STYLE_TABLIST_HEADERS
#1

Having a bit of trouble making a on and off toggle system with the Dialog, If someone can explain or get me started on it would be greatly appreciated.

Example..
PHONE: OFF (Bool to turn it on)

Started Code..:
PHP код:
    if(dialogid == DIALOG_SETTINGSMAIN)
    {
        if(
response)
        {
            new 
toggleOnOff[3];
            switch (
listitem) {
                new 
bool:togglemate true;
                new 
toggletext[3];
                if (
togglemate true)
                {
                    
format(output[], len, const format[], ...)
                }
                case 
0:
                {
                        
ShowPlayerDialog(playeridDIALOG_SETTINGSSUBDIALOG_STYLE_TABLIST_HEADERS"Player Settings - Toggle""Toggle\tStatus\n\
                            ---General---\n\
                            PHONE\tOFF\n\
                            Newbie Chat\tOFF\n\
                            News\tOFF\n\
                            OOC Chat\tOFF\n\
                            Whispers\tOFF\n\
                            Private Radio(/PR)\tOFF\n\
                            Hunger Meter\tOFF\n\
                            Famed\tOFF\n\
                            VIP\tOFF\n\
                            ---GROUPS---\n\
                            Dept\tOFF\n\
                            International\tOFF\n\
                            OOC Group (/g)\tOFF\n\
                            Radio\tOFF\n\
                            BUG Chat\tOFF\n\
                            Biz Radio\tOFF\n\
                            Point Messages\tOFF\n"
"Select""Close");
                }
            }
        }

Kind Regards,
minijackc
Reply
#2

Hi.

You can't have any code in your 'switch' statement if it's not under a 'case' label (so 'new togglemate=true' etc. will not compile).

You started off good, using 'switch(listitem)' and now you just have to bind actions to that specific listitem response, like setting your variables. To simply toggle a bool variable you can do 'var = !var;', or shorter, but not as readable: 'var ^= 1;'.
Reply
#3

Could you give me a little example snippet? Thanks again.
Reply
#4

I was on my phone when I wrote my original reply. There's not much to show here. Check the Wiki page.

PHP код:
// OnDialogResponse
if (dialogid == DIALOG_SETTINGSMAIN)
{
    if (
response)
    {
        switch (
listitem)
        {
            case 
0:
            {
                
phoneVar = !phoneVar;
            }
            case 
1:
            {
                
newbieChatVar = !newbieChatVar;
            }
            
// etc
        
}
        
// other possible code here, like ShowPlayerDialog
    
}
    return 
1;

Reply
#5

Greatly Appreciated, Thanks
Reply
#6

*Brushing off my pawn skills*



Код:
#include <a_samp>
#include <ZCMD>

/* Debug
CMD:lol(playerid, params[]) {
	ShowPlayerTogglesDialog(playerid);
	return true;
}

#define DIALOG_SETTINGSSUB 1234
#define DIALOG_SETTINGSMAIN 1235
*/


//Let's structure our toggle options using an enum so its easier to add or remove things later
enum e_TOGGLES {
	TOGGLE_PHONE,
	TOGGLE_NEWBIE_CHAT,
	TOGGLE_NEWS,
	TOGGLE_OOC_CHAT,
	TOGGLE_WHISPERS,
	TOGGLE_PRIVATE_RADIO,
	TOGGLE_HUNGER_METER,
	TOGGLE_FAMED,
	TOGGLE_VIP,
	TOGGLE_DEPT,
	TOGGLE_INTERNATIONAL,
	TOGGLE_OOC_GROUP,
	TOGGLE_RADIO,
	TOGGLE_BUG_CHAT,
	TOGGLE_BIZ_RADIO,
	TOGGLE_POINT_MESSAGES
};

//The enum above is for scripting, this variable here is the name which players see in dialog
new ToggleLabels[e_TOGGLES][] = {
	"Phone",
	"Newbie Chat",
	"News",
	"OOC Chat",
	"Whispers",
	"Private Radio (/PR)",
	"Hunger Meter",
	"Famed",
	"VIP",
	"Dept",
	"International",
	"OOC Group",
	"Radio",
	"BUG Chat",
	"Biz Radio",
	"Point Messages"
};

//Each player needs to have their own toggle settings
new	bool:PlayerToggleSettings[MAX_PLAYERS][e_TOGGLES];

//We make the dialog viewer a seperate function so as to keep code clean
stock ShowPlayerTogglesDialog(playerid) {
	new
		dialog_line[50],
		dialog_text[400]
	;
	
	//Loop through all toggle options
	for(new e_TOGGLES:i; i < e_TOGGLES; i++) {
	    //Add any headers if needed
	    if(i == TOGGLE_PHONE) strcat(dialog_text, "Toggle\tStatus\n---General---\n");
	    if(i == TOGGLE_DEPT) strcat(dialog_text, "---Groups---\n");
	
	    //Format each line with the player's toggle option and push it to the larger array
		format(dialog_line, sizeof dialog_line, "%s\t%s\n", ToggleLabels[i], PlayerToggleSettings[playerid][i] ? ("{8FE3FF}ON") : ("{4A4C4D}OFF"));
	    strcat(dialog_text, dialog_line);
	}
	
	ShowPlayerDialog(playerid, DIALOG_SETTINGSSUB, DIALOG_STYLE_TABLIST_HEADERS, "Player Settings - Toggle", dialog_text, "Select", "Close");
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_SETTINGSMAIN) {
        if(response) {
            switch(listitem) {
                case 0: {
                    ShowPlayerTogglesDialog(playerid);
                }
            }
        } else {
        
        }
        return true;
    }
    if(dialogid == DIALOG_SETTINGSSUB) {
        if(response) {
            switch(listitem) {
                case 0,10: {
                    //Ignore the headers
                    ShowPlayerTogglesDialog(playerid);
                }
                default: {
                    //Fix the listitem offset caused by headers
                    new toggle_index = listitem - 1;
                    if(listitem > 10) toggle_index -= 1;
					
					//Make sure the player is not sending fake listitems which will cause index errors
					if(!(0 <= toggle_index < _:e_TOGGLES)) {
					    SendClientMessage(playerid, 0xFF0000FF, "Invalid toggle option.");
					} else {
					    //Reverse the value of the toggle option of the player
					    PlayerToggleSettings[playerid][e_TOGGLES:toggle_index] = !PlayerToggleSettings[playerid][e_TOGGLES:toggle_index];
					}
					//Show them the updated dialog
					ShowPlayerTogglesDialog(playerid);
                }
            }
        } else {
			//Show Settings Main
        }
        return true;
    }
    return false;
}
Reply
#7

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
*Brushing off my pawn skills*



Код:
#include <a_samp>
#include <ZCMD>

/* Debug
CMD:lol(playerid, params[]) {
	ShowPlayerTogglesDialog(playerid);
	return true;
}

#define DIALOG_SETTINGSSUB 1234
#define DIALOG_SETTINGSMAIN 1235
*/


//Let's structure our toggle options using an enum so its easier to add or remove things later
enum e_TOGGLES {
	TOGGLE_PHONE,
	TOGGLE_NEWBIE_CHAT,
	TOGGLE_NEWS,
	TOGGLE_OOC_CHAT,
	TOGGLE_WHISPERS,
	TOGGLE_PRIVATE_RADIO,
	TOGGLE_HUNGER_METER,
	TOGGLE_FAMED,
	TOGGLE_VIP,
	TOGGLE_DEPT,
	TOGGLE_INTERNATIONAL,
	TOGGLE_OOC_GROUP,
	TOGGLE_RADIO,
	TOGGLE_BUG_CHAT,
	TOGGLE_BIZ_RADIO,
	TOGGLE_POINT_MESSAGES
};

//The enum above is for scripting, this variable here is the name which players see in dialog
new ToggleLabels[e_TOGGLES][] = {
	"Phone",
	"Newbie Chat",
	"News",
	"OOC Chat",
	"Whispers",
	"Private Radio (/PR)",
	"Hunger Meter",
	"Famed",
	"VIP",
	"Dept",
	"International",
	"OOC Group",
	"Radio",
	"BUG Chat",
	"Biz Radio",
	"Point Messages"
};

//Each player needs to have their own toggle settings
new	bool:PlayerToggleSettings[MAX_PLAYERS][e_TOGGLES];

//We make the dialog viewer a seperate function so as to keep code clean
stock ShowPlayerTogglesDialog(playerid) {
	new
		dialog_line[50],
		dialog_text[400]
	;
	
	//Loop through all toggle options
	for(new e_TOGGLES:i; i < e_TOGGLES; i++) {
	    //Add any headers if needed
	    if(i == TOGGLE_PHONE) strcat(dialog_text, "Toggle\tStatus\n---General---\n");
	    if(i == TOGGLE_DEPT) strcat(dialog_text, "---Groups---\n");
	
	    //Format each line with the player's toggle option and push it to the larger array
		format(dialog_line, sizeof dialog_line, "%s\t%s\n", ToggleLabels[i], PlayerToggleSettings[playerid][i] ? ("{8FE3FF}ON") : ("{4A4C4D}OFF"));
	    strcat(dialog_text, dialog_line);
	}
	
	ShowPlayerDialog(playerid, DIALOG_SETTINGSSUB, DIALOG_STYLE_TABLIST_HEADERS, "Player Settings - Toggle", dialog_text, "Select", "Close");
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_SETTINGSMAIN) {
        if(response) {
            switch(listitem) {
                case 0: {
                    ShowPlayerTogglesDialog(playerid);
                }
            }
        } else {
        
        }
        return true;
    }
    if(dialogid == DIALOG_SETTINGSSUB) {
        if(response) {
            switch(listitem) {
                case 0,10: {
                    //Ignore the headers
                    ShowPlayerTogglesDialog(playerid);
                }
                default: {
                    //Fix the listitem offset caused by headers
                    new toggle_index = listitem - 1;
                    if(listitem > 10) toggle_index -= 1;
					
					//Make sure the player is not sending fake listitems which will cause index errors
					if(!(0 <= toggle_index < _:e_TOGGLES)) {
					    SendClientMessage(playerid, 0xFF0000FF, "Invalid toggle option.");
					} else {
					    //Reverse the value of the toggle option of the player
					    PlayerToggleSettings[playerid][e_TOGGLES:toggle_index] = !PlayerToggleSettings[playerid][e_TOGGLES:toggle_index];
					}
					//Show them the updated dialog
					ShowPlayerTogglesDialog(playerid);
                }
            }
        } else {
			//Show Settings Main
        }
        return true;
    }
    return false;
}
Appreciate the smartass full code, I wanted to learn myself was just asking for an example ahahaha. Thanks anyway!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)