interior.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include <YSI_Coding\y_hooks>
  2. #define MAX_INTERIORS 40
  3. #define MAX_INTERIOR_NAME 57
  4. static IntName[MAX_INTERIORS][MAX_INTERIOR_NAME];
  5. static IntInterior[MAX_INTERIORS];
  6. static Float:IntPosX[MAX_INTERIORS];
  7. static Float:IntPosY[MAX_INTERIORS];
  8. static Float:IntPosZ[MAX_INTERIORS];
  9. static Float:IntPosA[MAX_INTERIORS];
  10. new Iterator:Interior<MAX_INTERIORS>;
  11. hook OnMySQLConnected()
  12. {
  13. inline const OnInteriorFound()
  14. {
  15. for(new i; i < cache_num_rows(); i++)
  16. {
  17. if(Iter_Free(Interior) == INVALID_ITERATOR_SLOT)
  18. {
  19. printf("The maximum amount of interiors has been reached. (%d)", Iter_Count(Interior));
  20. break;
  21. }
  22. new interiorid = INVALID_ITERATOR_SLOT;
  23. cache_get_value_name_int(i, "id", interiorid);
  24. cache_get_value_name(i, "name", IntName[interiorid]);
  25. cache_get_value_name_int(i, "interior", IntInterior[interiorid]);
  26. cache_get_value_name_float(i, "pos_x", IntPosX[interiorid]);
  27. cache_get_value_name_float(i, "pos_y", IntPosY[interiorid]);
  28. cache_get_value_name_float(i, "pos_z", IntPosZ[interiorid]);
  29. cache_get_value_name_float(i, "pos_a", IntPosA[interiorid]);
  30. Iter_Add(Interior, interiorid);
  31. }
  32. }
  33. MySQL_TQueryInline(MySQL_GetHandle(), using inline OnInteriorFound, "SELECT * FROM interiors");
  34. }
  35. ShowAvailableInteriors(playerid)
  36. {
  37. new count;
  38. new listitemEx[MAX_INTERIORS];
  39. new string[1024];
  40. strcat(string, "These are the available interiors:\n");
  41. foreach(new i : Interior)
  42. {
  43. listitemEx[count] = i;
  44. count++;
  45. strcat(string, va_return("%d. %s\n", i, IntName[i]));
  46. }
  47. inline _response(response, listitem, string:inputtext[])
  48. {
  49. #pragma unused inputtext
  50. if(!response) return 0;
  51. ShowInteriorMenu(playerid, listitemEx[listitem]);
  52. }
  53. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_TABLIST_HEADERS, "Available interiors", string, "Next", "Close");
  54. return 1;
  55. }
  56. ShowInteriorMenu(playerid, interiorid)
  57. {
  58. inline _response(responseEx, listitemEx, string:inputtextEx[])
  59. {
  60. #pragma unused inputtextEx
  61. if(!responseEx) return ShowAvailableInteriors(playerid);
  62. switch(listitemEx)
  63. {
  64. case 0: // Edit the name
  65. {
  66. inline NameInput(response, listitem, string:inputtext[])
  67. {
  68. #pragma unused listitem
  69. if(!response) return ShowInteriorMenu(playerid, interiorid);
  70. if(isnull(inputtext) || IsNumeric(inputtext))
  71. {
  72. SendErrorMessage(playerid, "You specified an invalid name.");
  73. return ShowInteriorMenu(playerid, interiorid);
  74. }
  75. if(strlen(inputtext) > MAX_INTERIOR_NAME - 1)
  76. {
  77. SendErrorMessageF(playerid, "Invalid name length, it must be below %d characters.", MAX_INTERIOR_NAME - 1);
  78. return ShowInteriorMenu(playerid, interiorid);
  79. }
  80. format(IntName[interiorid], MAX_INTERIOR_NAME, inputtext);
  81. new query[128];
  82. mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE interiors SET name = '%e' WHERE id = %d", inputtext, interiorid);
  83. mysql_tquery(MySQL_GetHandle(), query);
  84. SendAdminWarningF(playerid, "You've set Interior ID %d name to %s.", interiorid, inputtext);
  85. }
  86. Dialog_ShowCallback(playerid, using inline NameInput, DIALOG_STYLE_INPUT, "Set the name", "{b3b3b3}Type the new name", "Ok", "Back");
  87. }
  88. case 1: // Teleport to interior
  89. {
  90. SetPlayerPos(playerid, IntPosX[interiorid], IntPosY[interiorid], IntPosZ[interiorid]);
  91. SetPlayerFacingAngle(playerid, IntPosA[interiorid]);
  92. SetPlayerInterior(playerid, IntInterior[interiorid]);
  93. SetCameraBehindPlayer(playerid);
  94. }
  95. case 2: // Delete the interior
  96. {
  97. inline DoubleCheck(pid, dialogid, response, listitem, string:inputtext[])
  98. {
  99. #pragma unused pid, dialogid, listitem, inputtext
  100. if(!response) return ShowInteriorMenu(playerid, interiorid);
  101. new query[78];
  102. mysql_format(MySQL_GetHandle(), query, sizeof(query), "DELETE FROM interiors WHERE id = %d", interiorid);
  103. mysql_tquery(MySQL_GetHandle(), query);
  104. Iter_Remove(Interior, interiorid);
  105. SendAdminWarningF(playerid, "You have deleted an interior. (ID %d)", interiorid);
  106. }
  107. Dialog_ShowCallback(playerid, using inline DoubleCheck, DIALOG_STYLE_MSGBOX, va_return("Deleting Interior ID %d", interiorid), "{b3b3b3}Are you sure?", "Yes", "No");
  108. }
  109. }
  110. }
  111. new string[182];
  112. strcat(string, "Please choose an option\n");
  113. strcat(string, va_return("Set the name {b3b3b3}(currently %s){eeeeee}\n", IntName[interiorid]));
  114. strcat(string, "Teleport to this interior\n");
  115. strcat(string, "{ff6666}Delete this interior");
  116. Dialog_ShowCallback(playerid, using inline _response, DIALOG_STYLE_TABLIST_HEADERS, va_return("Interior ID %d", interiorid), string, "Next", "Back");
  117. return 1;
  118. }
  119. CMD:createinterior(playerid, params[])
  120. {
  121. if(Iter_Free(Interior) == INVALID_ITERATOR_SLOT) return SendErrorMessage(playerid, "The maximum amount of interiors has been reached.");
  122. if(isnull(params))
  123. return SendSyntaxMessage(playerid, "/createinterior (name)");
  124. if(strlen(params) > MAX_INTERIOR_NAME - 1)
  125. return SendErrorMessageF(playerid, "Invalid name length, it must be below %d characters.", MAX_INTERIOR_NAME - 1);
  126. new Float:x, Float:y, Float:z, Float:a;
  127. GetPlayerPos(playerid, x, y, z);
  128. GetPlayerFacingAngle(playerid, a);
  129. new interiorid = Iter_Free(Interior);
  130. new int = GetPlayerInterior(playerid);
  131. IntInterior[interiorid] = int;
  132. IntPosX[interiorid] = x;
  133. IntPosY[interiorid] = y;
  134. IntPosZ[interiorid] = z;
  135. IntPosA[interiorid] = a;
  136. format(IntName[interiorid], MAX_INTERIOR_NAME, params);
  137. new query[236];
  138. mysql_format(MySQL_GetHandle(), query, sizeof(query), "INSERT INTO interiors (id, name, interior, pos_x, pos_y, pos_z, pos_a) VALUES (%d, '%e', %d, %f, %f, %f, %f)", interiorid, params, int, x, y, z, a);
  139. mysql_tquery(MySQL_GetHandle(), query);
  140. Iter_Add(Interior, interiorid);
  141. SendAdminWarningF(playerid, "You have created an interior. ID: %d, Name: %s", interiorid, params);
  142. return 1;
  143. }
  144. CMD:interiors(playerid, params[])
  145. {
  146. ShowAvailableInteriors(playerid);
  147. return 1;
  148. }
  149. stock Interior_GetName(interiorid)
  150. {
  151. return IntName[interiorid];
  152. }
  153. stock Interior_GetInterior(interiorid)
  154. {
  155. return IntInterior[interiorid];
  156. }
  157. stock Interior_GetPosition(interiorid, &Float:x, &Float:y, &Float:z, &Float:a = 0.0)
  158. {
  159. x = IntPosX[interiorid];
  160. y = IntPosY[interiorid];
  161. z = IntPosZ[interiorid];
  162. a = IntPosA[interiorid];
  163. }
  164. stock bool:IsValidInterior(interiorid)
  165. {
  166. if(Iter_Contains(Interior, interiorid))
  167. {
  168. return true;
  169. }
  170. return false;
  171. }