Advertisement
Meta__

AntiDesktopDialog v0.2

Oct 8th, 2011
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.74 KB | None | 0 0
  1. /*****************************************************************************************************************************
  2. **                                                                                                                          **
  3. **  AntiDesktopDialog v0.2 by Meta                                                                                          **
  4. **                                                                                                                          **
  5. **  It's a simple solution for I-came-from-desktop-with-ESC-or-return-and-answered-the-dialog-problems!                     **
  6. **  This include makes the dialog display again and aborts any processing from the dialog that has been sent by mistake.    **
  7. **                                                                                                                          **
  8. **  Copyright 2011 Meta (metax@freenet.de, http://meta.spitnex.de/?lang=en). All rights reserved.                           **
  9. **                                                                                                                          **
  10. *****************************************************************************************************************************/
  11.  
  12. // Detect wheather the player is AFK.
  13. public OnPlayerUpdate(playerid)
  14. {
  15.     if(GetPVarType(playerid, "DesktopTimer") == 0)
  16.     {
  17.         SetPVarInt(playerid, "DesktopTimer", SetTimerEx("Desktop_Function",1000,1,"d",playerid));
  18.     }
  19.     SetPVarInt(playerid, "DesktopCount", GetPVarInt(playerid, "DesktopCount")+1);
  20.     CallLocalFunction("ADD_OnPlayerUpdate", "d", playerid);
  21.     return 1;
  22. }
  23.  
  24. #if defined _ALS_OnPlayerUpdate
  25.     #undef OnPlayerUpdate
  26. #else
  27.     #define _ALS_OnPlayerUpdate
  28. #endif
  29. #define OnPlayerUpdate ADD_OnPlayerUpdate
  30.  
  31. public OnPlayerDisconnect(playerid, reason)
  32. {
  33.     KillTimer(GetPVarInt(playerid, "DesktopTimer"));
  34.     return CallLocalFunction("ADD_OnPlayerDisconnect", "dd", playerid, reason);
  35. }
  36.  
  37. #if defined _ALS_OnPlayerDisconnect
  38.     #undef OnPlayerDisconnect
  39. #else
  40.     #define _ALS_OnPlayerDisconnect
  41. #endif
  42. #define OnPlayerDisconnect ADD_OnPlayerDisconnect
  43.  
  44. // Processing a count of seconds the player's been AFK. Needed later.
  45. public Desktop_Function(playerid)
  46. {
  47.     if(GetPlayerState(playerid) != PLAYER_STATE_WASTED && !IsPlayerNPC(playerid) && IsPlayerConnected(playerid))
  48.     {
  49.         if(GetPVarInt(playerid, "DesktopCount") > 0) { SetPVarInt(playerid, "DesktopStatus", 0); }
  50.         else if(GetPVarInt(playerid, "DesktopCount") <= 0) { SetPVarInt(playerid, "DesktopStatus", GetPVarInt(playerid, "DesktopStatus")+1); }
  51.         SetPVarInt(playerid, "DesktopCount", 0);
  52.     }
  53.     return 1;
  54. }
  55.  
  56. // Returns the PVar's String. By Meta.
  57. stock ReturnPVarString(playerid, varname[])
  58. {
  59.     new varstring[256]; // Make it longer if you've got some dialogs with huge texts. But use it with caution because if this is too big, the dialog probably won't be displayed again!
  60.     GetPVarString(playerid, varname, varstring, sizeof(varstring));
  61.     return varstring;
  62. }
  63.  
  64. // Catch the dialog that has been sent by mistake and let it pop up again.
  65. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  66. {
  67.     if(GetPVarInt(playerid, "DesktopStatus") > 1)
  68.     {
  69.         return ShowPlayerDialog(playerid, GetPVarInt(playerid, "PrevDialogID"), GetPVarInt(playerid, "PrevDialogStyle"), ReturnPVarString(playerid, "PrevDialogCaption"), ReturnPVarString(playerid, "PrevDialogInfo"), ReturnPVarString(playerid, "PrevDialogButton1"), ReturnPVarString(playerid, "PrevDialogButton2"));
  70.     }
  71.     if(inputtext[0] == '\0' || !strlen(inputtext)) { format(inputtext, 128, " "); }
  72.     return CallLocalFunction("ADD_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
  73. }
  74.  
  75. #if defined _ALS_OnDialogResponse
  76.     #undef OnDialogResponse
  77. #else
  78.     #define _ALS_OnDialogResponse
  79. #endif
  80. #define OnDialogResponse ADD_OnDialogResponse
  81.  
  82.  
  83. // Catch the Dialog's Data and store it into PVars.
  84. public ShowPlayerDialogWithAntiDesktop(playerid, dialogid, style, caption[], info[], button1[], button2[])
  85. {
  86.     SetPVarInt(playerid, "PrevDialogID", dialogid);
  87.     SetPVarInt(playerid, "PrevDialogStyle", style);
  88.     SetPVarString(playerid, "PrevDialogCaption", caption);
  89.     SetPVarString(playerid, "PrevDialogInfo", info);
  90.     SetPVarString(playerid, "PrevDialogButton1", button1);
  91.     SetPVarString(playerid, "PrevDialogButton2", button2);
  92.     //SendClientMessage(playerid, 0xFFFFFFFF, "ShowPlayerDialog"); // Debug
  93.     return ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  94. }
  95.  
  96. #define ShowPlayerDialog ShowPlayerDialogWithAntiDesktop
  97.  
  98. forward ADD_OnPlayerUpdate(playerid);
  99. forward ADD_OnPlayerDisconnect(playerid, reason);
  100. forward Desktop_Function(playerid);
  101. forward ADD_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  102. forward ShowPlayerDialogWithAntiDesktop(playerid, dialogid, style, caption[], info[], button1[], button2[]);
  103.  
  104. /* == EOF == */
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement