Guest User

zone.inc by Frenk96

a guest
Jan 8th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.07 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[] = "Safe");
  17. native GetTypeZone(zoneid);
  18. native GetZoneName(zoneid);
  19. // Player functions
  20. native IsPlayerInZone(playerid, zoneid);
  21. native IsPlayerInAnyZone(playerid);
  22. native GetPlayerZone(playerid);
  23.  
  24. native Zone_OnPlayerConnect(playerid);
  25. // Callbacks
  26. forward OnPlayerEnterZone(playerid, zoneid);
  27. forward OnPlayerExitZone(playerid, zoneid);
  28. */
  29.  
  30. new CountZone=0;
  31.  
  32. enum EnumZone
  33. {
  34.     ID,
  35.     Name[24],
  36.     Type[24],
  37.     Color,
  38.     Float:MinX,
  39.     Float:MinY,
  40.     Float:MaxX,
  41.     Float:MaxY
  42. };
  43. new Zone[MAX_ZONE][EnumZone];//global
  44.  
  45. new InZone[MAX_PLAYERS];
  46.  
  47. new PlayerText:TextZone[MAX_PLAYERS];
  48.  
  49. forward OnPlayerEnterZone(playerid,zoneid);
  50. forward OnPlayerExitZone(playerid,zoneid);
  51. forward Functions(playerid);
  52.  
  53. public Functions(playerid)
  54. {
  55.     if(IsPlayerInAnyZone(playerid)==1)
  56.     {
  57.         if(InZone[playerid] == -1)
  58.         {
  59.             InZone[playerid] = GetPlayerZone(playerid);
  60.             CallLocalFunction("OnPlayerEnterZone", "dd", playerid, InZone[playerid]);
  61.             TextZone[playerid] = CreatePlayerTextDraw(playerid, 45 ,320, GetZoneName(InZone[playerid]));
  62.             PlayerTextDrawFont(playerid, TextZone[playerid] , 1);
  63.             PlayerTextDrawLetterSize(playerid, TextZone[playerid] , 0.6, 2);
  64.             PlayerTextDrawColor(playerid, TextZone[playerid] , 0xd6bd00FF);
  65.             PlayerTextDrawSetOutline(playerid, TextZone[playerid] , false);
  66.             PlayerTextDrawSetProportional(playerid, TextZone[playerid] , true);
  67.             PlayerTextDrawSetShadow(playerid, TextZone[playerid] , 1);
  68.             PlayerTextDrawShow(playerid, TextZone[playerid]);
  69.         }
  70.     }
  71.     else
  72.     {
  73.         if(InZone[playerid]!=-1)
  74.         {
  75.             CallLocalFunction("OnPlayerExitZone", "dd", playerid, InZone[playerid]);
  76.             PlayerTextDrawDestroy(playerid, TextZone[playerid]);
  77.             InZone[playerid] = -1;
  78.         }
  79.     }
  80.     return 1;
  81. }
  82.  
  83. // Zone Function
  84.  
  85. stock CreateZone(Float:minX, Float:minY, Float:maxX, Float:maxY, color = COLOR_WHITE, name[] = "None", type[] = "None")
  86. {
  87.     if(CountZone >= MAX_ZONE) return 0;
  88.     new zoneid=GangZoneCreate(minX,minY,maxX,maxY);
  89.     Zone[zoneid][ID]= zoneid;
  90.     Zone[zoneid][Color]= color;
  91.     Zone[zoneid][MinX]= minX;
  92.     Zone[zoneid][MinY]= minY;
  93.     Zone[zoneid][MaxX]= maxX;
  94.     Zone[zoneid][MaxY]= maxY;
  95.     strcat(Zone[zoneid][Type], type);
  96.     if(strcmp(name, "None")==0) format(Zone[zoneid][Name],24,"Zone %d", zoneid);
  97.     else format(Zone[zoneid][Name],24,"%s", name);
  98.     CountZone++;
  99.     GangZoneShowForAll(zoneid, color);
  100.     return zoneid;
  101. }
  102.  
  103. stock CreateZoneByRange(Float:X, Float:Y, Float:Range = 5.0, color = COLOR_WHITE, name[] = "None", type[] = "Safe")
  104. {
  105.     if(CountZone >= MAX_ZONE) return 0;
  106.     new Float:minX = X-Range, Float:minY = Y-Range, Float:maxX = X+Range, Float:maxY = Y+Range;
  107.     new zoneid=GangZoneCreate(minX,minY,maxX,maxY);
  108.     Zone[zoneid][ID]= zoneid;
  109.     Zone[zoneid][Color]= color;
  110.     Zone[zoneid][MinX]= minX;
  111.     Zone[zoneid][MinY]= minY;
  112.     Zone[zoneid][MaxX]= maxX;
  113.     Zone[zoneid][MaxY]= maxY;
  114.     format(Zone[zoneid][Type],24,"%s", type);
  115.     if(strcmp(name, "None")==0) format(Zone[zoneid][Name],24,"Zona %d", zoneid);
  116.     else format(Zone[zoneid][Name],24,"%s", name);
  117.     CountZone++;
  118.     GangZoneShowForAll(zoneid, color);
  119.     return zoneid;
  120. }
  121.  
  122. stock GetTypeZone(zoneid)
  123. {
  124.     new type[24] = "Invalid Zone";
  125.     format(type,24,"%s", Zone[zoneid][Type]);
  126.     return type;
  127. }
  128.  
  129. stock GetZoneName(zoneid)
  130. {
  131.     new name[24] = "Invalid Zone";
  132.     format(name,24,"%s", Zone[zoneid][Name]);
  133.     return name;
  134. }
  135.  
  136. // Player function
  137.  
  138. stock IsPlayerInZone(playerid, zoneid)
  139. {
  140.     new Float:Px, Float:Py, Float:Pz;
  141.     GetPlayerPos(playerid, Px, Py, Pz);
  142.     if(Px>Zone[zoneid][MinX] && Py>Zone[zoneid][MinY] && Px<Zone[zoneid][MaxX] && Py<Zone[zoneid][MaxY]) return 1;
  143.     else return 0;
  144. }
  145.  
  146. stock IsPlayerInAnyZone(playerid)
  147. {
  148.     new Float:Px, Float:Py, Float:Pz;
  149.     GetPlayerPos(playerid, Px, Py, Pz);
  150.     for(new i = 0; i < CountZone; i++)
  151.     {
  152.       if(Px>Zone[i][MinX] && Py>Zone[i][MinY] && Px<Zone[i][MaxX] && Py<Zone[i][MaxY]) return 1;
  153.     }
  154.     return 0;
  155. }
  156.  
  157. stock GetPlayerZone(playerid)
  158. {
  159.     new Float:Px, Float:Py, Float:Pz;
  160.     GetPlayerPos(playerid, Px, Py, Pz);
  161.     for(new i = 0; i < CountZone; i++)
  162.     {
  163.       if(Px>Zone[i][MinX] && Py>Zone[i][MinY] && Px<Zone[i][MaxX] && Py<Zone[i][MaxY]) return i;
  164.     }
  165.     return -1;
  166. }
  167.  
  168. stock Zone_OnPlayerConnect(playerid)
  169. {
  170.     for(new i = 0; i <= CountZone; i++)
  171.     {
  172.       GangZoneShowForAll(i, Zone[i][Color]);
  173.     }
  174.     InZone[playerid] = -1;
  175.     SetTimerEx("Functions", 500, true, "i", playerid);
  176.     return 1;
  177. }
  178.  
  179. // Callbacks
  180.  
  181. public OnPlayerConnect(playerid)
  182. {
  183.     Zone_OnPlayerConnect(playerid);
  184.     return 1;
  185. }
Advertisement
Add Comment
Please, Sign In to add comment