hotel_rooms.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // This function begins to load all hotel rooms
  2. forward LoadHotelRooms();
  3. public LoadHotelRooms() {
  4. printf("[Hotel System] Query made to fetch hotel rooms...");
  5. new hotelQuery[100];
  6. mysql_format(sqlGameConnection, hotelQuery, sizeof(hotelQuery), "SELECT * FROM `hotelrooms`");
  7. mysql_pquery(sqlGameConnection, hotelQuery, "OnHotelRoomsLoaded");
  8. return 1;
  9. }
  10. // Called when all hotel room data has been loaded
  11. forward OnHotelRoomsLoaded();
  12. public OnHotelRoomsLoaded() {
  13. new hotelRows = cache_num_rows();
  14. if(hotelRows < 1) {
  15. printf("[Hotel System] No hotel rooms found in the database.");
  16. return 1;
  17. }
  18. printf("[Hotel System] %i hotel rooms found. Start loading...", hotelRows);
  19. for(new i = 0; i < hotelRows; i++) {
  20. new foundhID = cache_get_field_content_int(i, "ID");
  21. new foundhHotelID = cache_get_field_content_int(i, "HotelID");
  22. new foundhOwnerID = cache_get_field_content_int(i, "OwnerID");
  23. new foundhVW = cache_get_field_content_int(i, "VW");
  24. new foundhInt = cache_get_field_content_int(i, "Interior");
  25. new Float:foundhPos[3];
  26. foundhPos[0] = cache_get_field_content_float(i, "X");
  27. foundhPos[1] = cache_get_field_content_float(i, "Y");
  28. foundhPos[2] = cache_get_field_content_float(i, "Z");
  29. new foundCreatedBy[MAX_PLAYER_NAME + 1];
  30. cache_get_field_content(i, "CreatedBy", foundCreatedBy);
  31. CreateHotelRoom(foundhID, foundhHotelID, foundhOwnerID, foundhPos[0], foundhPos[1], foundhPos[2], foundhVW, foundhInt, foundCreatedBy);
  32. }
  33. return 1;
  34. }
  35. // This function saves all hotel rooms
  36. // this should be called when the server exits
  37. SaveHotelRooms() {
  38. for(new i = 0; i < MAX_HOTELROOMS; i++) {
  39. if(HotelRoomInfo[i][hUsed]) SaveHotelRoom(i);
  40. }
  41. return 1;
  42. }
  43. // This function saves a hotel room
  44. SaveHotelRoom(roomID) {
  45. if(!HotelRoomInfo[roomID][hUsed])
  46. return false;
  47. new hotelSaveQuery[500];
  48. format(hotelSaveQuery, sizeof(hotelSaveQuery),
  49. "REPLACE INTO `hotelrooms`\
  50. (ID,\
  51. OwnerID,\
  52. X,\
  53. Y,\
  54. Z,\
  55. VW,\
  56. Interior,\
  57. CreatedBy)\
  58. VALUES(%d, %d, %f, %f, %f, %d, %d, %e)",
  59. HotelRoomInfo[roomID][hSQLID],
  60. HotelRoomInfo[roomID][hOwnerID],
  61. HotelRoomInfo[roomID][hX],
  62. HotelRoomInfo[roomID][hY],
  63. HotelRoomInfo[roomID][hZ],
  64. HotelRoomInfo[roomID][hVW],
  65. HotelRoomInfo[roomID][hInt],
  66. HotelRoomInfo[roomID][hCreatedBy]
  67. );
  68. mysql_pquery(sqlGameConnection, hotelSaveQuery);
  69. printf("[Hotel System] Hotel room ID %i saved. (SQL %i)", roomID, HotelRoomInfo[roomID][hSQLID]);
  70. return 1;
  71. }
  72. // Show information related to the nearest hotel room
  73. CMD:hroominfo(playerid, params[]) {
  74. if(PlayerInfo[playerid][pDev] < 2)
  75. return AdmErrorMsg;
  76. new nearRoom = GetNearbyHotelRoom(playerid, 2.0);
  77. if(nearRoom == INVALID_HOTEL_ROOM)
  78. return SendClientMessage(playerid, COLOR_GREY, "You are not near any hotel room.");
  79. new hInfoStr[128];
  80. format(hInfoStr, sizeof(hInfoStr), "[Hotel Room ID %i]", nearRoom);
  81. SendClientMessage(playerid, SAMP_COLOR, hInfoStr);
  82. format(hInfoStr, sizeof(hInfoStr), "Owner: %s (SQL %i), Created by: %s, Hotel: %s",
  83. HotelRoomInfo[nearRoom][hOwnerName],
  84. HotelRoomInfo[nearRoom][hOwnerID],
  85. HotelRoomInfo[nearRoom][hCreatedBy],
  86. GetHotelName(HotelRoomInfo[nearRoom][hHotelID])
  87. );
  88. SendClientMessage(playerid, SAMP_COLOR, hInfoStr);
  89. return 1;
  90. }
  91. // Command to teleport to a hotel room
  92. CMD:gotohroom(playerid, params[]) {
  93. if(PlayerInfo[playerid][pDev] < 2)
  94. return AdmErrorMsg;
  95. new hroomID;
  96. if(sscanf(params, "i", hroomID))
  97. return SendClientMessage(playerid, COLOR_WHITE, "{00BFFF}USAGE:{FFFFFF} /gotohroom [hotel room ID]");
  98. if(hroomID < 0 || hroomID > MAX_HOTELROOMS)
  99. return SendClientMessage(playerid, COLOR_GREY, "You entered an invalid hotel room ID.");
  100. if(!HotelRoomInfo[hroomID][hUsed])
  101. return SendClientMessage(playerid, COLOR_GREY, "This hotel room ID does not exist.");
  102. // Teleport the player
  103. Timer_FreezePlayer(playerid, FREEZE, ENTER_FREEZE);
  104. SetPlayerPos(playerid, HotelRoomInfo[hroomID][hX], HotelRoomInfo[hroomID][hY], HotelRoomInfo[hroomID][hZ]);
  105. SetPlayerVirtualWorld(playerid, HotelRoomInfo[hroomID][hVW]);
  106. SetPlayerInterior(playerid, HotelRoomInfo[hroomID][hInt]);
  107. // Show center HUD
  108. new hotelStr[128];
  109. format(hotelStr, sizeof(hotelStr), "~w~Teleported to hotel room ~r~ID %i~w~.", hroomID);
  110. displayCenterHUDInfo(playerid, hotelStr, 8);
  111. return 1;
  112. }
  113. // Create a new hotel room in-game
  114. CreateHotelRoom(sethID, sethHotelID, sethOwnerID, Float:sethX, Float:sethY, Float:sethZ, sethVW, sethInt, sethCreatedBy[]) {
  115. // Find an available hotel room
  116. new availableHotel = -1;
  117. for(new i = 0; i < MAX_HOTELROOMS; i++) {
  118. if(!HotelRoomInfo[i][hUsed]) {
  119. availableHotel = i;
  120. break;
  121. }
  122. }
  123. if(availableHotel == -1) {
  124. printf("Max amount of hotel rooms reached! (%i)", MAX_HOTELROOMS);
  125. return 1;
  126. }
  127. HotelRoomInfo[availableHotel][hUsed] = true;
  128. HotelRoomInfo[availableHotel][hSQLID] = sethID;
  129. HotelRoomInfo[availableHotel][hHotelID] = sethHotelID;
  130. HotelRoomInfo[availableHotel][hOwnerID] = sethOwnerID;
  131. HotelRoomInfo[availableHotel][hVW] = sethVW;
  132. HotelRoomInfo[availableHotel][hInt] = sethInt;
  133. HotelRoomInfo[availableHotel][hX] = sethX;
  134. HotelRoomInfo[availableHotel][hY] = sethY;
  135. HotelRoomInfo[availableHotel][hZ] = sethZ;
  136. format(HotelRoomInfo[availableHotel][hCreatedBy], MAX_PLAYER_NAME + 1, "%s", sethCreatedBy);
  137. RefreshHotelVisual(availableHotel, true);
  138. printf("[Hotel System] Hotel room %i created. (SQL %i)", availableHotel, sethID);
  139. return 1;
  140. }
  141. // Refresh the "visuals" of a hotel room (pickup, 3D text)
  142. RefreshHotelVisual(hotelID, bool:findName = false) {
  143. DestroyDynamic3DTextLabel(HotelRoomInfo[hotelID][hText3D]);
  144. DestroyDynamicPickup(HotelRoomInfo[hotelID][hPickupID]);
  145. if(HotelRoomInfo[hotelID][hUsed]) {
  146. new displayOwner[MAX_PLAYER_NAME + 1];
  147. if(HotelRoomInfo[hotelID][hOwnerID] != 0) {
  148. if(!findName) {
  149. format(displayOwner, sizeof(displayOwner), "%s", HotelRoomInfo[hotelID][hOwnerName]);
  150. }
  151. else {
  152. new nameQuery[100];
  153. mysql_format(sqlGameConnection, nameQuery, sizeof(nameQuery), "SELECT Name FROM players WHERE ID = %d", HotelRoomInfo[hotelID][hOwnerID]);
  154. mysql_pquery(sqlGameConnection, nameQuery, "OnRoomOwnerFetched", "i", hotelID);
  155. return 1;
  156. }
  157. }
  158. else {
  159. format(displayOwner, sizeof(displayOwner), "Nobody");
  160. format(HotelRoomInfo[hotelID][hOwnerName], MAX_PLAYER_NAME + 1, "Nobody");
  161. }
  162. new hotelStr[150];
  163. format(hotelStr, sizeof(hotelStr), "Hotel Room{FFFFFF}\nOwner: %s\nRoom number: %i\nType /enter to go inside.", displayOwner, hotelID);
  164. HotelRoomInfo[hotelID][hText3D] = CreateDynamic3DTextLabel(hotelStr, COLOR_HOTELTEXT, HotelRoomInfo[hotelID][hX], HotelRoomInfo[hotelID][hY], HotelRoomInfo[hotelID][hZ] +0.88, 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, HotelRoomInfo[hotelID][hVW], HotelRoomInfo[hotelID][hInt], -1, 100);
  165. HotelRoomInfo[hotelID][hPickupID] = CreateDynamicPickup(HOTEL_PICKUP, 1, HotelRoomInfo[hotelID][hX], HotelRoomInfo[hotelID][hY], HotelRoomInfo[hotelID][hZ], HotelRoomInfo[hotelID][hVW]);
  166. }
  167. return 1;
  168. }
  169. // Called when the name of a hotel room owner is found
  170. forward OnRoomOwnerFetched(roomID);
  171. public OnRoomOwnerFetched(roomID) {
  172. new rows, fields, displayOwner[MAX_PLAYER_NAME + 1];
  173. cache_get_data(rows, fields);
  174. if(!rows) {
  175. format(displayOwner, sizeof(displayOwner), "Unknown");
  176. }
  177. else {
  178. cache_get_field_content(0, "Name", displayOwner);
  179. }
  180. format(HotelRoomInfo[roomID][hOwnerName], MAX_PLAYER_NAME + 1, "%s", displayOwner);
  181. printf("[Hotel System] Owner found for room ID %i (%s)", roomID, displayOwner);
  182. RefreshHotelVisual(roomID);
  183. return 1;
  184. }
  185. // Get the ID of the nearest hotel room to a player
  186. GetNearbyHotelRoom(playerid, Float:hotelRange = 5.0) {
  187. for(new i = 0; i < MAX_HOTELROOMS; i++) {
  188. if(!HotelRoomInfo[i][hUsed]) continue;
  189. if(IsPlayerInRangeOfPoint(playerid, hotelRange, HotelRoomInfo[i][hX], HotelRoomInfo[i][hY], HotelRoomInfo[i][hZ])) {
  190. if(GetPlayerVirtualWorld(playerid) == HotelRoomInfo[i][hVW]) {
  191. if(GetPlayerInterior(playerid) == HotelRoomInfo[i][hInt])
  192. return i;
  193. }
  194. }
  195. }
  196. return INVALID_HOTEL_ROOM;
  197. }