func.pwn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. ShowVehicleDialog(playerid, dialogid) {
  2. switch(dialogid) {
  3. case DIALOGID_VEHICLE_MAIN: {
  4. new vehicleid = GetPlayerEditVehicle(playerid);
  5. if( !IsValidVehicle(vehicleid) ) {
  6. return 1;
  7. }
  8. g_DialogInfo = "";
  9. for(new listitem; listitem < MAX_LISTITEMS_VEHICLE; listitem ++) {
  10. switch(listitem) {
  11. case LISTITEM_VEHICLE_GOTO: {
  12. strcat(g_DialogInfo, "Goto\t \n");
  13. }
  14. case LISTITEM_VEHICLE_GET: {
  15. strcat(g_DialogInfo, "Get\t \n");
  16. }
  17. case LISTITEM_VEHICLE_DRIVE: {
  18. strcat(g_DialogInfo, "Drive\t \n");
  19. }
  20. case LISTITEM_VEHICLE_COORD: {
  21. strcat(g_DialogInfo, "Coordinates & Rotation\t \n");
  22. }
  23. case LISTITEM_VEHICLE_MOVE: {
  24. strcat(g_DialogInfo, "Click & Drag Move\t \n");
  25. }
  26. case LISTITEM_VEHICLE_ATTACH: {
  27. new objectid = g_PlayerData[playerid][PLAYER_DATA_EDIT_ATTACHOBJECT];
  28. if( !IsValidObject(objectid) ) {
  29. strcat(g_DialogInfo, " \t \n");
  30. } else {
  31. strunpack(g_CommentString, g_ObjectData[objectid-1][OBJECT_DATA_COMMENT], MAX_COMMENT_LEN+1);
  32. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Attach Selected Object\t%s\n", g_CommentString);
  33. strcat(g_DialogInfo, g_DialogInfoRow);
  34. }
  35. }
  36. case LISTITEM_VEHICLE_DUPLICATE: {
  37. strcat(g_DialogInfo, "Duplicate\t \n");
  38. }
  39. case LISTITEM_VEHICLE_RECREATE: {
  40. strcat(g_DialogInfo, "Re-Create\t \n");
  41. }
  42. case LISTITEM_VEHICLE_REMOVE: {
  43. strcat(g_DialogInfo, "Remove\t \n");
  44. }
  45. case LISTITEM_VEHICLE_COMMENT: {
  46. strunpack(g_CommentString, g_VehicleData[vehicleid-1][VEHICLE_DATA_COMMENT], MAX_COMMENT_LEN+1);
  47. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Comment\t%s\n", g_CommentString);
  48. strcat(g_DialogInfo, g_DialogInfoRow);
  49. }
  50. case LISTITEM_VEHICLE_COMMENT_RESET: {
  51. GetVehicleModelName(GetVehicleModel(vehicleid), g_VehModelString, sizeof g_VehModelString);
  52. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Reset Comment To\t%s\n", g_VehModelString);
  53. strcat(g_DialogInfo, g_DialogInfoRow);
  54. }
  55. case LISTITEM_VEHICLE_COLOR1: {
  56. new colorid = g_VehicleData[vehicleid-1][VEHICLE_DATA_COLOR_1];
  57. if( colorid == INVALID_COLOR_ID ) {
  58. strcat(g_DialogInfo, "Color 1\tUnknown\n");
  59. } else {
  60. new rgb = GetVehicleColorRGB(colorid);
  61. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Color 1\t{%06x}ID %i\n", rgb, colorid);
  62. strcat(g_DialogInfo, g_DialogInfoRow);
  63. }
  64. }
  65. case LISTITEM_VEHICLE_COLOR2: {
  66. new colorid = g_VehicleData[vehicleid-1][VEHICLE_DATA_COLOR_2];
  67. if( colorid == INVALID_COLOR_ID ) {
  68. strcat(g_DialogInfo, "Color 2\tUnknown\n");
  69. } else {
  70. new rgb = GetVehicleColorRGB(colorid);
  71. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Color 2\t{%06x}ID %i\n", rgb, colorid);
  72. strcat(g_DialogInfo, g_DialogInfoRow);
  73. }
  74. }
  75. case LISTITEM_VEHICLE_MODSHOP: {
  76. new modshopid = GetVehicleModelModShop(GetVehicleModel(vehicleid));
  77. if( modshopid == INVALID_MODSHOP_ID ) {
  78. strcat(g_DialogInfo, " \t \n");
  79. } else {
  80. GetModShopName(modshopid, g_ModShopString, sizeof g_ModShopString);
  81. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "Teleport to Modshop\t%s\n", g_ModShopString);
  82. strcat(g_DialogInfo, g_DialogInfoRow);
  83. }
  84. }
  85. case LISTITEM_VEHICLE_REMOVEMODS: {
  86. strcat(g_DialogInfo, "Remove Modifications\t \n");
  87. }
  88. default: {
  89. strcat(g_DialogInfo, " \t \n");
  90. }
  91. }
  92. }
  93. ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_TABLIST, "Vehicle", g_DialogInfo, "Select", "Cancel");
  94. }
  95. case DIALOGID_VEHICLE_COORD: {
  96. new vehicleid = GetPlayerEditVehicle(playerid);
  97. if( !IsValidVehicle(vehicleid) ) {
  98. return 1;
  99. }
  100. new Float:x, Float:y, Float:z, Float:a;
  101. GetVehiclePos(vehicleid, x, y, z);
  102. GetVehicleZAngle(vehicleid, a);
  103. g_DialogInfo = "";
  104. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "x\t%f\n", x), strcat(g_DialogInfo, g_DialogInfoRow);
  105. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "y\t%f\n", y), strcat(g_DialogInfo, g_DialogInfoRow);
  106. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "z\t%f\n", z), strcat(g_DialogInfo, g_DialogInfoRow);
  107. format(g_DialogInfoRow, sizeof g_DialogInfoRow, "a\t%f\n", a), strcat(g_DialogInfo, g_DialogInfoRow);
  108. ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Vehicle Coordinates", g_DialogInfo, "Enter", "Cancel");
  109. }
  110. case DIALOGID_VEHICLE_COMMENT: {
  111. new vehicleid = GetPlayerEditVehicle(playerid);
  112. if( !IsValidVehicle(vehicleid) ) {
  113. return 1;
  114. }
  115. strunpack(g_CommentString, g_VehicleData[vehicleid-1][VEHICLE_DATA_COMMENT], MAX_COMMENT_LEN+1); // Get Comment
  116. format(g_DialogInfo, sizeof g_DialogInfo, "Current Comment: %s", g_CommentString);
  117. ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Vehicle Comment", g_DialogInfo, "Enter", "Cancel");
  118. }
  119. default: {
  120. return 0;
  121. }
  122. }
  123. return 1;
  124. }
  125. CopyVehicle(copy_vehicleid, Float:a) {
  126. if( !IsValidVehicle(copy_vehicleid) ) {
  127. return INVALID_VEHICLE_ID;
  128. }
  129. new Float:x, Float:y, Float:z, paste_vehicleid;
  130. GetVehiclePos(copy_vehicleid, x, y, z);
  131. paste_vehicleid = CreateVehicle(GetVehicleModel(copy_vehicleid), x, y, z, a, g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_COLOR_1], g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_COLOR_2], -1);
  132. if( paste_vehicleid == INVALID_VEHICLE_ID ) {
  133. return INVALID_VEHICLE_ID;
  134. }
  135. for(new slot; slot < MAX_COMPONENT_SLOTS; slot ++) {
  136. new componentid = GetVehicleComponentInSlot(copy_vehicleid, slot);
  137. if(componentid != 0) {
  138. AddVehicleComponent(paste_vehicleid, componentid);
  139. }
  140. }
  141. strunpack(g_CommentString, g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_COMMENT], MAX_COMMENT_LEN+1); // Get Vehicle Comment
  142. strpack(g_VehicleData[paste_vehicleid-1][VEHICLE_DATA_COMMENT], g_CommentString, MAX_COMMENT_LEN+1); // Set Vehicle Comment
  143. g_VehicleData[paste_vehicleid-1][VEHICLE_DATA_MEMORY_X ] = g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_MEMORY_X ];
  144. g_VehicleData[paste_vehicleid-1][VEHICLE_DATA_MEMORY_Y ] = g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_MEMORY_Y ];
  145. g_VehicleData[paste_vehicleid-1][VEHICLE_DATA_MEMORY_Z ] = g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_MEMORY_Z ];
  146. g_VehicleData[paste_vehicleid-1][VEHICLE_DATA_MEMORY_RZ] = g_VehicleData[copy_vehicleid-1][VEHICLE_DATA_MEMORY_RZ];
  147. return paste_vehicleid;
  148. }
  149. RecreateVehicle(copy_vehicleid, Float:a) {
  150. new paste_vehicleid = CopyVehicle(copy_vehicleid, a);
  151. if( paste_vehicleid != INVALID_VEHICLE_ID ) {
  152. TransferVehicleAttachments(copy_vehicleid, paste_vehicleid);
  153. for(new playerid, max_playerid = GetPlayerPoolSize(); playerid <= max_playerid; playerid ++) {
  154. if( !IsPlayerConnected(playerid) ) {
  155. continue;
  156. }
  157. if( GetPlayerEditVehicle(playerid) == copy_vehicleid ) {
  158. g_PlayerData[playerid][PLAYER_DATA_EDIT_ID] = paste_vehicleid;
  159. }
  160. for(new row; row < MAX_SELECTLIST_ROWS; row ++) {
  161. if( copy_vehicleid != g_SelectVehListData[playerid][SELECTLIST_DATA_ROW_ID][row] ) {
  162. continue;
  163. }
  164. g_SelectVehListData[playerid][SELECTLIST_DATA_ROW_ID][row] = paste_vehicleid;
  165. if( g_PlayerData[playerid][PLAYER_DATA_TDMODE] == TDMODE_SELECTLIST_VEHICLE ) {
  166. ApplySelectListRowData(playerid, row);
  167. }
  168. }
  169. }
  170. DestroyVehicle(copy_vehicleid);
  171. }
  172. return paste_vehicleid;
  173. }
  174. CopyVehicleAttachments(from_vehicleid, to_vehicleid) {
  175. if( !IsValidVehicle(from_vehicleid) || !IsValidVehicle(to_vehicleid) ) {
  176. return 0;
  177. }
  178. for(new loop_objectid = 1; loop_objectid <= MAX_OBJECTS; loop_objectid ++) {
  179. if( !IsValidObject(loop_objectid) ) {
  180. continue;
  181. }
  182. if( GetObjectAttachVehicle(loop_objectid) != from_vehicleid ) {
  183. continue;
  184. }
  185. new paste_objectid = CopyObject(loop_objectid, .copy_attachto = false);
  186. if( paste_objectid == INVALID_OBJECT_ID ) {
  187. return 0;
  188. }
  189. if( MigrateObjectAttachData(.from_objectid = loop_objectid, .to_objectid = paste_objectid, .attachtoid = to_vehicleid) ) {
  190. ApplyObjectAttachData(paste_objectid);
  191. }
  192. }
  193. return 1;
  194. }
  195. TransferVehicleAttachments(from_vehicleid, to_vehicleid) {
  196. if( !IsValidVehicle(from_vehicleid) || !IsValidVehicle(to_vehicleid) ) {
  197. return 0;
  198. }
  199. for(new loop_objectid = 1; loop_objectid <= MAX_OBJECTS; loop_objectid ++) {
  200. if( !IsValidObject(loop_objectid) ) {
  201. continue;
  202. }
  203. if( GetObjectAttachVehicle(loop_objectid) != from_vehicleid ) {
  204. continue;
  205. }
  206. g_ObjectData[loop_objectid-1][OBJECT_DATA_ATTACH_ID] = to_vehicleid;
  207. ApplyObjectAttachData(loop_objectid);
  208. }
  209. return 1;
  210. }
  211. IsVehicleOccupied(vehicleid, seat) {
  212. for(new playerid, max_playerid = GetPlayerPoolSize(); playerid <= max_playerid; playerid ++) {
  213. if(IsPlayerConnected(playerid) && GetPlayerVehicleID(playerid) == vehicleid && GetPlayerVehicleSeat(playerid) == seat) {
  214. return 1;
  215. }
  216. }
  217. return 0;
  218. }
  219. FindVehicles(result[], result_size, search[], offset, &max_offset) {
  220. new
  221. rows_found,
  222. rows_added,
  223. search_int = -1,
  224. packed_search[MAX_SEARCH_LEN+1 char]
  225. ;
  226. sscanf(search, "i", search_int);
  227. strpack(packed_search, search);
  228. for(new vehicleid = 1, max_vehicleid = GetVehiclePoolSize(), modelid, cache_idx; vehicleid <= max_vehicleid; vehicleid ++) {
  229. if( !IsValidVehicle(vehicleid) ) {
  230. continue;
  231. }
  232. modelid = GetVehicleModel(vehicleid);
  233. cache_idx = GetVehicleModelCacheIndex(modelid);
  234. if(
  235. isempty(search) ||
  236. search_int == vehicleid ||
  237. search_int == modelid ||
  238. strfind(g_VehicleData[vehicleid-1][VEHICLE_DATA_COMMENT], packed_search, true) != -1 ||
  239. ( cache_idx != INVALID_ARRAY_INDEX && strfind(g_VehModelNameCache[cache_idx], packed_search, true) != -1 )
  240. ){
  241. if( rows_found ++ < offset ) {
  242. continue;
  243. }
  244. if( rows_added < result_size ) {
  245. result[rows_added ++] = vehicleid;
  246. }
  247. }
  248. }
  249. max_offset = rows_found - 1;
  250. if( max_offset < 0 ) {
  251. max_offset = 0;
  252. }
  253. return rows_added;
  254. }