Advertisement
srdjan

San Andreas Maps 2.0

Sep 5th, 2011
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.18 KB | None | 0 0
  1. // 2.0 San Andreas Map
  2. // Made by Srdjan on 03/09/2011
  3.  
  4.  
  5. /* Changelog:
  6.  
  7.     2.0 San Andreas Maps - in this version you no longer can go "into" the buildings, "through" the ground, etc.
  8.     MapAndreas plug has been added and it works like a charm. Also there is new command, /trackveh and it will track
  9.     the nearest vehicle, distance is measured in 2D. If the vehicle goes underneat the bridge or a building or in
  10.     underground garage, the effect is lost. Also, you can use steering keys to break the effect. Zooming will not
  11.     break the tracking effect.
  12.    
  13.     1.0 San Andreas Maps - initial release; /map on; /map off.
  14.    
  15. */
  16.  
  17. #include <a_samp>
  18. #include <mapandreas>
  19.  
  20. new CheckingMap [MAX_PLAYERS];
  21. new OldPlayerVehID [MAX_PLAYERS];
  22. new OldPlayerSeat [MAX_PLAYERS];
  23. new Float: OldPos [MAX_PLAYERS][3];
  24. new OldInt [MAX_PLAYERS];
  25. new MapTimer [MAX_PLAYERS];
  26. new Float: CameraPos [MAX_PLAYERS][3];
  27. new Float: LookAt [MAX_PLAYERS][3];
  28. new Float: Degrees [MAX_PLAYERS];
  29. new MovePlayerTimer [MAX_PLAYERS];
  30. new Text: MapsTD;
  31. new Text: Coords [MAX_PLAYERS];
  32. new Text: MapsAltimeterPlus;
  33. new Text: MapsAltimeterMinus;
  34. new Text: MapsAltimeterLines;
  35. new Altitude [MAX_PLAYERS];
  36. new Text: MapsMainAltLine [MAX_PLAYERS];
  37. new VehFocus [MAX_PLAYERS];
  38.  
  39. enum Zones
  40. {
  41.     ZoneName [28],
  42.     Float: ZoneCoords[6]
  43. };
  44.  
  45. new Location [][Zones] =
  46. {
  47.     {"Los Santos",                  {44.60, -2892.90, 2997.00, -768.00}},
  48.     {"Las Venturas",                {869.40, 596.30, 2997.00, 2993.80}},
  49.     {"Bone County",                 {-480.50, 596.30, 869.40, 2993.80}},
  50.     {"Tierra Robada",               {-2997.40, 1659.60, -480.50, 2993.80}},
  51.     {"Tierra Robada",               {-1213.90, 596.30, -480.50, 1659.60}},
  52.     {"San Fierro",                  {-2997.40, -1115.50, -1213.90, 1659.60}},
  53.     {"Red County",                  {-1213.90,-768.00, 2997.00, 596.30}},
  54.     {"Flint County",                {-1213.90,-2892.90, 44.60, -768.00}},
  55.     {"Whetstone",                   {-2997.40, -2892.90, -1213.90, -1115.50}}
  56. };
  57.  
  58. forward CheckKeys (playerid);
  59. forward MovePlayer (playerid);
  60. forward FollowVehicle (playerid, vehid);
  61.  
  62. public OnFilterScriptInit ()
  63. {
  64.     MapsTD = TextDrawCreate (10.0, 440.0, "San Andreas Maps, all rights reserved.");
  65.     TextDrawSetShadow (MapsTD, 0);
  66.     TextDrawUseBox (MapsTD, 1);
  67.     TextDrawBoxColor (MapsTD, 0x00000022);
  68.     TextDrawLetterSize (MapsTD, 0.3, 0.7);
  69.     TextDrawTextSize (MapsTD, 300, 400);
  70.    
  71.     MapsAltimeterPlus = TextDrawCreate (10.0, 100.0, "~b~+");
  72.     TextDrawSetShadow (MapsAltimeterPlus, 0);
  73.     TextDrawLetterSize (MapsAltimeterPlus, 0.3, 0.7);
  74.     TextDrawUseBox (MapsAltimeterPlus, 1);
  75.     TextDrawBoxColor (MapsAltimeterPlus, 0xFFFFFFAA);
  76.     TextDrawTextSize (MapsAltimeterPlus, 17.0, 8.0);
  77.    
  78.     MapsAltimeterMinus = TextDrawCreate (11.0, 225.0, "~b~-");
  79.     TextDrawSetShadow (MapsAltimeterMinus, 0);
  80.     TextDrawLetterSize (MapsAltimeterMinus, 0.3, 0.7);
  81.     TextDrawUseBox (MapsAltimeterMinus, 1);
  82.     TextDrawBoxColor (MapsAltimeterMinus, 0xFFFFFFAA);
  83.     TextDrawTextSize (MapsAltimeterMinus, 17.0, 8.0);
  84.    
  85.     MapsAltimeterLines = TextDrawCreate (10.7, 109.0, "-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-~n~-");
  86.     TextDrawSetShadow (MapsAltimeterLines, 0);
  87.     TextDrawLetterSize (MapsAltimeterLines, 0.4, 0.7);
  88.    
  89.     for (new i = 0; i < MAX_PLAYERS; i++)
  90.     {
  91.         Coords [i] = TextDrawCreate (400.0, 430.0, "  Location: ~n~Coordinates:");
  92.         TextDrawSetShadow (Coords [i], 0);
  93.         TextDrawLetterSize (Coords [i], 0.3, 0.7);
  94.  
  95.         MapsMainAltLine [i] = TextDrawCreate (9.7, 102.8, " ");
  96.         TextDrawLetterSize (MapsMainAltLine [i], 0.6, 0.7);
  97.        
  98.         Degrees [i] = 0.0;
  99.         CheckingMap [i] = 0;
  100.         LookAt [i][0] = 0.0;
  101.         LookAt [i][1] = 0.0;
  102.         LookAt [i][2] = 0.0;
  103.     }
  104.  
  105.     MapAndreas_Init (MAP_ANDREAS_MODE_FULL);
  106.    
  107.     printf ("\nSan Andreas Map by Srdjan loaded.\n");
  108.     return 1;
  109. }
  110.  
  111. public OnPlayerCommandText (playerid, cmdtext[])
  112. {
  113.     if (!strcmp (cmdtext, "/map on", false))
  114.     {
  115.         if (CheckingMap [playerid]) return 1;
  116.         CheckingMap [playerid] = 1;
  117.         if (IsPlayerInAnyVehicle (playerid))
  118.         {
  119.             OldPlayerVehID [playerid] = GetPlayerVehicleID (playerid);
  120.             OldPlayerSeat [playerid] = GetPlayerVehicleSeat (playerid);
  121.         }
  122.  
  123.         OldInt [playerid] = GetPlayerInterior (playerid);
  124.         GetPlayerPos (playerid, OldPos [playerid][0], OldPos [playerid][1], OldPos [playerid][2]);
  125.         MapTimer [playerid] = SetTimerEx ("CheckKeys", 80, 1, "d", playerid);
  126.  
  127.         CheckMap (playerid);
  128.         return 1;
  129.     }
  130.    
  131.     if (!strcmp (cmdtext, "/map off", false))
  132.     {
  133.         if (!CheckingMap [playerid]) return 1;
  134.         CheckingMap [playerid] = 0;
  135.         TogglePlayerControllable (playerid, 1);
  136.         SetPlayerPos (playerid, OldPos [playerid][0], OldPos [playerid][1], OldPos [playerid][2]);
  137.         SetPlayerInterior (playerid, OldInt [playerid]);
  138.         SetCameraBehindPlayer (playerid);
  139.         KillTimer (MapTimer [playerid]);
  140.         KillTimer (MovePlayerTimer [playerid]);
  141.         Degrees [playerid] = 0.0;
  142.         TextDrawHideForPlayer (playerid, MapsTD);
  143.         TextDrawHideForPlayer (playerid, Coords [playerid]);
  144.         TextDrawHideForPlayer (playerid, MapsAltimeterPlus);
  145.         TextDrawHideForPlayer (playerid, MapsAltimeterMinus);
  146.         TextDrawHideForPlayer (playerid, MapsAltimeterLines);
  147.         TextDrawHideForPlayer (playerid, MapsMainAltLine [playerid]);
  148.         if (OldPlayerVehID [playerid] > 0)
  149.         {
  150.             PutPlayerInVehicle (playerid, OldPlayerVehID [playerid], OldPlayerSeat [playerid]);
  151.         }
  152.         return 1;
  153.     }
  154.    
  155.     if (!strcmp (cmdtext, "/trackveh", false))
  156.     {
  157.         if (!CheckingMap [playerid]) return 1;
  158.         if (VehFocus [playerid] > 0) return 1;
  159.         new Float: distance = 250.0, ID = -1;
  160.         for (new vehid = 1; vehid < MAX_VEHICLES; vehid++)
  161.         {
  162.             new Float: x, Float: y, Float: z;
  163.             if (GetVehiclePos (vehid, x, y, z))
  164.             {
  165.                 x -= CameraPos [playerid][0];
  166.                 y -= CameraPos [playerid][1];
  167.                 new Float: dist = floatsqroot ((floatpower (x, 2)) + (floatpower (y, 2)));
  168.                 if (distance > dist)
  169.                 {
  170.                     distance = dist;
  171.                     ID = vehid;
  172.                 }
  173.             }
  174.         }
  175.         if (ID > 0)
  176.         {
  177.             VehFocus [playerid] = SetTimerEx ("FollowVehicle", 100, 1, "dd", playerid, ID);
  178.         }
  179.         return 1;
  180.     }
  181.     return 0;
  182. }
  183.  
  184. public CheckKeys (playerid)
  185. {
  186.     new keys, updown, leftright, boost, Float: maxZ;
  187.     GetPlayerKeys (playerid, keys, updown, leftright);
  188.     if (!CheckingMap [playerid]) return 1;
  189.     if (updown == KEY_UP)
  190.     {
  191.         if (keys == KEY_WALK)
  192.         {
  193.             MapAndreas_FindZ_For2DCoord (CameraPos [playerid][0], CameraPos [playerid][1], maxZ);
  194.             if (CameraPos [playerid][2] - 15 >= maxZ)
  195.             {
  196.                 CameraPos [playerid][2] = CameraPos [playerid][2] - 10.0;
  197.                 Altitude [playerid] --;
  198.             }
  199.         }
  200.         else
  201.         {
  202.             if (CameraPos [playerid][2] < 75.0)
  203.             {
  204.                 boost = 2;
  205.             }
  206.             else if (CameraPos [playerid][2] < 150.0)
  207.             {
  208.                 boost = 5;
  209.             }
  210.             else if (CameraPos [playerid][2] < 300.0)
  211.             {
  212.                 boost = 10;
  213.             }
  214.             else if (CameraPos [playerid][2] >= 300.0)
  215.             {
  216.                 boost = 30;
  217.             }
  218.            
  219.             MapAndreas_FindZ_For2DCoord (CameraPos [playerid][0], CameraPos [playerid][1], maxZ);
  220.             while (maxZ > CameraPos [playerid][2])
  221.             {
  222.                 CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  223.                 Altitude [playerid]++;
  224.             }
  225.             if (VehFocus [playerid] > -1)
  226.             {
  227.                 KillTimer (VehFocus [playerid]);
  228.                 VehFocus [playerid] = -1;
  229.             }
  230.         }
  231.  
  232.         CameraPos [playerid][0] = CameraPos [playerid][0] + (boost * floatsin (-Degrees [playerid], degrees));
  233.         CameraPos [playerid][1] = CameraPos [playerid][1] + (boost * floatcos (-Degrees [playerid], degrees));
  234.  
  235.         MovePlayerCamera (playerid);
  236.     }
  237.     else if (updown == KEY_DOWN)
  238.     {
  239.         if (keys == KEY_WALK)
  240.         {
  241.             if (CameraPos [playerid][2] < 650.0)
  242.             {
  243.                 CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  244.                 Altitude [playerid] ++;
  245.             }
  246.         }
  247.         else
  248.         {
  249.             if (CameraPos [playerid][2] < 75.0)
  250.             {
  251.                 boost = 2;
  252.             }
  253.             else if (CameraPos [playerid][2] < 150.0)
  254.             {
  255.                 boost = 5;
  256.             }
  257.             else if (CameraPos [playerid][2] < 300.0)
  258.             {
  259.                 boost = 10;
  260.             }
  261.             else if (CameraPos [playerid][2] >= 300.0)
  262.             {
  263.                 boost = 30;
  264.             }
  265.            
  266.             MapAndreas_FindZ_For2DCoord (CameraPos [playerid][0], CameraPos [playerid][1], maxZ);
  267.             while (maxZ > CameraPos [playerid][2])
  268.             {
  269.                 CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  270.                 Altitude [playerid]++;
  271.             }
  272.             if (VehFocus [playerid] > -1)
  273.             {
  274.                 KillTimer (VehFocus [playerid]);
  275.                 VehFocus [playerid] = -1;
  276.             }
  277.         }
  278.        
  279.         CameraPos [playerid][0] = CameraPos [playerid][0] - (boost * floatsin (-Degrees [playerid], degrees));
  280.         CameraPos [playerid][1] = CameraPos [playerid][1] - (boost * floatcos (-Degrees [playerid], degrees));
  281.  
  282.         MovePlayerCamera (playerid);
  283.     }
  284.  
  285.     if (leftright == KEY_LEFT)
  286.     {
  287.         if (keys == KEY_WALK)
  288.         {
  289.             Degrees [playerid] = Degrees [playerid] + 5.0;
  290.             if (Degrees [playerid] == 360)
  291.             {
  292.                 Degrees [playerid] = 0;
  293.             }
  294.         }
  295.         else
  296.         {
  297.             if (CameraPos [playerid][2] < 75.0)
  298.             {
  299.                 boost = 2;
  300.             }
  301.             else if (CameraPos [playerid][2] < 150.0)
  302.             {
  303.                 boost = 5;
  304.             }
  305.             else if (CameraPos [playerid][2] < 300.0)
  306.             {
  307.                 boost = 10;
  308.             }
  309.             else if (CameraPos [playerid][2] >= 300.0)
  310.             {
  311.                 boost = 30;
  312.             }
  313.    
  314.             MapAndreas_FindZ_For2DCoord (CameraPos [playerid][0], CameraPos [playerid][1], maxZ);
  315.             while (maxZ > CameraPos [playerid][2])
  316.             {
  317.                 CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  318.                 Altitude [playerid]++;
  319.             }
  320.             if (VehFocus [playerid] > -1)
  321.             {
  322.                 KillTimer (VehFocus [playerid]);
  323.                 VehFocus [playerid] = -1;
  324.             }
  325.         }
  326.  
  327.         CameraPos [playerid][0] = CameraPos [playerid][0] + (boost * floatsin (-Degrees [playerid] - 90.0, degrees));
  328.         CameraPos [playerid][1] = CameraPos [playerid][1] + (boost * floatcos (-Degrees [playerid] - 90.0, degrees));
  329.  
  330.         MovePlayerCamera (playerid);
  331.     }
  332.     else if (leftright == KEY_RIGHT)
  333.     {
  334.         if (keys == KEY_WALK)
  335.         {
  336.             Degrees [playerid] = Degrees [playerid] - 5.0;
  337.             if (Degrees [playerid] < 0)
  338.             {
  339.                 Degrees [playerid] = 355;
  340.             }
  341.         }
  342.         else
  343.         {
  344.             if (CameraPos [playerid][2] < 75.0)
  345.             {
  346.                 boost = 2;
  347.             }
  348.             else if (CameraPos [playerid][2] < 150.0)
  349.             {
  350.                 boost = 5;
  351.             }
  352.             else if (CameraPos [playerid][2] < 300.0)
  353.             {
  354.                 boost = 10;
  355.             }
  356.             else if (CameraPos [playerid][2] >= 300.0)
  357.             {
  358.                 boost = 30;
  359.             }
  360.        
  361.             MapAndreas_FindZ_For2DCoord (CameraPos [playerid][0], CameraPos [playerid][1], maxZ);
  362.             while (maxZ > CameraPos [playerid][2])
  363.             {
  364.                 CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  365.                 Altitude [playerid]++;
  366.             }
  367.             if (VehFocus [playerid] > -1)
  368.             {
  369.                 KillTimer (VehFocus [playerid]);
  370.                 VehFocus [playerid] = -1;
  371.             }
  372.         }
  373.        
  374.         CameraPos [playerid][0] = CameraPos [playerid][0] + (boost * floatsin (-Degrees [playerid] + 90.0, degrees));
  375.         CameraPos [playerid][1] = CameraPos [playerid][1] + (boost * floatcos (-Degrees [playerid] + 90.0, degrees));
  376.  
  377.         MovePlayerCamera (playerid);
  378.     }
  379.    
  380.     MovePlayerCamera (playerid);
  381.    
  382.     return 1;
  383. }
  384.  
  385. MovePlayerCamera (playerid)
  386. {
  387.     new str[128];
  388.     format (str, sizeof (str), "    Location: %s~n~Coordinates: x = %.2f   y = %.2f", LocationName (CameraPos [playerid][0], CameraPos [playerid][1]), CameraPos [playerid][0], CameraPos [playerid][1]);
  389.     TextDrawSetString (Coords [playerid], str);
  390.     TextDrawShowForPlayer (playerid, Coords [playerid]);
  391.     TextDrawSetString (MapsMainAltLine [playerid], AltimeterLine (Altitude [playerid]));
  392.     TextDrawShowForPlayer (playerid, MapsMainAltLine [playerid]);
  393.     SetPlayerCameraPos (playerid, CameraPos [playerid][0], CameraPos [playerid][1], CameraPos [playerid][2]);
  394.     SetPlayerCameraLookAt (playerid, CameraPos [playerid][0] + (floatsin (-Degrees [playerid], degrees)), CameraPos [playerid][1] + (floatcos (-Degrees [playerid], degrees)), 0.0);
  395. }
  396.  
  397. AltimeterLine (Alt)
  398. {
  399.     new str[64], k;
  400.    
  401.     if (Alt > 43)
  402.     {
  403.         Alt = Alt - 5;
  404.         k++;
  405.     }
  406.     while (Alt > 23)
  407.     {
  408.         Alt = Alt - 4;
  409.         k++;
  410.     }
  411.     while (Alt > 2)
  412.     {
  413.         Alt = Alt - 3;
  414.         k++;
  415.     }
  416.  
  417.     for (new i = 0; i <= k; i++)
  418.     {
  419.         strcat (str, "~n~", sizeof (str));
  420.     }
  421.     strcat (str, "~r~-", sizeof (str));
  422.     return str;
  423. }
  424.  
  425. CheckMap (playerid)
  426. {
  427.     TextDrawShowForPlayer (playerid, MapsTD);
  428.     TextDrawShowForPlayer (playerid, Coords [playerid]);
  429.     TextDrawShowForPlayer (playerid, MapsAltimeterPlus);
  430.     TextDrawShowForPlayer (playerid, MapsAltimeterMinus);
  431.     TextDrawShowForPlayer (playerid, MapsAltimeterLines);
  432.     TextDrawShowForPlayer (playerid, MapsMainAltLine [playerid]);
  433.     Altitude [playerid] = 8;
  434.     SetPlayerInterior (playerid, 0);
  435.     CameraPos [playerid][0] = 0.0;
  436.     CameraPos [playerid][1] = 0.0;
  437.     CameraPos [playerid][2] = 100.0;
  438.     SetPlayerPos (playerid, 0.0, 0.0, -10.0);
  439.     SetPlayerCameraPos (playerid, 0.0, 0.0, 100.0);
  440.     SetPlayerCameraLookAt (playerid, 0.0, 0.1, 0.0);
  441.     TogglePlayerControllable (playerid, 0);
  442.     MovePlayerTimer [playerid] = SetTimerEx ("MovePlayer", 1000, 1, "d", playerid);
  443. }
  444.  
  445. public MovePlayer (playerid)
  446. {
  447.     SetPlayerPos (playerid, CameraPos [playerid][0], CameraPos [playerid][1], -50.0);
  448.     return 1;
  449. }
  450.  
  451. LocationName (Float: x, Float: y)
  452. {
  453.     new str[28];
  454.     for (new i = 0; i != sizeof (Location); i++)
  455.     {
  456.         if (x >= Location [i][ZoneCoords][0] && x <= Location [i][ZoneCoords][2] && y >= Location [i][ZoneCoords][1] && y <= Location [i][ZoneCoords][3])
  457.         {
  458.             format (str, sizeof (str), "%s", Location [i][ZoneName]);
  459.         }
  460.     }
  461.     return str;
  462. }
  463.  
  464. public OnPlayerDisconnect (playerid, reason)
  465. {
  466.     OnPlayerCommandText (playerid, "/map off");
  467.     return 1;
  468. }
  469.  
  470. public FollowVehicle (playerid, vehid)
  471. {
  472.     new Float: x, Float: y, Float: z;
  473.     GetVehiclePos (vehid, x, y, z);
  474.     new Float: maxZ;
  475.     MapAndreas_FindZ_For2DCoord (x, y, maxZ);
  476.     if (maxZ > z)
  477.     {
  478.         KillTimer (VehFocus [playerid]);
  479.     }
  480.     else
  481.     {
  482.         CameraPos [playerid][0] = x;
  483.         CameraPos [playerid][1] = y;
  484.  
  485.     }
  486.     while (maxZ > CameraPos [playerid][2])
  487.     {
  488.         CameraPos [playerid][2] = CameraPos [playerid][2] + 10.0;
  489.         Altitude [playerid]++;
  490.     }
  491.    
  492.     MovePlayerCamera (playerid);
  493.     return 1;
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement