Advertisement
Guest User

Seif

a guest
Jul 3rd, 2009
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.81 KB | None | 0 0
  1. /*
  2.                                 Gang Zone Maker - By Seif
  3. */
  4. /*x---------------------------------Important-------------------------------------x*/
  5. //**INCLUDES**//
  6. #include <a_samp>
  7. //**PRAGMAS**//
  8.  
  9. //**MISC**//
  10.  
  11. /*x---------------------------------Defining-------------------------------------x*/
  12. //**COLORS*//
  13. #define GREEN           0x21DD00FF
  14. #define RED             0xE60000FF
  15. #define ADMIN_RED       0xFB0000FF
  16. #define YELLOW          0xFFFF00FF
  17. #define ORANGE          0xF97804FF
  18. #define LIGHTRED        0xFF8080FF
  19. #define LIGHTBLUE       0x00C2ECFF
  20. #define PURPLE          0xB360FDFF
  21. #define PLAYER_COLOR    0xFFFFFFFF
  22. #define BLUE            0x1229FAFF
  23. #define LIGHTGREEN      0x38FF06FF
  24. #define DARKPINK        0xE100E1FF
  25. #define DARKGREEN       0x008040FF
  26. #define ANNOUNCEMENT    0x6AF7E1FF
  27. #define COLOR_SYSTEM    0xEFEFF7AA
  28. #define GREY            0xCECECEFF
  29. #define PINK            0xD52DFFFF
  30. #define DARKGREY        0x626262FF
  31. #define AQUAGREEN       0x03D687FF
  32. #define NICESKY         0x99FFFFAA
  33. #define WHITE           0xFFFFFFFF
  34. //**MISC**//
  35. #define MAX_PICKUPS     400         // SA-MP's pickup limit
  36. #define MAX_TURFS       100         // Maximum turfs creatable by default. Best to only decrease it when editing. Each turf has 4 pickups each. 4*100 = 400 = pickup limit.
  37. #define DEFAULTCOLOR    WHITE       // Default color for gang zone creation(In full alpha 255(FF) recommended)
  38. #define ALPHA           128         // The number of alpha you want to reduce from the color. Basically, the transparency. 128 = half
  39. //**VARIABLES**//
  40. enum tInfo
  41. {
  42.     Float:tMin_X,
  43.     Float:tMin_Y,
  44.     Float:tMin_Z,
  45.     Float:tMax_X,
  46.     Float:tMax_Y,
  47.     Float:tMax_Z,
  48.     tID,
  49.     tColor,
  50. }
  51. new TurfInfo[MAX_TURFS][tInfo];
  52. enum pInfo
  53. {
  54.     Float:pX,
  55.     Float:pY,
  56.     Float:pZ,
  57.     pID,
  58.     pTurfID,
  59. }
  60. new PickupInfo[MAX_PICKUPS][pInfo];
  61. new Menu:zone;
  62. new AreaAvailability[MAX_TURFS];
  63. new LastTurf[MAX_PLAYERS];
  64. // **FORWARDS** //
  65.  
  66. /*x---------------------------------CallBacks-------------------------------------x*/
  67. public OnFilterScriptInit()
  68. {
  69.     zone = CreateMenu("Turf Maker", 0, 20, 120, 150, 400);
  70.     AddMenuItem(zone, 0, "Minimum");
  71.     AddMenuItem(zone, 0, "Maximum");
  72.    
  73.     for(new t; t < MAX_TURFS; t++)
  74.     {
  75.         DestroyArea(t);
  76.     }
  77.    
  78.     for(new p; p < MAX_PICKUPS; p++)
  79.     {
  80.         PickupInfo[p][pX] = 0.0;
  81.         PickupInfo[p][pY] = 0.0;
  82.         PickupInfo[p][pZ] = 0.0;
  83.         PickupInfo[p][pID] = -1;
  84.         PickupInfo[p][pTurfID] = -1;
  85.     }
  86.    
  87.     for(new i; i < MAX_PLAYERS; i++)
  88.     {
  89.         LastTurf[i] = -1;
  90.     }
  91.    
  92. //    LoadTurfFile(); // Loads the saved turfs
  93.  
  94.     print("<|-----------------------------------------|>");
  95.     print("    .:[ - Gang Zone Maker by Seif - ]:.");
  96.     print("<|-----------------------------------------|>");
  97.     return 1;
  98. }
  99.  
  100. public OnFilterScriptExit()
  101. {
  102.     DestroyMenu(zone);
  103.     for(new p; p < MAX_PICKUPS; p++)
  104.     {
  105.         DestroyPickup(p);
  106.     }
  107.     for(new t; t < MAX_TURFS; t++)
  108.     {
  109.         GangZoneDestroy(t);
  110.     }
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerConnect(playerid)
  115. {
  116.     return 1;
  117. }
  118.  
  119. public OnPlayerDisconnect(playerid, reason)
  120. {
  121.     LastTurf[playerid] = -1;
  122.     return 1;
  123. }
  124.  
  125. public OnPlayerSpawn(playerid)
  126. {
  127.     return 1;
  128. }
  129.  
  130. public OnPlayerDeath(playerid, killerid, reason)
  131. {
  132.     return 1;
  133. }
  134.  
  135. public OnVehicleSpawn(vehicleid)
  136. {
  137.     return 1;
  138. }
  139.  
  140. public OnVehicleDeath(vehicleid, killerid)
  141. {
  142.     return 1;
  143. }
  144.  
  145. public OnPlayerText(playerid, text[])
  146. {
  147.     return 1;
  148. }
  149.  
  150. public OnPlayerPrivmsg(playerid, recieverid, text[])
  151. {
  152.     return 1;
  153. }
  154.  
  155. public OnPlayerCommandText(playerid, cmdtext[])
  156. {
  157.     new cmd[128], idx, tmp[128];
  158.     cmd = strtok(cmdtext, idx);
  159.    
  160.     if (!strcmp("/turf", cmd, true))
  161.     {
  162.         tmp = strtok(cmdtext, idx);
  163.         if (!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "USAGE: /turf [create/destroy/color/save/load/goto]");
  164.        
  165.         if (!strcmp("create", tmp, true))
  166.         {
  167.             SetPlayerFacingAngle(playerid, 0);
  168.             SetCameraBehindPlayer(playerid);
  169.             TogglePlayerControllable(playerid, false);
  170.             ShowMenuForPlayer(zone, playerid);
  171.         }
  172.         else if (!strcmp("destroy", tmp, true))
  173.         {
  174.             if (IsPlayerInATurf(playerid))
  175.             {
  176.                 for(new i; i < MAX_TURFS; i++)
  177.                 {
  178.                     if (!AreaAvailability[i])
  179.                     {
  180.                         if (IsPlayerInArea(playerid, TurfInfo[i][tMax_X], TurfInfo[i][tMin_X], TurfInfo[i][tMax_Y], TurfInfo[i][tMin_Y]))
  181.                         {
  182.                             GangZoneDestroy(TurfInfo[i][tID]);
  183.                             for(new p; p < MAX_PICKUPS; p++)
  184.                             {
  185.                                 if (PickupInfo[p][pTurfID] == TurfInfo[i][tID])
  186.                                 {
  187.                                     DestroyPickup(p);
  188.                                 }
  189.                             }
  190.                             DestroyArea(i);
  191.                             SendClientMessage(playerid, GREEN, "Turf erased!");
  192.                             return 1;
  193.                         }
  194.                     }
  195.                 }
  196.             }
  197.             else SendClientMessage(playerid, RED, "You must be at the zone you want to destroy!");
  198.         }
  199.         else if (!strcmp("color", tmp, true))
  200.         {
  201.             if (IsPlayerInATurf(playerid))
  202.             {
  203.                 tmp = strtok(cmdtext, idx);
  204.                
  205.                 SendClientMessage(playerid, LIGHTGREEN, "|- Color List -|");
  206.  
  207.                 new areaid = -1;
  208.                 if (!fexist("TurfColors.txt"))
  209.                 {
  210.                     print("color file doesn't exist");
  211.                     SendClientMessage(playerid, RED, "None. Please ask the server owner to add colors in the file 'TurfColors.txt' in the following format: ColorName,HexColor");
  212.                     return 1;
  213.                 }
  214.                
  215.                 new str[128], LineColor[100]; // 100 = max colors your file can contain. I don't think you'll ever exceed that?
  216.                 new File:areafile = fopen("TurfColors.txt", io_read);
  217.                 if (areafile)
  218.                 {
  219.                     print("opening color file");
  220.                     new colorstr[256], lines;
  221.                     while (fread(areafile, colorstr, 256))
  222.                     {
  223.                         lines++;
  224.                         format(str, sizeof str, "%d- %s", lines, colorstr);
  225.                         new colorvar;
  226.                         if (strfind(colorstr, ",", false) != -1)
  227.                         {
  228.                             strdel(colorstr, 0, strfind(colorstr, ",", false)+1);
  229.                             if (strlen(colorstr) > 10) strdel(colorstr, strlen(colorstr)-2, strlen(colorstr));
  230.                             colorvar = HexToInt(colorstr)-ALPHA; // 80 = alpha
  231.                             LineColor[lines] = colorvar;
  232.                         }
  233.                         SendClientMessage(playerid, colorvar, str);
  234.                     }
  235.                     for(new i; i < MAX_TURFS; i++)
  236.                     {
  237.                         if (!AreaAvailability[i])
  238.                         {
  239.                             if (IsPlayerInArea(playerid, TurfInfo[i][tMax_X], TurfInfo[i][tMin_X], TurfInfo[i][tMax_Y], TurfInfo[i][tMin_Y]))
  240.                             {
  241.                                 areaid = i;
  242.                                 fclose(areafile);
  243.                                 break;
  244.                             }
  245.                         }
  246.                     }
  247.                     if (areaid == -1)
  248.                     {
  249.                         SendClientMessage(playerid, RED, "You're not in a created area!");
  250.                         fclose(areafile);
  251.                         return 1;
  252.                     }
  253.                     fclose(areafile);
  254.                 }
  255.                 if (!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "USAGE: /turf [create/destroy/COLOR/save/load/goto] [color id](listed above)");
  256.                 new colorid = strval(tmp);
  257.  
  258.                 TurfInfo[areaid][tColor] = LineColor[colorid];
  259.                 GangZoneShowForAll(TurfInfo[areaid][tID], LineColor[colorid]);
  260.                 format(str, sizeof str, "Color changed to ID %d", colorid);
  261.                 SendClientMessage(playerid, LineColor[colorid], str);
  262.             }
  263.             else SendClientMessage(playerid, RED, "You must be at the zone you want to save(make sure you created it first!)");
  264.         }
  265.         else if (!strcmp("save", tmp, true))
  266.         {
  267.             if (IsPlayerInATurf(playerid))
  268.             {
  269.                 tmp = msgstrtok(cmdtext, idx);
  270.                 if (!strlen(tmp)) return SendClientMessage(playerid, RED, "You must enter a comment!");
  271.                
  272.                 new areaid = -1;
  273.                 if (!fexist("TurfCoords.pwn"))
  274.                 {
  275.                     print("file doesn't exist");
  276.                     new File:newfile = fopen("TurfCoords.pwn", io_write);
  277.                     if (newfile)
  278.                     {
  279.                         print("made new file");
  280.                         fwrite(newfile, " ");
  281.                         fclose(newfile);
  282.                     }
  283.                 }
  284.                 print("file now exists");
  285.                 new File:areafile = fopen("TurfCoords.pwn", io_append);
  286.                 if (areafile)
  287.                 {
  288.                     print("opening file");
  289.                     for(new i; i < MAX_TURFS; i++)
  290.                     {
  291.                         if (!AreaAvailability[i])
  292.                         {
  293.                             if (IsPlayerInArea(playerid, TurfInfo[i][tMax_X], TurfInfo[i][tMin_X], TurfInfo[i][tMax_Y], TurfInfo[i][tMin_Y]))
  294.                             {
  295.                                 areaid = i;
  296.                                 break;
  297.                             }
  298.                         }
  299.                     }
  300.                     if (areaid == -1)
  301.                     {
  302.                         SendClientMessage(playerid, RED, "You're not in a created area!");
  303.                         fclose(areafile);
  304.                     }
  305.                     print("saving...");
  306.                     new string[256];
  307.                     format(string, sizeof string, "// Gang Zone Maker(SeifTurf) by Seif -- '%s' //\n%f, %f, %f, %f\nnew zoneid = GangZoneCreate(playerid, %f, %f, %f, %f);\nGangZoneShowForAll(zoneid, %d);\n", tmp, TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tColor]);
  308.                     fwrite(areafile, string);
  309.                     fclose(areafile);
  310.                     AddToLoadFile(areaid, tmp);
  311.                     SendClientMessage(playerid, LIGHTGREEN, "Turf coordinates saved in /scriptfiles/TurfCoords.pwn !");
  312.                 }
  313.             }
  314.             else SendClientMessage(playerid, RED, "You must be at the zone you want to save(make sure you created it first!)");
  315.         }
  316.         else if (!strcmp("load", tmp, true))
  317.         {
  318.             LoadTurfFile();
  319.             SendClientMessage(playerid, LIGHTGREEN, " All saved turfs have loaded!");
  320.         }
  321.         else if (!strcmp("goto", tmp, true))
  322.         {
  323.             tmp = strtok(cmdtext, idx);
  324.             if (!strlen(tmp)) return SendClientMessage(playerid, RED, "You must pick a pickup to teleport to(1-4)");
  325.             new pickup = strval(tmp);
  326.             if (pickup < 1 || pickup > 4) return SendClientMessage(playerid, RED, "There are only 4 pickups per turf!");
  327.            
  328.             if (IsPlayerInATurf(playerid))
  329.             {
  330.                 for(new i; i < MAX_TURFS; i++)
  331.                 {
  332.                     if (!AreaAvailability[i])
  333.                     {
  334.                         if (IsPlayerInArea(playerid, TurfInfo[i][tMax_X], TurfInfo[i][tMin_X], TurfInfo[i][tMax_Y], TurfInfo[i][tMin_Y]))
  335.                         {
  336.                             new Pickup[4];
  337.                             new pickupid;
  338.                             for(new p; p < MAX_PICKUPS; p++)
  339.                             {
  340.                                 if (PickupInfo[p][pTurfID] == TurfInfo[i][tID])
  341.                                 {
  342.                                     Pickup[pickupid] = p;
  343.                                     pickupid++;
  344.                                 }
  345.                             }
  346.                             pickupid = Pickup[pickup-1];
  347.                             SetPlayerPos(playerid, PickupInfo[pickupid][pX], PickupInfo[pickupid][pY], PickupInfo[pickupid][pZ]);
  348.                             SetPlayerFacingAngle(playerid, 0.0);
  349.                             return 1;
  350.                         }
  351.                     }
  352.                 }
  353.             }
  354.             else SendClientMessage(playerid, RED, "You must be at the turf where you want to teleport to one of its pickups!");
  355.         }
  356.         else return SendClientMessage(playerid, ORANGE, "USAGE: /turf [create/destroy/color/save/load/goto]");
  357.         return 1;
  358.     }
  359.     return 0;
  360. }
  361.  
  362. public OnPlayerSelectedMenuRow(playerid, row)
  363. {
  364.     new Menu:menu = GetPlayerMenu(playerid);
  365.     if (menu == zone)
  366.     {
  367.         HideMenuForPlayer(menu, playerid);
  368.         switch (row)
  369.         {
  370.             case 0: // Minimum
  371.             {
  372.                 new areaid;
  373.                 if (LastTurf[playerid] != -1) areaid = LastTurf[playerid];
  374.                 else areaid = FindAreaID();
  375.                 printf("last: %d - found: %d", LastTurf[playerid], FindAreaID());
  376.                 new Float:X,Float:Y,Float:Z;
  377.                 GetPlayerPos(playerid, X, Y, Z);
  378.                 TurfInfo[areaid][tMin_X] = X;
  379.                 TurfInfo[areaid][tMin_Y] = Y;
  380.                 TurfInfo[areaid][tMin_Z] = Z;
  381.                 if (LastTurf[playerid] == -1) LastTurf[playerid] = areaid;
  382.                 else LastTurf[playerid] = -1;
  383.                 OnPlayerExitedMenu(playerid);
  384.                 printf("availability: %d - TURF: %d", AreaAvailability[areaid], areaid);
  385.                 if (AreaAvailability[areaid] == 0)
  386.                 {
  387.                     new pickupid;
  388.                     new gangid = GangZoneCreate(TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y]);
  389.                     GangZoneShowForAll(gangid, DEFAULTCOLOR-ALPHA);
  390.                     TurfInfo[areaid][tID] = gangid;
  391.                     TurfInfo[areaid][tColor] = DEFAULTCOLOR-ALPHA;
  392.                     printf("zone id: %d, areaid: %d", TurfInfo[areaid][tID], areaid);
  393.  
  394.                     pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMin_Z]);
  395.                     PickupInfo[pickupid][pX] = TurfInfo[areaid][tMin_X];
  396.                     PickupInfo[pickupid][pY] = TurfInfo[areaid][tMin_Y];
  397.                     PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMin_Z];
  398.                     PickupInfo[pickupid][pTurfID] = gangid;
  399.  
  400.                     pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMax_Z]);
  401.                     PickupInfo[pickupid][pX] = TurfInfo[areaid][tMax_X];
  402.                     PickupInfo[pickupid][pY] = TurfInfo[areaid][tMax_Y];
  403.                     PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMax_Z];
  404.                     PickupInfo[pickupid][pTurfID] = gangid;
  405.  
  406.                     X = TurfInfo[areaid][tMin_X];   // North west
  407.                     Y = TurfInfo[areaid][tMax_Y];
  408.                     Z = TurfInfo[areaid][tMax_Z];
  409.                     pickupid = CreatePickup(1239, 23, X, Y, Z);
  410.                     PickupInfo[pickupid][pX] = X;
  411.                     PickupInfo[pickupid][pY] = Y;
  412.                     PickupInfo[pickupid][pZ] = Z;
  413.                     PickupInfo[pickupid][pTurfID] = gangid;
  414.  
  415.                     X = TurfInfo[areaid][tMax_X];   // South east
  416.                     Y = TurfInfo[areaid][tMin_Y];
  417.                     Z = TurfInfo[areaid][tMin_Z];
  418.                     pickupid = CreatePickup(1239, 23, X, Y, Z);
  419.                     PickupInfo[pickupid][pX] = X;
  420.                     PickupInfo[pickupid][pY] = Y;
  421.                     PickupInfo[pickupid][pZ] = Z;
  422.                     PickupInfo[pickupid][pTurfID] = gangid;
  423.                 }
  424.                 AreaAvailability[areaid] = 0;
  425.                 printf("availabilityTWO: %d - TURF: %d", AreaAvailability[areaid], areaid);
  426.                 SendClientMessage(playerid, GREEN, "Minimum X and Y created");
  427.             }
  428.             case 1: // Maximum
  429.             {
  430.                 new areaid;
  431.                 if (LastTurf[playerid] != -1) areaid = LastTurf[playerid];
  432.                 else areaid = FindAreaID();
  433.                 printf("last: %d - found: %d", LastTurf[playerid], FindAreaID());
  434.                 new Float:X,Float:Y,Float:Z;
  435.                 GetPlayerPos(playerid, X, Y, Z);
  436.                 TurfInfo[areaid][tMax_X] = X;
  437.                 TurfInfo[areaid][tMax_Y] = Y;
  438.                 TurfInfo[areaid][tMax_Z] = Z;
  439.                 if (LastTurf[playerid] == -1) LastTurf[playerid] = areaid;
  440.                 else LastTurf[playerid] = -1;
  441.                 OnPlayerExitedMenu(playerid);
  442.                 printf("availability: %d - TURF: %d", AreaAvailability[areaid], areaid);
  443.                 if (AreaAvailability[areaid] == 0)
  444.                 {
  445.                     new pickupid;
  446.                     new gangid = GangZoneCreate(TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y]);
  447.                     GangZoneShowForAll(gangid, DEFAULTCOLOR-ALPHA);
  448.                     TurfInfo[areaid][tID] = gangid;
  449.                     TurfInfo[areaid][tColor] = DEFAULTCOLOR-ALPHA;
  450.                     printf("zone id: %d, areaid: %d", TurfInfo[areaid][tID], areaid);
  451.  
  452.                     pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMin_Z]);
  453.                     PickupInfo[pickupid][pX] = TurfInfo[areaid][tMin_X];
  454.                     PickupInfo[pickupid][pY] = TurfInfo[areaid][tMin_Y];
  455.                     PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMin_Z];
  456.                     PickupInfo[pickupid][pTurfID] = gangid;
  457.  
  458.                     pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMax_Z]);
  459.                     PickupInfo[pickupid][pX] = TurfInfo[areaid][tMax_X];
  460.                     PickupInfo[pickupid][pY] = TurfInfo[areaid][tMax_Y];
  461.                     PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMax_Z];
  462.                     PickupInfo[pickupid][pTurfID] = gangid;
  463.  
  464.                     X = TurfInfo[areaid][tMin_X];   // North west
  465.                     Y = TurfInfo[areaid][tMax_Y];
  466.                     Z = TurfInfo[areaid][tMax_Z];
  467.                     pickupid = CreatePickup(1239, 23, X, Y, Z);
  468.                     PickupInfo[pickupid][pX] = X;
  469.                     PickupInfo[pickupid][pY] = Y;
  470.                     PickupInfo[pickupid][pZ] = Z;
  471.                     PickupInfo[pickupid][pTurfID] = gangid;
  472.  
  473.                     X = TurfInfo[areaid][tMax_X];   // South east
  474.                     Y = TurfInfo[areaid][tMin_Y];
  475.                     Z = TurfInfo[areaid][tMin_Z];
  476.                     pickupid = CreatePickup(1239, 23, X, Y, Z);
  477.                     PickupInfo[pickupid][pX] = X;
  478.                     PickupInfo[pickupid][pY] = Y;
  479.                     PickupInfo[pickupid][pZ] = Z;
  480.                     PickupInfo[pickupid][pTurfID] = gangid;
  481.                 }
  482.                 AreaAvailability[areaid] = 0;
  483.                 printf("availabilityTWO: %d - TURF: %d", AreaAvailability[areaid], areaid);
  484.                 SendClientMessage(playerid, GREEN, "Maximum X and Y created");
  485.             }
  486.         }
  487.     }
  488.     return 1;
  489. }
  490.  
  491. public OnPlayerExitedMenu(playerid)
  492. {
  493.     TogglePlayerControllable(playerid, true);
  494.     return 1;
  495. }
  496.  
  497. stock strtok(const string[], &index)
  498. {
  499.     new length = strlen(string);
  500.     while ((index < length) && (string[index] <= ' '))
  501.     {
  502.         index++;
  503.     }
  504.  
  505.     new offset = index;
  506.     new result[128];
  507.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  508.     {
  509.         result[index - offset] = string[index];
  510.         index++;
  511.     }
  512.     result[index - offset] = EOS;
  513.     return result;
  514. }
  515.  
  516. stock msgstrtok(const string[], &idx)
  517. {
  518.     new length = strlen(string);
  519.     while ((idx < length) && (string[idx] <= ' '))
  520.     {
  521.         idx++;
  522.     }
  523.     new offset = idx;
  524.     new result[128];
  525.     while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
  526.     {
  527.         result[idx - offset] = string[idx];
  528.         idx++;
  529.     }
  530.     result[idx - offset] = EOS;
  531.     return result;
  532. }
  533.  
  534. stock FindAreaID()
  535. {
  536.     for(new i; i < MAX_TURFS; i++)
  537.     {
  538.         if (AreaAvailability[i] == 1) return i;
  539.     }
  540.     return -1;
  541. }
  542.  
  543. stock IsPlayerInATurf(playerid)
  544. {
  545.     for(new i; i < MAX_TURFS; i++)
  546.     {
  547.         if (!AreaAvailability[i])
  548.         {
  549.             if (IsPlayerInArea(playerid, TurfInfo[i][tMax_X], TurfInfo[i][tMin_X], TurfInfo[i][tMax_Y], TurfInfo[i][tMin_Y]))
  550.             {
  551.                 return 1;
  552.             }
  553.         }
  554.     }
  555.     return 0;
  556. }
  557.  
  558. stock IsPlayerInArea(playerid, Float:max_x, Float:min_x, Float:max_y, Float:min_y)
  559. {
  560.     new Float:X, Float:Y, Float:Z;
  561.     GetPlayerPos(playerid, X, Y, Z);
  562.     if(X <= max_x && X >= min_x && Y <= max_y && Y >= min_y) return 1;
  563.     return 0;
  564. }
  565.  
  566. stock DestroyArea(areaid)
  567. {
  568.     TurfInfo[areaid][tMax_X] = 0.0;
  569.     TurfInfo[areaid][tMax_Y] = 0.0;
  570.     TurfInfo[areaid][tMax_Z] = 0.0;
  571.     TurfInfo[areaid][tMin_X] = 0.0;
  572.     TurfInfo[areaid][tMin_Y] = 0.0;
  573.     TurfInfo[areaid][tMin_Z] = 0.0;
  574.     TurfInfo[areaid][tID] = -1;
  575.     AreaAvailability[areaid] = 1;
  576. }
  577.  
  578. forward PlayerToPoint(playerid,Float:radi, Float:px, Float:py, Float:pz); public PlayerToPoint(playerid,Float:radi, Float:px, Float:py, Float:pz)
  579. {
  580.     if(IsPlayerConnected(playerid))
  581.     {
  582.         new Float:x, Float:y, Float:z;
  583.         new Float:ox, Float:oy, Float:oz;
  584.         GetPlayerPos(playerid, ox, oy, oz);
  585.         x = (ox -px);
  586.         y = (oy -py);
  587.         z = (oz -pz);
  588.         if (((x < radi) && (x > -radi)) && ((y < radi) && (y > -radi)) && ((z < radi) && (z > -radi))) return 1;
  589.     }
  590.     return 0;
  591. }
  592.  
  593. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  594. {
  595.     if (newkeys & KEY_SECONDARY_ATTACK)
  596.     {
  597.         for(new p; p < MAX_PICKUPS; p++)
  598.         {
  599.             if (PlayerToPoint(playerid, 3.0, PickupInfo[p][pX], PickupInfo[p][pY], PickupInfo[p][pZ]))
  600.             {
  601.                 SetPlayerPos(playerid, PickupInfo[p][pX], PickupInfo[p][pY], PickupInfo[p][pZ]);
  602.                 break;
  603.             }
  604.         }
  605.     }
  606. }
  607.  
  608. stock HexToInt(string[])    // I did not create this
  609. {
  610.     if (string[0]==0) return 0;
  611.     new i;
  612.     new cur=1;
  613.     new res=0;
  614.     for (i=strlen(string);i>0;i--)
  615.     {
  616.         if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
  617.         cur=cur*16;
  618.     }
  619.     return res;
  620. }
  621.  
  622. stock IntToHex(number)
  623. {
  624.     new m=1;
  625.     new depth=0;
  626.     while (number>=m) {
  627.         m = m*16;
  628.         depth++;
  629.     }
  630.     depth--;
  631.     new str[128];
  632.     for (new i = depth; i >= 0; i--)
  633.     {
  634.         str[i] = ( number & 0x0F) + 0x30; // + (tmp > 9 ? 0x07 : 0x00)
  635.         str[i] += (str[i] > '9') ? 0x07 : 0x00;
  636.         number >>= 4;
  637.     }
  638.     str[8] = '\0';
  639.     return str;
  640. }
  641.  
  642. stock split(const strsrc[], strdest[][], delimiter)     // I did not create this
  643. {
  644.     new i, li;
  645.     new aNum;
  646.     new len;
  647.  
  648.     while(i <= strlen(strsrc)){
  649.         if(strsrc[i]==delimiter || i==strlen(strsrc)){
  650.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  651.             strdest[aNum][len] = 0;
  652.             li = i+1;
  653.             aNum++;
  654.         }
  655.         i++;
  656.     }
  657.     return 1;
  658. }
  659.  
  660. stock AddToLoadFile(areaid, comment[])
  661. {
  662.     if (!fexist("turfinfo.load"))
  663.     {
  664.         new File:newfile = fopen("turfinfo.load", io_write);
  665.         if (newfile)
  666.         {
  667.             fwrite(newfile, " ");
  668.             fclose(newfile);
  669.         }
  670.     }
  671.    
  672.     new File:turffile = fopen("turfinfo.load", io_append);
  673.     if (turffile)
  674.     {
  675.         new string[256];
  676.         format(string, sizeof string, "%f|%f|%f|%f|%f|%f|%d|%s\n", TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMin_Z], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMax_Z], TurfInfo[areaid][tColor], comment);
  677.         printf("[SAVE]%s", string);
  678.         fwrite(turffile, string);
  679.         fclose(turffile);
  680.     }
  681.     return 1;
  682. }
  683.  
  684. stock LoadTurfFile()
  685. {
  686.     if (!fexist("turfinfo.load"))
  687.     {
  688.         new File:newfile = fopen("turfinfo.load", io_write);
  689.         if (newfile)
  690.         {
  691.             fwrite(newfile, " ");
  692.             fclose(newfile);
  693.             return 1;
  694.         }
  695.     }
  696.    
  697.     new File:turffile = fopen("turfinfo.load", io_read);
  698.     if (turffile)
  699.     {
  700.         new str[256], turf[10][32];
  701.         while (fread(turffile, str, 256))
  702.         {
  703.             split(str, turf, '|');
  704.             printf("%s", str);
  705.             new areaid = FindAreaID();
  706.             TurfInfo[areaid][tMin_X] = floatstr(turf[0]);
  707.             TurfInfo[areaid][tMin_Y] = floatstr(turf[1]);
  708.             TurfInfo[areaid][tMin_Z] = floatstr(turf[2]);
  709.             TurfInfo[areaid][tMax_X] = floatstr(turf[3]);
  710.             TurfInfo[areaid][tMax_Y] = floatstr(turf[4]);
  711.             TurfInfo[areaid][tMax_Z] = floatstr(turf[5]);
  712.             TurfInfo[areaid][tColor] = strval(turf[6])+ALPHA;
  713.            
  714.             new string[128];
  715.             format(string, sizeof string, "%f,%f,%f,%f,%f,%f,%s", TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMin_Z], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMax_Z], TurfInfo[areaid][tColor]);
  716.             printf("[LOAD]%s", string);
  717.            
  718.             AreaAvailability[areaid] = 0;
  719.             new pickupid;
  720.             new gangid = GangZoneCreate(TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y]);
  721.             GangZoneShowForAll(gangid, TurfInfo[areaid][tColor]-ALPHA);
  722.             TurfInfo[areaid][tID] = gangid;
  723.  
  724.             pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMin_X], TurfInfo[areaid][tMin_Y], TurfInfo[areaid][tMin_Z]);
  725.             PickupInfo[pickupid][pX] = TurfInfo[areaid][tMin_X];
  726.             PickupInfo[pickupid][pY] = TurfInfo[areaid][tMin_Y];
  727.             PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMin_Z];
  728.             PickupInfo[pickupid][pTurfID] = gangid;
  729.  
  730.             pickupid = CreatePickup(1239, 23, TurfInfo[areaid][tMax_X], TurfInfo[areaid][tMax_Y], TurfInfo[areaid][tMax_Z]);
  731.             PickupInfo[pickupid][pX] = TurfInfo[areaid][tMax_X];
  732.             PickupInfo[pickupid][pY] = TurfInfo[areaid][tMax_Y];
  733.             PickupInfo[pickupid][pZ] = TurfInfo[areaid][tMax_Z];
  734.             PickupInfo[pickupid][pTurfID] = gangid;
  735.  
  736.             new Float:X, Float:Y, Float:Z;
  737.  
  738.             X = TurfInfo[areaid][tMin_X];   // North west
  739.             Y = TurfInfo[areaid][tMax_Y];
  740.             Z = TurfInfo[areaid][tMax_Z];
  741.             pickupid = CreatePickup(1239, 23, X, Y, Z);
  742.             PickupInfo[pickupid][pX] = X;
  743.             PickupInfo[pickupid][pY] = Y;
  744.             PickupInfo[pickupid][pZ] = Z;
  745.             PickupInfo[pickupid][pTurfID] = gangid;
  746.  
  747.             X = TurfInfo[areaid][tMax_X];   // South east
  748.             Y = TurfInfo[areaid][tMin_Y];
  749.             Z = TurfInfo[areaid][tMin_Z];
  750.             pickupid = CreatePickup(1239, 23, X, Y, Z);
  751.             PickupInfo[pickupid][pX] = X;
  752.             PickupInfo[pickupid][pY] = Y;
  753.             PickupInfo[pickupid][pZ] = Z;
  754.             PickupInfo[pickupid][pTurfID] = gangid;
  755.         }
  756.         fclose(turffile);
  757.     }
  758.     return 1;
  759. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement