Advertisement
GammixSAMP

gangzones.inc - Compact version - By Gammix

May 10th, 2015
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. /*
  2. Interactive Gangzones (gangzones.inc)
  3. * Add boders to your gangzones and fully customizable gangzones. New dynamic functions for gangzones.
  4.  
  5. Author: (creator)
  6. * Gammix
  7.  
  8. Contributors:
  9. * Incognito - Streamer plugin, used dynamic areas
  10.  
  11. (c) Copyright 2015
  12. * This file is provided as is (no warranties).
  13. */
  14. /*
  15. FUNCTIONS:
  16. native GangZoneCreate(Float:minx, Float:miny, Float:maxx, Float:maxy, color = -1, Float:bordersize = 1.0, brodercolor = 0x00000060);
  17. native GangZoneDestroy(zone);
  18. native GangZoneExist(zone);
  19. native GangZoneShowForPlayer(playerid, zone, color = -1, bordercolor = -1);
  20. native GangZoneShowForAll(zone, color = -1, bordercolor = -1);
  21. native GangZoneHideForPlayer(playerid, zone);
  22. native GangZoneHideForAll(zone);
  23. native GangZoneFlashForPlayer(playerid, zone, flashcolor);
  24. native GangZoneFlashForAll(zone, flashcolor);
  25. native GangZoneStopFlashForPlayer(playerid, zone);
  26. native GangZoneStopFlashForAll(zone);
  27. native CountAllGangZones();
  28. native IsPlayerInGangZone(playerid, zone);
  29. native IsPlayerInAnyGangZone(playerid);
  30. native GetPlayerGangZone(playerid);
  31.  
  32. CALLBACKS:
  33. public OnPlayerEnterGangZone(playerid, zone);
  34. public OnPlayerLeaveGangZone(playerid, zone);
  35. */
  36.  
  37. #include <streamer>
  38.  
  39. #define MAX_ZONES 1024//maximum gangzones your server can have, the limit is upto 1024 and minimum 5
  40. //Note: Creating one interactive gangzone makes total 5 zones, 4 for borders and 1 for the main zone!
  41.  
  42. enum GangzoneInfo
  43. {
  44. bool:E_exist,
  45. E_border[4],
  46. Float:E_minx,
  47. Float:E_miny,
  48. Float:E_maxx,
  49. Float:E_maxy,
  50. E_dynamic,
  51. E_color,
  52. E_bordercolor
  53. }
  54. static gGangzone[MAX_ZONES][GangzoneInfo];
  55.  
  56. //Note: if you use this in a filterscript, please define "FILTERSCRIPT" in your script
  57. #if defined FILTERSCRIPT// if used in a filterscript
  58.  
  59. public OnFilterScriptExit()
  60. {
  61. DestroyAllGangZones();//destory all gangzones
  62.  
  63. return CallLocalFunction("GZ_OnFilterScriptExit", " ");
  64. }
  65. #if defined _ALS_OnFilterScriptExit
  66. #undef OnFilterScriptExit
  67. #else
  68. #define _ALS_OnFilterScriptExit
  69. #endif
  70. #define OnFilterScriptExit GZ_OnFilterScriptExit
  71. forward GZ_OnFilterScriptExit();
  72.  
  73. #else// if used in a gamemode
  74.  
  75. public OnGameModeExit()
  76. {
  77. DestroyAllGangZones();//destory all gangzones
  78.  
  79. return CallLocalFunction("GZ_OnGameModeExit", " ");
  80. }
  81. #if defined _ALS_OnGameModeExit
  82. #undef OnGameModeExit
  83. #else
  84. #define _ALS_OnGameModeExit
  85. #endif
  86. #define OnGameModeExit GZ_OnGameModeExit
  87. forward GZ_OnGameModeExit();
  88.  
  89. #endif
  90.  
  91. stock GangZoneCreate_(Float:minx, Float:miny, Float:maxx, Float:maxy, color = -1, Float:bordersize = 1.0, brodercolor = 0x00000060)
  92. {
  93. new E_zone = GangZoneCreate(minx, miny, maxx, maxy);//the main zone
  94.  
  95. gGangzone[E_zone][E_minx] = minx;
  96. gGangzone[E_zone][E_miny] = miny;
  97. gGangzone[E_zone][E_maxx] = maxx;
  98. gGangzone[E_zone][E_maxy] = maxy;
  99.  
  100. gGangzone[E_zone][E_color] = color;
  101. gGangzone[E_zone][E_bordercolor] = brodercolor;
  102.  
  103. #define SEPERATION (2.0 * bordersize)//the seperation value to differenciate borders from gangzone, set accordingly! (Default: 2.0)
  104. gGangzone[E_zone][E_border][0] = GangZoneCreate(minx - SEPERATION, miny, minx + SEPERATION, maxy);//border 1
  105. gGangzone[E_zone][E_border][1] = GangZoneCreate(minx - SEPERATION, maxy - SEPERATION, maxx, maxy + SEPERATION);//border 2
  106. gGangzone[E_zone][E_border][2] = GangZoneCreate(maxx - SEPERATION, miny, maxx + SEPERATION, maxy);//border 3
  107. gGangzone[E_zone][E_border][3] = GangZoneCreate(minx - SEPERATION, miny - SEPERATION, maxx, miny + SEPERATION);//border 4
  108.  
  109. gGangzone[E_zone][E_dynamic] = CreateDynamicRectangle(minx, miny, maxx, maxy);//creating the dynamic zone
  110.  
  111. gGangzone[E_zone][E_exist] = true;//finally, zone exists!
  112. return E_zone;
  113. }
  114. #if defined _ALS_GangZoneCreate
  115. #undef GangZoneCreate
  116. #else
  117. #define _ALS_GangZoneCreate
  118. #endif
  119. #define GangZoneCreate GangZoneCreate_
  120.  
  121. stock GangZoneDestroy_(zone)
  122. {
  123. if(! gGangzone[zone][E_exist]) return false;//check if exists
  124.  
  125. gGangzone[zone][E_minx] = 0.0;
  126. gGangzone[zone][E_miny] = 0.0;
  127. gGangzone[zone][E_maxx] = 0.0;
  128. gGangzone[zone][E_maxy] = 0.0;
  129.  
  130. GangZoneDestroy(zone);//destroy main zone
  131.  
  132. for(new border = 0; border < 4; border++)//destroy all 4 borders
  133. {
  134. GangZoneDestroy(gGangzone[zone][E_border][border]);
  135. }
  136.  
  137. DestroyDynamicArea(gGangzone[zone][E_dynamic]);//destory dynamic area
  138. gGangzone[zone][E_dynamic] = -1;
  139.  
  140. gGangzone[zone][E_exist] = false;//finally, zone doesn't exists
  141. return true;
  142. }
  143. #if defined _ALS_GangZoneDestroy
  144. #undef GangZoneDestroy
  145. #else
  146. #define _ALS_GangZoneDestroy
  147. #endif
  148. #define GangZoneDestroy GangZoneDestroy_
  149.  
  150. stock GangZoneExist(zone)
  151. {
  152. if(zone < 0 || zone >= MAX_ZONES)
  153. {
  154. printf("Error::GangZoneExist()::Out Of Bounds::%i", zone);//by pottus
  155. return false;//if invalid zone id
  156. }
  157.  
  158. return gGangzone[zone][E_exist];//check if zone exists!
  159. }
  160.  
  161. stock GangZoneShowForPlayer_(playerid, zone, color = -1, bordercolor = -1)
  162. {
  163. /*
  164. NOTE: if color is "-1" and if bordercolor is "-1", then the system will set
  165. the zone color automatically to default(the one set on creating the zone)!
  166. */
  167.  
  168. if(! GangZoneExist(zone)) return false;
  169.  
  170. if(color == -1) color = gGangzone[zone][E_color];
  171. else gGangzone[zone][E_color] = color;
  172. if(bordercolor == -1) bordercolor = gGangzone[zone][E_bordercolor];
  173. else gGangzone[zone][E_bordercolor] = bordercolor;
  174.  
  175. GangZoneShowForPlayer(playerid, zone, color);
  176. for(new border = 0; border < 4; border++) GangZoneShowForPlayer(playerid, gGangzone[zone][E_border][border], bordercolor);
  177.  
  178. return true;
  179. }
  180. #if defined _ALS_GangZoneShowForPlayer
  181. #undef GangZoneShowForPlayer
  182. #else
  183. #define _ALS_GangZoneShowForPlayer
  184. #endif
  185. #define GangZoneShowForPlayer GangZoneShowForPlayer_
  186.  
  187. stock GangZoneShowForAll_(zone, color = -1, bordercolor = -1)
  188. {
  189. if(! GangZoneExist(zone)) return false;
  190.  
  191. if(color == -1) color = gGangzone[zone][E_color];
  192. else gGangzone[zone][E_color] = color;
  193. if(bordercolor == -1) bordercolor = gGangzone[zone][E_bordercolor];
  194. else gGangzone[zone][E_bordercolor] = bordercolor;
  195.  
  196. GangZoneShowForAll(zone, color);
  197. for(new border = 0; border < 4; border++) GangZoneShowForAll(gGangzone[zone][E_border][border], bordercolor);
  198.  
  199. return true;
  200. }
  201. #if defined _ALS_GangZoneShowForAll
  202. #undef GangZoneShowForAll
  203. #else
  204. #define _ALS_GangZoneShowForAll
  205. #endif
  206. #define GangZoneShowForAll GangZoneShowForAll_
  207.  
  208. stock GangZoneHideForPlayer_(playerid, zone)
  209. {
  210. if(! GangZoneExist(zone)) return false;
  211.  
  212. GangZoneHideForPlayer(playerid, zone);
  213. for(new border = 0; border < 4; border++) GangZoneHideForPlayer(playerid, gGangzone[zone][E_border][border]);
  214.  
  215. return true;
  216. }
  217. #if defined _ALS_GangZoneHideForPlayer
  218. #undef GangZoneHideForPlayer
  219. #else
  220. #define _ALS_GangZoneHideForPlayer
  221. #endif
  222. #define GangZoneHideForPlayer GangZoneHideForPlayer_
  223.  
  224. stock GangZoneHideForAll_(zone)
  225. {
  226. if(! GangZoneExist(zone)) return false;
  227.  
  228. GangZoneHideForAll(zone);
  229. for(new border = 0; border < 4; border++) GangZoneHideForAll(gGangzone[zone][E_border][border]);
  230.  
  231. return true;
  232. }
  233. #if defined _ALS_GangZoneHideForAll
  234. #undef GangZoneHideForAll
  235. #else
  236. #define _ALS_GangZoneHideForAll
  237. #endif
  238. #define GangZoneHideForAll GangZoneHideForAll_
  239.  
  240. //the flashing functions are same as that of samp!
  241. // GangZoneFlashForPlayer(playerid, zone, flashcolor);
  242.  
  243. // GangZoneFlashForAll(zone, flashcolor);
  244.  
  245. // GangZoneStopFlashForPlayer(playerid, zone);
  246.  
  247. // GangZoneStopFlashForAll(zone);
  248.  
  249. stock CountAllGangZones()
  250. {
  251. new count = 0;
  252. for(new zone = 0; zone < MAX_ZONES; zone++)
  253. {
  254. if(GangZoneExist(zone))
  255. {
  256. count ++;
  257. }
  258. }
  259. return count;
  260. }
  261.  
  262. stock DestroyAllGangZones()
  263. {
  264. for(new zone = 0; zone < MAX_ZONES; zone++)
  265. {
  266. if(GangZoneExist(zone))
  267. {
  268. GangZoneDestroy(zone);
  269. }
  270. }
  271. return true;
  272. }
  273.  
  274. stock ShowAllGangZonesForPlayer(playerid, color = -1, bordercolor = -1)
  275. {
  276. for(new zone = 0; zone < MAX_ZONES; zone++)
  277. {
  278. if(GangZoneExist(zone))
  279. {
  280. GangZoneShowForPlayer(playerid, zone, color, bordercolor);
  281. }
  282. }
  283. return true;
  284. }
  285.  
  286. stock ShowAllGangZonesForAll(color = -1, bordercolor = -1)
  287. {
  288. for(new zone = 0; zone < MAX_ZONES; zone++)
  289. {
  290. if(GangZoneExist(zone))
  291. {
  292. GangZoneShowForAll(zone color, bordercolor);
  293. }
  294. }
  295. return true;
  296. }
  297.  
  298. stock HideAllGangZonesForPlayer(playerid)
  299. {
  300. for(new zone = 0; zone < MAX_ZONES; zone++)
  301. {
  302. if(GangZoneExist(zone))
  303. {
  304. GangZoneHideForPlayer(playerid, zone);
  305. }
  306. }
  307. return true;
  308. }
  309.  
  310. stock HideAllGangZonesForAll()
  311. {
  312. for(new zone = 0; zone < MAX_ZONES; zone++)
  313. {
  314. if(GangZoneExist(zone))
  315. {
  316. GangZoneHideForAll(zone);
  317. }
  318. }
  319. return true;
  320. }
  321.  
  322. stock IsPlayerInGangZone(playerid, zone)
  323. {
  324. if(! GangZoneExist(zone)) return false;
  325.  
  326. if(IsPlayerInDynamicArea(playerid, gGangzone[zone][E_dynamic])) return true;
  327. return false;
  328. }
  329.  
  330. stock IsPlayerInAnyGangZone(playerid)
  331. {
  332. if(! IsPlayerConnected(playerid)) return false;
  333.  
  334. if(IsPlayerInAnyDynamicArea(playerid)) return true;
  335. return false;
  336. }
  337.  
  338. stock GetPlayerGangZone(playerid)
  339. {
  340. if(! IsPlayerConnected(playerid)) return false;
  341.  
  342. return GetPlayerNumberDynamicAreas(playerid);
  343. }
  344.  
  345. public OnPlayerEnterDynamicArea(playerid, areaid)
  346. {
  347. for(new zone = 0; zone < MAX_ZONES; zone++)
  348. {
  349. if(GangZoneExist(zone))
  350. {
  351. if(areaid == gGangzone[zone][E_dynamic])
  352. {
  353. CallLocalFunction("OnPlayerEnterGangZone", "dd", playerid, zone);
  354. break;
  355. }
  356. }
  357. }
  358. return CallLocalFunction("GZ_OnPlayerEnterDynamicArea", "ii", playerid, areaid);
  359. }
  360. #if defined _ALS_OnPlayerEnterDynamicArea
  361. #undef OnPlayerEnterDynamicArea
  362. #else
  363. #define _ALS_OnPlayerEnterDynamicArea
  364. #endif
  365. #define OnPlayerEnterDynamicArea GZ_OnPlayerEnterDynamicArea
  366. forward GZ_OnPlayerEnterDynamicArea(playerid, areaid);
  367.  
  368. //the system callback
  369. forward OnPlayerEnterGangZone(playerid, zone);
  370.  
  371. public OnPlayerLeaveDynamicArea(playerid, areaid)
  372. {
  373. for(new zone = 0; zone < MAX_ZONES; zone++)
  374. {
  375. if(GangZoneExist(zone))
  376. {
  377. if(areaid == gGangzone[zone][E_dynamic])
  378. {
  379. CallLocalFunction("OnPlayerLeaveGangZone", "dd", playerid, zone);
  380. break;
  381. }
  382. }
  383. }
  384. return CallLocalFunction("GZ_OnPlayerLeaveDynamicArea", "ii", playerid, areaid);
  385. }
  386. #if defined _ALS_OnPlayerLeaveDynamicArea
  387. #undef OnPlayerLeaveDynamicArea
  388. #else
  389. #define _ALS_OnPlayerLeaveDynamicArea
  390. #endif
  391. #define OnPlayerLeaveDynamicArea GZ_OnPlayerLeaveDynamicArea
  392. forward GZ_OnPlayerLeaveDynamicArea(playerid, areaid);
  393.  
  394. //the system callback
  395. forward OnPlayerLeaveGangZone(playerid, zone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement