Guest User

zone.inc 1.1 by Frenk96

a guest
Jan 13th, 2016
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.51 KB | None | 0 0
  1. #include <a_samp>
  2. #pragma tabsize 0
  3.  
  4. #define MAX_ZONE 1024
  5.  
  6. #define COLOR_GREY 0xAFAFAFAA
  7. #define COLOR_GREEN 0x33AA33AA
  8. #define COLOR_RED 0xAA3333AA
  9. #define COLOR_YELLOW 0xFFFF00AA
  10. #define COLOR_WHITE 0xFFFFFFAA
  11. #define COLOR_BLUE 0x0080C055
  12.  
  13. /*
  14. // Zone functions
  15. native CreateZone(Float:minX, Float:minY, Float:maxX, Float:maxY, color = COLOR_WHITE, name[] = "None", type[] = "None");
  16. native CreateZoneByRange(Float:X, Float:Y, Float:Range = 5.0, color = COLOR_WHITE, name[] = "None", type[] = "None");
  17. // NEW
  18. native CreateRhombusZone(Float:X, Float:Y, Float:Range = 50.0, color = COLOR_WHITE, name[] = "None", type[] = "None")
  19. native CreateTriangleZone(Float:X, Float:Y, Float:Range = 50.0, cardinalPoint[] = "North", color = COLOR_WHITE, name[] = "None", type[] = "None")
  20. //
  21. native GetZoneType(zoneid); // Changed
  22. native GetZoneName(zoneid);
  23. // Player functions
  24. native IsPlayerInZone(playerid, zoneid);
  25. native IsPlayerInAnyZone(playerid);
  26. native GetPlayerZone(playerid);
  27.  
  28. native Zone_OnPlayerConnect(playerid);
  29. // Callbacks
  30. forward OnPlayerEnterZone(playerid, zoneid);
  31. forward OnPlayerExitZone(playerid, zoneid);
  32. */
  33.  
  34. new CountZone=0;
  35.  
  36. enum EnumZone
  37. {
  38.     ID,
  39.     Name[24],
  40.     Type[24],
  41.     Color,
  42.     Float:MinX,
  43.     Float:MinY,
  44.     Float:MaxX,
  45.     Float:MaxY
  46. };
  47. new Zone[MAX_ZONE][EnumZone];//global
  48.  
  49. new InZone[MAX_PLAYERS];
  50.  
  51. new PlayerText:TextZone[MAX_PLAYERS];
  52.  
  53. forward OnPlayerEnterZone(playerid,zoneid);
  54. forward OnPlayerExitZone(playerid,zoneid);
  55. forward Functions(playerid);
  56.  
  57. public Functions(playerid)
  58. {
  59.     if(IsPlayerInAnyZone(playerid)==1)
  60.     {
  61.         if(InZone[playerid] == -1)
  62.         {
  63.             InZone[playerid] = GetPlayerZone(playerid);
  64.             CallLocalFunction("OnPlayerEnterZone", "dd", playerid, InZone[playerid]);
  65.             TextZone[playerid] = CreatePlayerTextDraw(playerid, 45 ,320, GetZoneName(InZone[playerid]));
  66.             PlayerTextDrawFont(playerid, TextZone[playerid] , 1);
  67.             PlayerTextDrawLetterSize(playerid, TextZone[playerid] , 0.6, 2);
  68.             PlayerTextDrawColor(playerid, TextZone[playerid] , 0xd6bd00FF);
  69.             PlayerTextDrawSetOutline(playerid, TextZone[playerid] , false);
  70.             PlayerTextDrawSetProportional(playerid, TextZone[playerid] , true);
  71.             PlayerTextDrawSetShadow(playerid, TextZone[playerid] , 1);
  72.             PlayerTextDrawShow(playerid, TextZone[playerid]);
  73.         }
  74.     }
  75.     else
  76.     {
  77.         if(InZone[playerid]!=-1)
  78.         {
  79.             CallLocalFunction("OnPlayerExitZone", "dd", playerid, InZone[playerid]);
  80.             PlayerTextDrawDestroy(playerid, TextZone[playerid]);
  81.             InZone[playerid] = -1;
  82.         }
  83.     }
  84.     return 1;
  85. }
  86.  
  87. // Zone Function
  88.  
  89. stock CreateZone(Float:minX, Float:minY, Float:maxX, Float:maxY, color = COLOR_WHITE, name[] = "None", type[] = "None")
  90. {
  91.     if(CountZone >= MAX_ZONE) return 0;
  92.     new zoneid=GangZoneCreate(minX,minY,maxX,maxY);
  93.     Zone[zoneid][ID]= zoneid;
  94.     Zone[zoneid][Color]= color;
  95.     Zone[zoneid][MinX]= minX;
  96.     Zone[zoneid][MinY]= minY;
  97.     Zone[zoneid][MaxX]= maxX;
  98.     Zone[zoneid][MaxY]= maxY;
  99.     strcat(Zone[zoneid][Type], type);
  100.     if(strcmp(name, "None")==0) format(Zone[zoneid][Name],24,"Zone %d", zoneid);
  101.     else format(Zone[zoneid][Name],24,"%s", name);
  102.     CountZone++;
  103.     GangZoneShowForAll(zoneid, color);
  104.     return zoneid;
  105. }
  106.  
  107. stock CreateZoneByRange(Float:X, Float:Y, Float:Range = 50.0, color = COLOR_WHITE, name[] = "None", type[] = "None")
  108. {
  109.     if(CountZone >= MAX_ZONE) return 0;
  110.     new Float:minX = X-Range, Float:minY = Y-Range, Float:maxX = X+Range, Float:maxY = Y+Range;
  111.     new zoneid=GangZoneCreate(minX,minY,maxX,maxY);
  112.     Zone[zoneid][ID]= zoneid;
  113.     Zone[zoneid][Color]= color;
  114.     Zone[zoneid][MinX]= minX;
  115.     Zone[zoneid][MinY]= minY;
  116.     Zone[zoneid][MaxX]= maxX;
  117.     Zone[zoneid][MaxY]= maxY;
  118.     format(Zone[zoneid][Type],24,"%s", type);
  119.     if(strcmp(name, "None")==0) format(Zone[zoneid][Name],24,"Zona %d", zoneid);
  120.     else format(Zone[zoneid][Name],24,"%s", name);
  121.     CountZone++;
  122.     GangZoneShowForAll(zoneid, color);
  123.     return zoneid;
  124. }
  125.  
  126. stock CreateRhombusZone(Float:X, Float:Y, Float:Range = 50.0, color = COLOR_WHITE, name[] = "None", type[] = "None")
  127. {
  128.     new Float:minX, Float:minY, Float:maxX, Float:maxY;
  129.     new i=0;
  130.     while(i <= Range)
  131.     {
  132.         minX = X-Range+i; minY = Y-i; maxX = X+Range-i; maxY = Y+i;
  133.         CreateZone(minX, minY, maxX, maxY, color, name, type);
  134.         i++;
  135.     }
  136.     return i;
  137. }
  138.  
  139. stock CreateTriangleZone(Float:X, Float:Y, Float:Range = 50.0, cardinalPoint[] = "North", color = COLOR_WHITE, name[] = "None", type[] = "None")
  140. {
  141.     new Float:minX, Float:minY, Float:maxX, Float:maxY;
  142.     new i=0;
  143.     while(i <= Range)
  144.     {
  145.         if(strcmp(cardinalPoint, "North")==0) { minX = X-Range+i; minY = Y; maxX = X+Range-i; maxY = Y+i; }
  146.         else if(strcmp(cardinalPoint, "South")==0) { minX = X-Range+i; minY = Y-i; maxX = X+Range-i; maxY = Y; }
  147.         else if(strcmp(cardinalPoint, "East")==0) { minX = X; minY = Y-i; maxX = X+Range-i; maxY = Y+i; }
  148.         else if(strcmp(cardinalPoint, "West")==0) { minX = X-Range+i; minY = Y-i; maxX = X; maxY = Y+i; }
  149.         CreateZone(minX, minY, maxX, maxY, color, name, type);
  150.         i++;
  151.     }
  152.     return i;
  153. }
  154.  
  155. stock GetZoneType(zoneid)
  156. {
  157.     new type[24] = "Invalid Zone";
  158.     format(type,24,"%s", Zone[zoneid][Type]);
  159.     return type;
  160. }
  161.  
  162. stock GetZoneName(zoneid)
  163. {
  164.     new name[24] = "Invalid Zone";
  165.     format(name,24,"%s", Zone[zoneid][Name]);
  166.     return name;
  167. }
  168.  
  169. // Player function
  170.  
  171. stock IsPlayerInZone(playerid, zoneid)
  172. {
  173.     new Float:Px, Float:Py, Float:Pz;
  174.     GetPlayerPos(playerid, Px, Py, Pz);
  175.     if(Px>Zone[zoneid][MinX] && Py>Zone[zoneid][MinY] && Px<Zone[zoneid][MaxX] && Py<Zone[zoneid][MaxY]) return 1;
  176.     else return 0;
  177. }
  178.  
  179. stock IsPlayerInAnyZone(playerid)
  180. {
  181.     new Float:Px, Float:Py, Float:Pz;
  182.     GetPlayerPos(playerid, Px, Py, Pz);
  183.     for(new i = 0; i < CountZone; i++)
  184.     {
  185.       if(Px>Zone[i][MinX] && Py>Zone[i][MinY] && Px<Zone[i][MaxX] && Py<Zone[i][MaxY]) return 1;
  186.     }
  187.     return 0;
  188. }
  189.  
  190. stock GetPlayerZone(playerid)
  191. {
  192.     new Float:Px, Float:Py, Float:Pz;
  193.     GetPlayerPos(playerid, Px, Py, Pz);
  194.     for(new i = 0; i < CountZone; i++)
  195.     {
  196.       if(Px>Zone[i][MinX] && Py>Zone[i][MinY] && Px<Zone[i][MaxX] && Py<Zone[i][MaxY]) return i;
  197.     }
  198.     return -1;
  199. }
  200.  
  201. stock Zone_OnPlayerConnect(playerid)
  202. {
  203.     for(new i = 0; i <= CountZone; i++)
  204.     {
  205.       GangZoneShowForAll(i, Zone[i][Color]);
  206.     }
  207.     InZone[playerid] = -1;
  208.     SetTimerEx("Functions", 500, true, "i", playerid);
  209.     return 1;
  210. }
  211.  
  212. // Callbacks
  213.  
  214. public OnPlayerConnect(playerid)
  215. {
  216.     Zone_OnPlayerConnect(playerid);
  217.     return 1;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment