Guest User

New Dynamic Update System by Usman

a guest
Dec 16th, 2017
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. //Dynamic Update System
  2. #include <a_samp>
  3. #include <dini>
  4. #include <zcmd>
  5. #include <sscanf>
  6.  
  7. // Dialogs //
  8. #define DIALOG_UPDATED 50
  9. #define DIALOG_UPDATE 51
  10. #define DIALOG_UE 52
  11. #define DIALOG_U 53
  12.  
  13. // Colors //
  14. #define COLOR_WHITE 0xFFFFFFFF
  15. #define COLOR_YELLOW 0xFFFF00FF
  16. #define COLOR_RED 0xFF0000FF
  17.  
  18.  
  19. public OnFilterScriptInit()
  20. {
  21. print("\n--------------------------------------");
  22. print(" Dynamic Update System By Usman");
  23. print("--------------------------------------\n");
  24.  
  25. if (!dini_Exists("updates.ini")){ dini_Create("updates.ini");}
  26. return 1;
  27. }
  28.  
  29. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  30. {
  31. new updates = GetPVarInt(playerid, "UID");
  32. if(dialogid == DIALOG_UPDATE)
  33. {
  34. if(response)
  35. {
  36. if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_UPDATE, DIALOG_STYLE_INPUT, "adding update", "please write your update below", "Add", "Cancel");
  37. for(new x=1 ; x<560 ; x++)
  38. {
  39. new s[256];
  40. format(s, sizeof(s), "update%d", x);
  41. if(!dini_Isset("updates.ini", s))
  42. {
  43. new year, month, day;
  44. getdate(year, month, day);
  45. new utext[1024];
  46. format(utext, sizeof(utext), "%d/%d/%d", day, month, year);
  47. format(s, sizeof(s), "date%d", x);
  48. dini_Set("updates.ini", s, utext);
  49. format(utext, sizeof(utext), "%s", inputtext);
  50. format(s, sizeof(s), "update%d", x);
  51. dini_Set("updates.ini", s, utext);
  52. new dd = dini_Int("updates.ini", "MAX");
  53. dini_IntSet("updates.ini", "MAX", dd+1);
  54. format(s, sizeof(s), "Added update id %d. Your Update: '%s', and Date: %d/%d/%d.", x, inputtext, day, month, year);
  55. SendClientMessage(playerid, COLOR_YELLOW, s);
  56. break;
  57. }
  58. }
  59. return 1;
  60. }
  61. return 1;
  62. }
  63. if(dialogid == DIALOG_UE)
  64. {
  65. if(response)
  66. {
  67. if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_UE, DIALOG_STYLE_INPUT, "editing your update", "please write your update below", "Edit", "Cancel");
  68. new s[256];
  69. format(s, sizeof(s), "update%d", updates);
  70. if(dini_Isset("updates.ini", s))
  71. {
  72. new year, month, day;
  73. getdate(year, month, day);
  74. new utext[1024];
  75. format(utext, sizeof(utext), "%d/%d/%d", day, month, year, inputtext);
  76. format(s, sizeof(s), "date%d", updates);
  77. dini_Set("updates.ini", s, utext);
  78. format(s, sizeof(s), "update%d", updates);
  79. format(utext, sizeof(utext), "%s", inputtext);
  80. dini_Set("updates.ini", s, utext);
  81. format(s, sizeof(s), "Update editted '%s'", inputtext);
  82. SendClientMessage(playerid, COLOR_YELLOW, s);
  83. }
  84. else return SendClientMessage(playerid, COLOR_RED, "Error: Update Doesnt Exist!");
  85. return 1;
  86. }
  87. return 1;
  88. }
  89. return 1;
  90. }
  91.  
  92.  
  93. CMD:addupdate(playerid, params[])
  94. {
  95. if(!IsPlayerAdmin(playerid)) return 0;
  96. ShowPlayerDialog(playerid, DIALOG_UPDATE, DIALOG_STYLE_INPUT, "adding update", "please write your update below", "Add", "Cancel");
  97. return 1;
  98. }
  99.  
  100. CMD:editupdate(playerid, params[])
  101. {
  102. if(!IsPlayerAdmin(playerid)) return 0;
  103. new updates;
  104. if(sscanf(params, "d", updates)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /editupdate [update id]");
  105. SetPVarInt(playerid, "UID", updates);
  106. ShowPlayerDialog(playerid, DIALOG_UE, DIALOG_STYLE_INPUT, "editing update", "Write your new update below", "Edit", "Cancel");
  107. return 1;
  108. }
  109.  
  110. CMD:delupdate(playerid, params[])
  111. {
  112. if(!IsPlayerAdmin(playerid)) return 0;
  113. new ud;
  114. if(sscanf(params, "d", ud)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /delupdate [updateid]");
  115. new dd = dini_Int("updates.ini", "MAX");
  116. if(ud < dd) return SendClientMessage(playerid, COLOR_RED, "Error: Update Doesn't Exist!");
  117. new tmp[256], h[256];
  118. format(tmp, sizeof(tmp), "update%d", ud);
  119. format(h, sizeof(h), "date%d", ud);
  120. dini_Unset("updates.ini", tmp);
  121. dini_Unset("updates.ini", h);
  122. dini_IntSet("updates.ini", "MAX", dd-1);
  123. new string[250];
  124. format(string, sizeof(string), "Update %d has removed.", ud);
  125. SendClientMessage(playerid, COLOR_YELLOW, string);
  126. return 1;
  127. }
  128.  
  129. CMD:updates(playerid, params[])
  130. {
  131. new tmp[256], tmp4[512];
  132. new dd = dini_Int("updates.ini", "MAX");
  133. if (dd == 0) return SendClientMessage(playerid, COLOR_RED, "Currently There are no update.");
  134. new tmp3[512], h[256];
  135.  
  136. for (new u = 1; u <= dd; u++)
  137. {
  138. format(tmp, 20, "update%d", u);
  139. format(h, sizeof(h), "date%d", u);
  140. format(tmp, sizeof(tmp), "%s", dini_Get("updates.ini", tmp));
  141. format(tmp3, sizeof(tmp3), "%s%s.\t%s\n", tmp3, tmp, dini_Get("updates.ini", h));
  142. }
  143. format(tmp4, sizeof(tmp4), "Updates\tDate Of Update\n%s", tmp3);
  144. ShowPlayerDialog(playerid, DIALOG_UPDATED, DIALOG_STYLE_TABLIST_HEADERS, "{FF0000}Server Name {FFFFFF}- Server Updates", tmp4, "Ok", "");
  145. return 1;
  146. }
  147.  
  148. CMD:maxupdates(playerid, params[])
  149. {
  150. new str[256];
  151. if(!IsPlayerAdmin(playerid)) return 0;
  152. new dd = dini_Int("updates.ini", "MAX");
  153. format(str, sizeof(str), "Currently we have %d updates.", dd);
  154. SendClientMessage(playerid, COLOR_YELLOW, str);
  155. return 1;
  156. }
Add Comment
Please, Sign In to add comment