Advertisement
horsemeat

MultipageV1

Aug 31st, 2014
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.19 KB | None | 0 0
  1. //-------------------------------Horsemeat------------------------------------//
  2. //-------------------------------Multipage-----------------------------------//
  3. //-----------------------------------V1-------------------------------------//
  4. //-------------------------------horsemeat---------------------------------//
  5. //-----------------------------built-on-0.3z------------------------------//
  6. //--------------------LastUpdate-for-0.3z-8,31,2014----------------------//
  7. //go here for the latest updates ---------------------------------------//
  8. #pragma dynamic 20000
  9. #include <a_samp>
  10. #include <ysi\y_dialog>
  11. #include <ysu\y_inline>
  12. #if defined _multipage_included
  13. #endinput
  14. #endif
  15. #define _multipage_included
  16. forward MenuPageString(playerid,index,dialogid,string[],size);
  17. forward MenuPageReturn(playerid,index,dialogid);
  18. MenuPage(playerid,did, data[], size, string:label[],string:button1[],string:button2[])
  19. {
  20.     new page;
  21.     new bool:nextpage = false;
  22.     inline MenuPageD(pid, dialogid, response, listitem, string:inputtext[])
  23.     {
  24.         #pragma unused dialogid, pid, inputtext
  25.         if(response)
  26.         {
  27.             if(listitem == 10)
  28.             {  
  29.                 if(nextpage)
  30.                 {
  31.                     page = page + 10;
  32.                     Dialog_ShowCallback(playerid,using inline MenuPageD, DIALOG_STYLE_LIST,label ,MenuPageText(playerid,page,did,nextpage,data,size), button1,button2);
  33.                 }
  34.                 else
  35.                 {
  36.                     Dialog_ShowCallback(playerid,using inline MenuPageD, DIALOG_STYLE_LIST, label,MenuPageText(playerid,page,did,nextpage,data,size), button1,button2);
  37.                 }
  38.             }
  39.             else if(listitem == 11)
  40.             {
  41.                 if(page >= 10)
  42.                 {
  43.                     page = page - 10;
  44.                     Dialog_ShowCallback(playerid,using inline MenuPageD, DIALOG_STYLE_LIST, label,MenuPageText(playerid,page,did,nextpage,data,size), button1,button2);
  45.                 }
  46.                 else
  47.                 {
  48.                     Dialog_ShowCallback(playerid,using inline MenuPageD, DIALOG_STYLE_LIST, label,MenuPageText(playerid,page,did,nextpage,data,size), button1,button2);
  49.                 }
  50.             }
  51.             else
  52.             {
  53.                 new selected = MenuPageSelected(page,listitem,data,size);
  54.                 CallRemoteFunction("MenuPageReturn","iii",playerid,selected,did);
  55.             }
  56.         }
  57.     }
  58.     Dialog_ShowCallback(playerid,using inline MenuPageD, DIALOG_STYLE_LIST, label, MenuPageText(playerid,page,did,nextpage,data,size), button1,button2);
  59. }
  60. stock MenuPageSelected(page,selected,data[],size)
  61. {
  62.     new limitcount,actualcount;
  63.     for(new count;count < size;count++)
  64.     {
  65.         if((data[count])==1)
  66.         {
  67.             if((limitcount) >= page)
  68.             {
  69.                 if((actualcount) == selected)
  70.                 {
  71.                     return count;
  72.                 }
  73.                 else
  74.                 {
  75.                     actualcount++;
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 limitcount++;
  81.             }
  82.         }
  83.     }
  84.     return -1;
  85. }
  86. stock MenuPageText(playerid,page,dialogid,&bool:nextpage,data[],size)
  87. {
  88.     new string[1024],stradd[1024],limitcount,actualcount;
  89.     for(new count;count < size;count++)
  90.     {
  91.         if((data[count])==1)
  92.         {
  93.             if((limitcount) >= page)
  94.             {
  95.                 if((actualcount) < 10)
  96.                 {
  97.                     actualcount++;
  98.                     new str[256];
  99.                     format(str,sizeof(str),"%s",GetStringForPage(playerid,count,dialogid));
  100.                     if(isnull(string))
  101.                     {
  102.                         format(string,sizeof(string),"%s",str);
  103.                     }
  104.                     else
  105.                     {
  106.                         format(stradd,sizeof(stradd),"%s\n%s",string,str);
  107.                         format(string,sizeof(string),"%s",stradd);
  108.                     }
  109.                 }
  110.                 else
  111.                 {
  112.                     break;
  113.                 }
  114.             }
  115.             else
  116.             {
  117.                 limitcount++;
  118.             }
  119.         }
  120.     }
  121.     if((actualcount)==10)
  122.     {
  123.         if(CheckNextPage(page,data,size))
  124.         {
  125.             nextpage = true;
  126.             format(stradd,sizeof(stradd),"%s\nNextpage",string);
  127.             format(string,sizeof(string),"%s",stradd);
  128.         }
  129.     }
  130.     else
  131.     {
  132.         nextpage = false;
  133.         while(actualcount != 10)
  134.         {
  135.             actualcount++;
  136.             if(isnull(string))
  137.             {
  138.                 format(string,sizeof(string),"empty");
  139.             }
  140.             else
  141.             {
  142.                 format(stradd,sizeof(stradd),"%s\nempty",string);
  143.                 format(string,sizeof(string),"%s",stradd);
  144.             }
  145.         }
  146.         format(stradd,sizeof(stradd),"%s\nNo Next Page",string);
  147.         format(string,sizeof(string),"%s",stradd);
  148.     }
  149.     if((page) >= 10)
  150.     {
  151.         format(stradd,sizeof(stradd),"%s\nLast Page",string);
  152.         format(string,sizeof(string),"%s",stradd);
  153.     }
  154.     return string;
  155. }
  156. stock CheckNextPage(page,data[],size)
  157. {
  158.     new limitcount = 0;
  159.     new npage = page + 10;
  160.     for(new count;count < size;count++)
  161.     {
  162.         if((data[count])==1)
  163.         {
  164.             if((limitcount) >= npage)
  165.             {
  166.                 return true;
  167.             }
  168.             else
  169.             {
  170.                 limitcount++;
  171.             }
  172.         }
  173.     }
  174.     return false;
  175. }
  176. stock GetStringForPage(playerid,index,dialogid)
  177. {
  178.     new text[256];
  179.     format(text,sizeof(text),"Test\n");
  180.     CallLocalFunction2("MenuPageString","iiisi",playerid,index,dialogid,text,sizeof(text));
  181.     return text;
  182. }
  183. //Thanks Slice/Y_Less for this script
  184. //http://forum.sa-mp.com/showpost.php?p=1642880&postcount=2950
  185. stock CallLocalFunction2(const szFunction[], const szFormat[], {Float, _}:...)
  186. {
  187.     new
  188.              iFunc,
  189.              iIndex,
  190.              iTemp,
  191.              iNumArgs = strlen(szFormat),
  192.              iArg = iNumArgs,
  193.         bool:bPackedFormat = ispacked(szFormat)
  194.     ;
  195.    
  196.     // Get the function's address
  197.     if (-1 != (iIndex = funcidx(szFunction))) {
  198.         // Load the offset to DAT from the prefix
  199.         #emit LCTRL        1
  200.        
  201.         // Invert it so we have the offset to the prefix from DAT
  202.         #emit NEG
  203.        
  204.         // Copy it to alt for use later
  205.         #emit MOVE.alt
  206.        
  207.         // Add 32 to jump to the offset containing the public function's table
  208.         #emit ADD.C        32
  209.        
  210.         // Read the value there; must be done using LREF because
  211.         // it's outside of the DAT section
  212.         #emit STOR.S.pri   iTemp
  213.         #emit LREF.S.pri   iTemp
  214.        
  215.         // Add the value we just loaded to the prefix (that we stored in alt)
  216.         #emit ADD
  217.        
  218.         // Add index * 8 (each entry contains 2 cells - a pointer to the function's name
  219.         // and a pointer to the function itself, relative to COD).
  220.         #emit LOAD.S.alt   iIndex
  221.         #emit SHL.C.alt    3
  222.        
  223.         // Add that to the offset
  224.         #emit ADD
  225.        
  226.         // Now get the address it's pointing to. This seems to only work
  227.         // using LREF (as opposed to LOAD.I, for example).
  228.         #emit STOR.S.pri   iTemp
  229.         #emit LREF.S.pri   iTemp
  230.        
  231.         // Now store it
  232.         #emit STOR.S.pri   iFunc
  233.     } else {
  234.         return 0;
  235.     }
  236.    
  237.     while (--iArg >= 0) {
  238.         switch (bPackedFormat ? szFormat{iArg} : szFormat[iArg]) {
  239.             // String, array, and variables passed by reference
  240.             case 's', 'a', 'v': {
  241.                 // Load the frame pointer
  242.                 #emit LCTRL 5
  243.                
  244.                 // Add 12 + (2 + iArg) * 4 to get the argument we want
  245.                 #emit LOAD.S.alt  iArg
  246.                 #emit SHL.C.alt   2
  247.                 #emit ADD
  248.                 #emit ADD.C       20
  249.                
  250.                 // Load the address there
  251.                 #emit LOAD.I
  252.                
  253.                 // Push that address
  254.                 #emit PUSH.pri
  255.             }
  256.            
  257.             // Single-cell arguments passed by value; I used "default"
  258.             // here because it seems that's what CallLocalFunction does.
  259.             default: {
  260.                 // Load the frame pointer
  261.                 #emit LCTRL 5
  262.                
  263.                 // Add 12 + (2 + iArg) * 4 to get the argument we want
  264.                 #emit LOAD.S.alt  iArg
  265.                 #emit SHL.C.alt   2
  266.                 #emit ADD
  267.                 #emit ADD.C       20
  268.                
  269.                 // Load the address there
  270.                 #emit LOAD.I
  271.                
  272.                 // Load the value that address points to
  273.                 #emit LOAD.I
  274.                
  275.                 // Push that value
  276.                 #emit PUSH.pri
  277.             }
  278.         }
  279.     }
  280.    
  281.     // Push iNumArgs * 4
  282.     #emit LOAD.S.pri  iNumArgs
  283.     #emit SHL.C.pri   2
  284.     #emit PUSH.pri
  285.    
  286.     // Push the return address
  287.     #emit LCTRL       6
  288.     #emit ADD.C       28
  289.     #emit PUSH.pri
  290.    
  291.     // Call the function
  292.     #emit LOAD.S.pri  iFunc
  293.     #emit SCTRL       6
  294.    
  295.     // Restore the stack
  296.     #emit STACK       24
  297.    
  298.     // Return (pri is the return value, which comes from iFunc)
  299.     #emit RETN
  300.    
  301.     // Never actually happens
  302.     return 0;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement