Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dynamic Dialogs BETA
- *
- * (c) Copyright 2013, GameMan aka Lemonadio aka MeowCola
- *
- */
- /* NATIVES for "Pawno"
- native CreateDialog(caption[], button1[], button2[] = "");
- native DestroyDialog(dialogid);
- native AddDialogItem(dialogid, itemid, itemtext[]);
- native UpdateDialogItem(dialogid, itemid, newitemtext[]);
- native GetDialogItemText(dialogid, itemid, dest[]);
- native DeleteDialogItem(dialogid, itemid);
- native UpdateDialogCaption(dialogid, newcaption[]);
- native GetDialogCaption(dialogid, dest[]);
- native UpdateDialogButton1(dialogid, newbutton[]);
- native UpdateDialogButton2(dialogid, newbutton[]);
- native GetDialogButton1(dialogid, dest[]);
- native GetDialogButton2(dialogid, dest[]);
- native ShowDialogForPlayer(playerid, dialogid);
- native HideDialogForPlayer(playerid);
- native GetPlayerDIalog(playerid);
- */
- #if !defined _samp_included
- #error "Please include 'a_samp.inc' before 'dyndial.inc'"
- #endif
- #if defined _dynamic_dialogs_included
- #endinput
- #endif
- #define _dynamic_dialogs_included
- #define PrintERROR(%1) printf("DynamicDialogs ERROR: %s!", %1)
- #define DIALOGID_OFFSET 25000
- #define MAX_DIALOGS (MAX_PLAYERS*2)
- #define MAX_DIALOG_ITEMS (32)
- #define MAX_ITEM_LENGTH (64)
- #define MAX_CAPTION_LENGTH (64)
- #define MAX_BUTTON_LENGTH (8)
- forward OnDynamicDialogResponse(playerid, dialogid, response, itemid, itemtext[]);
- enum DD_Enum {
- bool:DialogExist,
- DialogCaption[MAX_CAPTION_LENGTH],
- Button1[MAX_BUTTON_LENGTH],
- Button2[MAX_BUTTON_LENGTH]
- }
- new DialogInfo[MAX_DIALOGS][DD_Enum];
- enum DDI_Enum {
- ItemID,
- ItemText[MAX_ITEM_LENGTH]
- }
- new DialogItems[MAX_DIALOGS][MAX_DIALOG_ITEMS][DDI_Enum];
- new CurDialog[MAX_PLAYERS];
- #if defined FILTERSCRIPT
- public OnFilterScriptInit() {
- for(new i = 0; i < MAX_DIALOGS; i++) {
- for(new di = 0; di < MAX_DIALOG_ITEMS; di++) {
- DialogItems[i][di][ItemID] = -1;
- }
- }
- foreach(new i : Players) {
- CurDialog[i] = -1;
- }
- if(funcidx("dd_OnFilterScriptInit") != -1) return CallLocalFunction("dd_OnFilterScriptInit", "");
- return 1;
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit dd_OnFilterScriptInit
- forward dd_OnFilterScriptInit();
- public OnFilterScriptExit() {
- for(new d = 0; d < MAX_DIALOGS; d++) {
- if(DialogInfo[d][DialogExist]) DestroyDialog(d);
- }
- if(funcidx("dd_OnFilterScriptExit") != -1) return CallLocalFunction("dd_OnFilterScriptExit", "");
- return 1;
- }
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit dd_OnFilterScriptExit
- forward dd_OnFilterScriptExit();
- #else
- public OnGameModeInit() {
- for(new i = 0; i < MAX_DIALOGS; i++) {
- for(new di = 0; di < MAX_DIALOG_ITEMS; di++) {
- DialogItems[i][di][ItemID] = -1;
- }
- }
- if(funcidx("dd_OnGameModeInit") != -1) return CallLocalFunction("dd_OnGameModeInit", "");
- return 1;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit dd_OnGameModeInit
- forward dd_OnGameModeInit();
- public OnGameModeExit() {
- for(new d = 0; d < MAX_DIALOGS; d++) {
- if(DialogInfo[d][DialogExist]) DestroyDialog(d);
- }
- if(funcidx("dd_OnGameModeExit") != -1) return CallLocalFunction("dd_OnGameModeExit", "");
- return 1;
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit dd_OnGameModeExit
- forward dd_OnGameModeExit();
- #endif
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if(CurDialog[playerid] != -1) {
- new dialog_id = CurDialog[playerid];
- CurDialog[playerid] = -1;
- for(new di = 0, x = 0; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialog_id][di][ItemID] == -1) continue;
- if(x == listitem) {
- if(funcidx("OnDynamicDialogResponse") != -1) CallLocalFunction("OnDynamicDialogResponse", "dddds", playerid, dialog_id, response, DialogItems[dialog_id][di][ItemID], inputtext);
- break;
- }
- x++;
- }
- }
- if(funcidx("dd_OnDialogResponse") != -1) return CallLocalFunction("dd_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
- return 0;
- }
- #if defined _ALS_OnDialogResponse
- #undef OnDialogResponse
- #else
- #define _ALS_OnDialogResponse
- #endif
- #define OnDialogResponse dd_OnDialogResponse
- forward dd_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
- public OnPlayerConnect(playerid)
- {
- CurDialog[playerid] = -1;
- if(funcidx("dd_OnPlayerConnect") != -1) return CallLocalFunction("dd_OnPlayerConnect", "d",playerid);
- return 1;
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect dd_OnPlayerConnect
- forward dd_OnPlayerConnect(playerid);
- stock CreateDialog(caption[], button1[], button2[] = "") {
- if(caption[0] == EOS || strlen(caption) > MAX_CAPTION_LENGTH) return -1;
- if(button1[0] == EOS || strlen(button1) > MAX_BUTTON_LENGTH || strlen(button2) > MAX_BUTTON_LENGTH) return -1;
- for(new i = 0; i < MAX_DIALOGS; i++) {
- if(DialogInfo[i][DialogExist]) continue;
- DialogInfo[i][DialogExist] = true;
- strcat(DialogInfo[i][DialogCaption], caption, MAX_CAPTION_LENGTH);
- strcat(DialogInfo[i][Button1], button1, MAX_BUTTON_LENGTH);
- strcat(DialogInfo[i][Button2], button2, MAX_BUTTON_LENGTH);
- return i;
- }
- return -1;
- }
- stock DestroyDialog(dialogid) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- foreach(new i : Player) {
- if(CurDialog[i] != dialogid) continue;
- HideDialogForPlayer(i);
- }
- DialogInfo[dialogid][DialogExist] = false;
- strdel(DialogInfo[dialogid][DialogCaption], 0, MAX_CAPTION_LENGTH);
- strdel(DialogInfo[dialogid][Button1], 0, MAX_BUTTON_LENGTH);
- strdel(DialogInfo[dialogid][Button2], 0, MAX_BUTTON_LENGTH);
- for(new di; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialogid][di][ItemID] == -1) continue;
- DialogItems[dialogid][di][ItemID] = -1;
- strdel(DialogItems[dialogid][di][ItemText], 0, MAX_ITEM_LENGTH);
- }
- return 1;
- }
- stock AddDialogItem(dialogid, itemid, itemtext[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(itemid < 0 || itemtext[0] == EOS || strlen(itemtext) > MAX_ITEM_LENGTH) return 0;
- for(new di = 0; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialogid][di][ItemID] != -1) continue;
- DialogItems[dialogid][di][ItemID] = itemid;
- strcat(DialogItems[dialogid][di][ItemText], itemtext, MAX_ITEM_LENGTH);
- return 1;
- }
- return 0;
- }
- stock GetDialogItemText(dialogid, itemid, dest[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(itemid < 0) return 0;
- for(new di; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialogid][di][ItemID] != itemid) continue;
- strcat(dest, DialogItems[dialogid][di][ItemText], MAX_ITEM_LENGTH);
- return 1;
- }
- return 0;
- }
- stock DeleteDialogItem(dialogid, itemid) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(itemid < 0 || itemid >= sizeof(DialogItems[]) || DialogItems[dialogid][itemid][ItemID] == -1) return 0;
- DialogItems[dialogid][itemid][ItemID] = -1;
- strdel(DialogItems[dialogid][itemid][ItemText], 0, MAX_ITEM_LENGTH);
- return 1;
- }
- stock UpdateDialogItem(dialogid, itemid, newitemtext[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(itemid < 0) return 0;
- for(new di; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialogid][di][ItemID] != itemid) continue;
- format(DialogItems[dialogid][di][ItemText], MAX_ITEM_LENGTH, newitemtext);
- return 1;
- }
- return 0;
- }
- stock UpdateDialogCaption(dialogid, newcaption[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(newcaption[0] == EOS || strlen(newcaption) > MAX_CAPTION_LENGTH) return 0;
- format(DialogInfo[dialogid][DialogCaption], MAX_CAPTION_LENGTH, newcaption);
- return 1;
- }
- stock GetDialogCaption(dialogid, dest[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(caption[0] == EOS || strlen(caption) > MAX_CAPTION_LENGTH) return 0;
- strcat(dest, DialogInfo[dialogid][DialogCaption], MAX_CAPTION_LENGTH);
- return 1;
- }
- stock UpdateDialogButton1(dialogid, newbutton[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(newbutton[0] == EOS || strlen(newbutton) > MAX_BUTTON_LENGTH) return 0;
- format(DialogInfo[dialogid][Button1], MAX_BUTTON_LENGTH, newbutton);
- return 1;
- }
- stock GetDialogButton1(dialogid, dest[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(newbutton[0] == EOS || strlen(newbutton) > MAX_BUTTON_LENGTH) return 0;
- strcat(dest, DialogInfo[dialogid][Button1], MAX_BUTTON_LENGTH);
- return 1;
- }
- stock UpdateDialogButton2(dialogid, newbutton[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(strlen(newbutton) > MAX_BUTTON_LENGTH) return 0;
- format(DialogInfo[dialogid][Button2], MAX_BUTTON_LENGTH, newbutton);
- return 1;
- }
- stock GetDialogButton2(dialogid, dest[]) {
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- if(newbutton[0] == EOS || strlen(newbutton) > MAX_BUTTON_LENGTH) return 0;
- strcat(dest, DialogInfo[dialogid][Button2], MAX_BUTTON_LENGTH);
- return 1;
- }
- stock ShowDialogForPlayer(playerid, dialogid) {
- if(!IsPlayerConnected(playerid)) return 0;
- if(dialogid < 0 || dialogid >= sizeof(DialogInfo)) {
- PrintERROR("Dialog ID out of bounds array");
- return 0;
- }
- if(!DialogInfo[dialogid][DialogExist]) {
- PrintERROR("Dialog doesn't exist");
- return 0;
- }
- CurDialog[playerid] = dialogid;
- new msg[2048];
- for(new di = 0; di < MAX_DIALOG_ITEMS; di++) {
- if(DialogItems[dialogid][di][ItemID] == -1) continue;
- new tmp[MAX_ITEM_LENGTH+2];
- format(tmp, sizeof(tmp), "%s\n", DialogItems[dialogid][di][ItemText]);
- strcat(msg, tmp);
- }
- ShowPlayerDialog(playerid, dialogid+DIALOGID_OFFSET, DIALOG_STYLE_LIST, DialogInfo[dialogid][DialogCaption], msg, DialogInfo[dialogid][Button1], DialogInfo[dialogid][Button2]);
- return 1;
- }
- stock HideDialogForPlayer(playerid) {
- if(!IsPlayerConnected(playerid)) return 0;
- CurDialog[playerid] = -1;
- ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", " ");
- return 1;
- }
- stock GetPlayerDIalog(playerid) {
- if(!IsPlayerConnected(playerid)) return -1;
- return CurDialog[playerid];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement