mapedit.pwn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #include <a_samp>
  2. #include <sscanf2>
  3. #include <strlib> // Slice's strlib (NOT WESTIE'S!)
  4. native IsValidVehicle(vehicleid);
  5. #pragma dynamic 19100 // To avoid warnings at compiling
  6. //------------------------------------------------------------------------------
  7. // Defined Values & Enumerators
  8. #define MAX_SEARCH_LEN 20
  9. #define MAX_COMMENT_LEN 20
  10. #define INVALID_TIMER_ID 0
  11. #define INVALID_MODEL_ID -1
  12. #define INVALID_COLOR_ID -1
  13. #define INVALID_ROW -1
  14. #define INVALID_MAP_ID 0
  15. #define INVALID_ARRAY_INDEX -1
  16. #define SELECT_TD_COLOR 0xFF0000FF
  17. #define RGBA_WHITE 0xFFFFFFFF
  18. #define RGBA_GREEN 0x00FF00FF
  19. #define RGBA_RED 0xFF0000FF
  20. #define RGBA_YELLOW 0xFFFF00FF
  21. #define RGBA_ORANGE 0xFFA500FF
  22. //#define MONEYREFILL_TOGGLED // Automatic money refill; useful for money in modshops (comment / remove this line to disable it)
  23. #include "mapedit/pattach/value.pwn"
  24. #include "mapedit/cammode/value.pwn"
  25. #include "mapedit/idtype/value.pwn"
  26. #include "mapedit/matindextype/value.pwn"
  27. #include "mapedit/mapnew/value.pwn"
  28. #include "mapedit/mapsave/value.pwn"
  29. #include "mapedit/object/value.pwn"
  30. #include "mapedit/offsetedit/value.pwn"
  31. #include "mapedit/pickup/value.pwn"
  32. #include "mapedit/vehicle/value.pwn"
  33. #include "mapedit/dialog/value.pwn"
  34. #include "mapedit/matalign/value.pwn"
  35. #include "mapedit/anim/value.pwn"
  36. #include "mapedit/modshop/value.pwn"
  37. #include "mapedit/bone/value.pwn"
  38. #include "mapedit/texture/value.pwn"
  39. #include "mapedit/font/value.pwn"
  40. #include "mapedit/model/value.pwn"
  41. #include "mapedit/skin/value.pwn"
  42. #include "mapedit/matsize/value.pwn"
  43. #include "mapedit/vehmodel/value.pwn"
  44. #include "mapedit/vehcolor/value.pwn"
  45. #include "mapedit/editmarker/value.pwn"
  46. #include "mapedit/modelcolor/value.pwn"
  47. #include "mapedit/tdmode/value.pwn"
  48. #include "mapedit/createlist/value.pwn"
  49. #include "mapedit/catselect/value.pwn"
  50. #include "mapedit/category/value.pwn"
  51. #include "mapedit/selectlist/value.pwn"
  52. #include "mapedit/colorlist/value.pwn"
  53. #include "mapedit/texturelist/value.pwn"
  54. #include "mapedit/fontlist/value.pwn"
  55. #include "mapedit/help/value.pwn"
  56. #include "mapedit/animlist/value.pwn"
  57. #include "mapedit/modelview/value.pwn"
  58. #include "mapedit/catmanager/value.pwn"
  59. #include "mapedit/textureview/value.pwn"
  60. #include "mapedit/maplist/value.pwn"
  61. #include "mapedit/moneyrefill/value.pwn"
  62. #include "mapedit/building/value.pwn"
  63. #include "mapedit/buildlist/value.pwn"
  64. //------------------------------------------------------------------------------
  65. // Variables
  66. new
  67. DB: g_ResourceDB,
  68. DB: g_MapDB,
  69. DBResult: g_DBResult
  70. ;
  71. #include "mapedit/actor/var.pwn"
  72. #include "mapedit/object/var.pwn"
  73. #include "mapedit/pickup/var.pwn"
  74. #include "mapedit/player/var.pwn"
  75. #include "mapedit/vehicle/var.pwn"
  76. #include "mapedit/matsize/var.pwn"
  77. #include "mapedit/strvar/var.pwn"
  78. #include "mapedit/toolbar/var.pwn"
  79. #include "mapedit/model/var.pwn"
  80. #include "mapedit/texture/var.pwn"
  81. #include "mapedit/vehmodel/var.pwn"
  82. #include "mapedit/font/var.pwn"
  83. #include "mapedit/skin/var.pwn"
  84. #include "mapedit/vehcolor/var.pwn"
  85. #include "mapedit/modelcolor/var.pwn"
  86. #include "mapedit/createlist/var.pwn"
  87. #include "mapedit/catselect/var.pwn"
  88. #include "mapedit/selectlist/var.pwn"
  89. #include "mapedit/colorlist/var.pwn"
  90. #include "mapedit/texturelist/var.pwn"
  91. #include "mapedit/fontlist/var.pwn"
  92. #include "mapedit/help/var.pwn"
  93. #include "mapedit/animlist/var.pwn"
  94. #include "mapedit/modelview/var.pwn"
  95. #include "mapedit/catmanager/var.pwn"
  96. #include "mapedit/textureview/var.pwn"
  97. #include "mapedit/cammode/var.pwn"
  98. #include "mapedit/offsetedit/var.pwn"
  99. #include "mapedit/editmarker/var.pwn"
  100. #include "mapedit/pattach/var.pwn"
  101. #include "mapedit/maplist/var.pwn"
  102. #include "mapedit/maploaded/var.pwn"
  103. #include "mapedit/building/var.pwn"
  104. #include "mapedit/buildlist/var.pwn"
  105. //------------------------------------------------------------------------------
  106. // Macros
  107. #define HOLDING(%0) ( newkeys & %0 )
  108. #define PRESSED(%0) ( (newkeys & %0) && !(oldkeys & %0) )
  109. #define RELEASED(%0) ( !(newkeys & %0) && (oldkeys & %0) )
  110. #include "mapedit/pattach/macro.pwn"
  111. #include "mapedit/dialog/macro.pwn"
  112. #include "mapedit/object/macro.pwn"
  113. #include "mapedit/pickup/macro.pwn"
  114. #include "mapedit/bone/macro.pwn"
  115. #include "mapedit/texture/macro.pwn"
  116. #include "mapedit/vehmodel/macro.pwn"
  117. #include "mapedit/font/macro.pwn"
  118. #include "mapedit/skin/macro.pwn"
  119. #include "mapedit/vehcolor/macro.pwn"
  120. #include "mapedit/modelcolor/macro.pwn"
  121. #include "mapedit/matalign/macro.pwn"
  122. #include "mapedit/building/macro.pwn"
  123. //------------------------------------------------------------------------------
  124. // Hooked Functions
  125. #include "mapedit/object/hook.pwn"
  126. #include "mapedit/vehicle/hook.pwn"
  127. #include "mapedit/actor/hook.pwn"
  128. #include "mapedit/pickup/hook.pwn"
  129. #include "mapedit/selecttd/hook.pwn"
  130. //------------------------------------------------------------------------------
  131. // Additional Functions
  132. GetMapFilePath(mapname[], path[], path_size) {
  133. format(path, path_size, "maps/%s.map", mapname);
  134. }
  135. #include "mapedit/floatfunc/func.pwn"
  136. #include "mapedit/colorfunc/func.pwn"
  137. #include "mapedit/matalign/func.pwn"
  138. #include "mapedit/anim/func.pwn"
  139. #include "mapedit/modshop/func.pwn"
  140. #include "mapedit/bone/func.pwn"
  141. #include "mapedit/texture/func.pwn"
  142. #include "mapedit/font/func.pwn"
  143. #include "mapedit/model/func.pwn"
  144. #include "mapedit/skin/func.pwn"
  145. #include "mapedit/matsize/func.pwn"
  146. #include "mapedit/vehmodel/func.pwn"
  147. #include "mapedit/vehcolor/func.pwn"
  148. #include "mapedit/actor/func.pwn"
  149. #include "mapedit/pattach/func.pwn"
  150. #include "mapedit/cammode/func.pwn"
  151. #include "mapedit/mapnew/func.pwn"
  152. #include "mapedit/mapload/func.pwn"
  153. #include "mapedit/object/func.pwn"
  154. #include "mapedit/offsetedit/func.pwn"
  155. #include "mapedit/pickup/func.pwn"
  156. #include "mapedit/player/func.pwn"
  157. #include "mapedit/mapsave/func.pwn"
  158. #include "mapedit/vehicle/func.pwn"
  159. #include "mapedit/toolbar/func.pwn"
  160. #include "mapedit/editmarker/func.pwn"
  161. #include "mapedit/modelcolor/func.pwn"
  162. #include "mapedit/tdmode/func.pwn"
  163. #include "mapedit/clickdragobj/func.pwn"
  164. #include "mapedit/createlist/func.pwn"
  165. #include "mapedit/catselect/func.pwn"
  166. #include "mapedit/category/func.pwn"
  167. #include "mapedit/selectlist/func.pwn"
  168. #include "mapedit/colorlist/func.pwn"
  169. #include "mapedit/texturelist/func.pwn"
  170. #include "mapedit/fontlist/func.pwn"
  171. #include "mapedit/help/func.pwn"
  172. #include "mapedit/animlist/func.pwn"
  173. #include "mapedit/modelview/func.pwn"
  174. #include "mapedit/catmanager/func.pwn"
  175. #include "mapedit/textureview/func.pwn"
  176. #include "mapedit/maplist/func.pwn"
  177. #include "mapedit/maploaded/func.pwn"
  178. #include "mapedit/mapdb/func.pwn"
  179. #include "mapedit/building/func.pwn"
  180. #include "mapedit/buildlist/func.pwn"
  181. //------------------------------------------------------------------------------
  182. // Callbacks
  183. public OnFilterScriptInit() {
  184. g_ResourceDB = db_open("mapedit.db");
  185. if( !g_ResourceDB ) {
  186. print("ERROR: mapedit.db failed to open!");
  187. }
  188. g_MapDB = db_open("mapedit_maps.db");
  189. if( !g_MapDB ) {
  190. print("ERROR: mapedit_maps.db failed to open!");
  191. }
  192. if( !fexist("maps/") ) {
  193. printf("ERROR: The file path .../scriptfiles/maps does not exist!");
  194. }
  195. LoadModelCache();
  196. LoadVehicleModelCache();
  197. LoadTextureCache();
  198. LoadFontCache();
  199. LoadSkinCache();
  200. LoadVehicleColorCache();
  201. LoadModelColorCache();
  202. for(new playerid, max_playerid = GetPlayerPoolSize(); playerid <= max_playerid; playerid ++) {
  203. if( IsPlayerConnected(playerid) ) {
  204. DefaultPlayerData(playerid);
  205. EnablePlayerCameraTarget(playerid, true); // to enable look-selecting vehicles, objects, actors
  206. }
  207. }
  208. #if defined core_OnFilterScriptInit
  209. core_OnFilterScriptInit();
  210. #endif
  211. }
  212. #if defined _ALS_OnFilterScriptInit
  213. #undef OnFilterScriptInit
  214. #else
  215. #define _ALS_OnFilterScriptInit
  216. #endif
  217. #define OnFilterScriptInit core_OnFilterScriptInit
  218. #if defined core_OnFilterScriptInit
  219. forward core_OnFilterScriptInit();
  220. #endif
  221. public OnFilterScriptExit() {
  222. if( g_ResourceDB ) {
  223. db_close(g_ResourceDB);
  224. }
  225. #if defined core_OnFilterScriptExit
  226. core_OnFilterScriptExit();
  227. #endif
  228. }
  229. #if defined _ALS_OnFilterScriptExit
  230. #undef OnFilterScriptExit
  231. #else
  232. #define _ALS_OnFilterScriptExit
  233. #endif
  234. #define OnFilterScriptExit core_OnFilterScriptExit
  235. #if defined core_OnFilterScriptExit
  236. forward core_OnFilterScriptExit();
  237. #endif
  238. public OnPlayerConnect(playerid) {
  239. DefaultPlayerData(playerid);
  240. EnablePlayerCameraTarget(playerid, true); // to enable look-selecting vehicles, objects, actors
  241. #if defined core_OnPlayerConnect
  242. return core_OnPlayerConnect(playerid);
  243. #else
  244. return 1;
  245. #endif
  246. }
  247. #if defined _ALS_OnPlayerConnect
  248. #undef OnPlayerConnect
  249. #else
  250. #define _ALS_OnPlayerConnect
  251. #endif
  252. #define OnPlayerConnect core_OnPlayerConnect
  253. #if defined core_OnPlayerConnect
  254. forward core_OnPlayerConnect(playerid);
  255. #endif
  256. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  257. if( PRESSED(KEY_YES) || (PRESSED(KEY_CROUCH) && GetPlayerState(playerid) == PLAYER_STATE_SPECTATING) ) {
  258. SelectTextDraw(playerid, SELECT_TD_COLOR); // toggle mouse mode
  259. }
  260. #if defined core_OnPlayerKeyStateChange
  261. core_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  262. #endif
  263. }
  264. #if defined _ALS_OnPlayerKeyStateChange
  265. #undef OnPlayerKeyStateChange
  266. #else
  267. #define _ALS_OnPlayerKeyStateChange
  268. #endif
  269. #define OnPlayerKeyStateChange core_OnPlayerKeyStateChange
  270. #if defined core_OnPlayerKeyStateChange
  271. forward core_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  272. #endif
  273. public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ) {
  274. if( g_CamModeData[playerid][CAMMODE_DATA_TOGGLE] ) {
  275. StopPlayerObject(playerid, g_CamModeData[playerid][CAMMODE_DATA_POID]);
  276. SetPlayerObjectPos(playerid, g_CamModeData[playerid][CAMMODE_DATA_POID], fX, fY, fZ);
  277. } else {
  278. SetPlayerPosFindZ(playerid, fX, fY, fZ);
  279. }
  280. #if defined core_OnPlayerClickMap
  281. core_OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ);
  282. #else
  283. return 0;
  284. #endif
  285. }
  286. #if defined _ALS_OnPlayerClickMap
  287. #undef OnPlayerClickMap
  288. #else
  289. #define _ALS_OnPlayerClickMap
  290. #endif
  291. #define OnPlayerClickMap core_OnPlayerClickMap
  292. #if defined core_OnPlayerClickMap
  293. forward core_OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ);
  294. #endif
  295. #include "mapedit/vehicle/call.pwn"
  296. #include "mapedit/object/call.pwn"
  297. #include "mapedit/pickup/call.pwn"
  298. #include "mapedit/actor/call.pwn"
  299. #include "mapedit/pattach/call.pwn"
  300. #include "mapedit/selectlist/call.pwn"
  301. #include "mapedit/createlist/call.pwn"
  302. #include "mapedit/toolbar/call.pwn"
  303. #include "mapedit/editmarker/call.pwn"
  304. #include "mapedit/offsetedit/call.pwn"
  305. #include "mapedit/cammode/call.pwn"
  306. #include "mapedit/clickdragobj/call.pwn"
  307. #include "mapedit/tdmode/call.pwn"
  308. #include "mapedit/catselect/call.pwn"
  309. #include "mapedit/colorlist/call.pwn"
  310. #include "mapedit/texturelist/call.pwn"
  311. #include "mapedit/fontlist/call.pwn"
  312. #include "mapedit/help/call.pwn"
  313. #include "mapedit/animlist/call.pwn"
  314. #include "mapedit/modelview/call.pwn"
  315. #include "mapedit/catmanager/call.pwn"
  316. #include "mapedit/selecttd/call.pwn"
  317. #include "mapedit/mapnew/call.pwn"
  318. #include "mapedit/mapload/call.pwn"
  319. #include "mapedit/mapsave/call.pwn"
  320. #include "mapedit/textureview/call.pwn"
  321. #include "mapedit/maplist/call.pwn"
  322. #include "mapedit/maploaded/call.pwn"
  323. #include "mapedit/moneyrefill/call.pwn"
  324. #include "mapedit/building/call.pwn"
  325. #include "mapedit/buildlist/call.pwn"
  326. #include "mapedit/printsuccess/call.pwn" // has to be at the end of callback list, prints a message if called
  327. main() {
  328. }