SA-MP Forums Archive
[Include] Callback Dialogs (Faster processing dialogs) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Callback Dialogs (Faster processing dialogs) (/showthread.php?tid=266799)



Callback Dialogs (Faster processing dialogs) - clavador - 06.07.2011

NOTE: After testing, switch statements are faster than this (not that much). Anyway, be free to use it if you want to have a more well presented script file, as this gives you the possibility to separate dialogs in functions.


This include will give you the ability to call dialogs directly as if they are callbacks (that means that you dont have to fill your code with lots of ifs or switches).

This include is similar to Gamer_Z one, but I made my own because I couldn't get it to work with JunkBuster and I thought of releasing it for whoever may need it.

Thanks to Gamer_Z for the idea:

(i fixed the bug where i forgot to remove the dialogid from the define)

pawn Код:
//
//   Made by Clavador
//  original idea by
//       gamer_Z (Thanks)
//    find it here:
// https://sampforum.blast.hk/showthread.php?tid=260298


new DialogToCall[24];

// REMOVE THIS CALLBACK FROM ALL YOUR OTHER SCRIPTS
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{  
        format(DialogToCall,24,"DialogResponse_%d",dialogid); // DONT USE NEGATIVE CALLBACKS
        if(isnull(inputtext))format(inputtext,2,"\1");
        if(funcidx(DialogToCall) != -1)
    return CallLocalFunction(DialogToCall,"iiis",playerid,response,listitem,inputtext);
       
        return 0;
}

// DEFINE THE FUNCTION
#define Dialog(%1) forward DialogResponse_%1(playerid, response, listitem, inputtext[]); \
                   public DialogResponse_%1(playerid, response, listitem, inputtext[])

/*

REPLACE YOUR if(dialogid == 1) with this function

Dialog(1) // (playerid,response,lisitem,inputtext[]) are passed as always
{
   if(response)
   {
       //do something  
   }
   return 1;
}

*/



Re: Callback Dialogs (Faster processing dialogs) - VivianKris - 06.07.2011

great!


Re: Callback Dialogs (Faster processing dialogs) - LZLo - 06.07.2011

excellent!