Advertisement
Seregamil

new Areas

May 13th, 2013
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. // By Seregamil
  2. #include <a_samp>
  3.  
  4. #define m_a 12//arg/4=количество зон
  5. #define m_z 3//количество зон максимум
  6.  
  7. #include mxINI
  8.  
  9. new Float:pos[m_z][4];
  10. new areas = 0;
  11. new countcoords;
  12. new zone[m_z];
  13.  
  14. main()
  15. {
  16. readFileZone("RDM/area.ini");
  17. }
  18.  
  19. readFileZone(len[])
  20. {
  21. new str[150];
  22. new file = ini_openFile(len);
  23. ini_getString(file,"Zone",str);
  24. ini_closeFile(file);
  25. return readCoords(str);
  26. }
  27.  
  28. readCoords(arg[])
  29. {
  30. new idx;
  31.  
  32. new coord = 0;
  33. new area = 0;
  34. countcoords = 0;
  35.  
  36. for(new x;x!=m_a;x++){
  37. new Float:ok = floatstr(strtok(arg, idx, ','));//read
  38. if(ok == 0.00000) break;//stop
  39. pos[area][coord] = ok;//save
  40. //printf("pos[%d][%d] = %f",area,coord,pos[area][coord]);//send
  41. coord++;//add coord
  42. countcoords++;
  43. if(coord == 4) {
  44. areas++;
  45. area++;//+1 number
  46. coord = 0;//0 coord
  47. }
  48. }
  49. if(countcoords % 4 == 0)//allcoords % 4 - yes
  50. {
  51. for(new l;l!=sizeof zone;l++) GangZoneDestroy(zone[l]);
  52. new zones = 0;
  53. for(new x;x!=areas;x++)
  54. {
  55. zone[x] = GangZoneCreate(pos[x][0],pos[x][1],pos[x][2],pos[x][3]);
  56. //printf("%d - created",x);
  57. GangZoneShowForAll(zone[x], 0x000000FF);
  58. zones++;
  59. if(zones == areas) break;
  60. }
  61. }
  62. printf("Количество арен:%d",areas);
  63. SetTimer("update",500,1);
  64. return 1;
  65. }
  66.  
  67. forward update();
  68. public update()
  69. {
  70. for(new x;x!=GetMaxPlayers();x++) if(IsPlayerConnected(x) && !IsPlayerNPC(x)) search(x,areas);
  71. }
  72.  
  73. new Float:xx[MAX_PLAYERS],Float:yy[MAX_PLAYERS],Float:zz[MAX_PLAYERS];
  74.  
  75. search(playerid,&index)
  76. {
  77. new select = -1;
  78. for(new j;j!=index;j++)
  79. {
  80. if(InTheGangZone(playerid,pos[j][0],pos[j][1],pos[j][2],pos[j][3])) {
  81. save(playerid);
  82. select = j;
  83. break;
  84. }
  85. }
  86. if(select == -1) escape(playerid);
  87. }
  88.  
  89. save(playerid)
  90. {
  91. new Float:x,Float:y,Float:z;
  92. if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid,x,y,z);
  93. else GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
  94. xx[playerid] = x;
  95. yy[playerid] = y;
  96. zz[playerid] = z;
  97. return true;
  98. }
  99.  
  100. escape(playerid)
  101. {
  102. if(!IsPlayerInAnyVehicle(playerid)) SetPlayerPos(playerid,xx[playerid],yy[playerid],zz[playerid]);
  103. else SetVehiclePos(playerid,xx[playerid],yy[playerid],zz[playerid]);
  104. return 1;
  105. }
  106.  
  107. stock InTheGangZone(playerid,Float:min_x,Float:min_y,Float:max_x,Float:max_y)
  108. {
  109. new Float:xxxx,Float:yyyy,Float:zzzz;
  110. GetPlayerPos(playerid,xxxx,yyyy,zzzz);
  111. if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid),xxxx,yyyy,zzzz);
  112. if((xxxx <= max_x && xxxx >= min_x) && (yyyy <= max_y && yyyy >= min_y))return 1;
  113. return 0;
  114. }
  115. strtok(const string[], &index,seperator=' ')
  116. {
  117. new length = strlen(string);
  118. new offset = index;
  119. new result[256];
  120. while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
  121. {
  122. result[index - offset] = string[index];
  123. index++;
  124. }
  125. result[index - offset] = EOS;
  126. if ((index < length) && (string[index] == seperator)) index++;
  127. return result;
  128. }
  129.  
  130. public OnPlayerSpawn(playerid)
  131. {
  132. for(new x;x!=sizeof zone;x++) GangZoneShowForPlayer(playerid,zone[x], 0x000000FF);
  133. return true;
  134. }
  135. // By Seregamil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement