Advertisement
Less_Arkwood

Sistema de carreras

Jan 4th, 2024 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 16.49 KB | Gaming | 0 0
  1. #include <open.mp>
  2. #include <zcmd>
  3.  
  4. #define LOBBY_PLAYER   0
  5. #define JOINED_PLAYER  1
  6. #define RESTAURED      0
  7.  
  8. forward UpdateCounterCheckpoint(playerid);
  9.  
  10. // ALMACÉN DE DATOS DE UN JUGADOR
  11. // =========================================================================================
  12. enum playerData {
  13.     PlayerText:counterCheckpoints,
  14.     playerName[MAX_PLAYER_NAME],
  15.     vehicleRacePlayer,    
  16.     checkpointsPassed,
  17.     joiningRace
  18. };
  19.  
  20. new playerInfo[MAX_PLAYERS][playerData];
  21. // =========================================================================================
  22.  
  23. // ALMACÉN DE COORDENADAS DE UNA CARRERA
  24. // =========================================================================================
  25. enum pointsRace {  
  26.     Float:coordX,
  27.     Float:coordY,
  28.     Float:coordZ,
  29.     Float:angle
  30. };
  31.  
  32. new checkpointsRace[][pointsRace] = {
  33.     {138.3773, 1944.0968, 18.9926, 359.8733}, // POSICIÓN INICIAL: coordX, coordY, coordZ, angle
  34.     {133.2255, 2052.2720, 16.4774},
  35.     {-12.1056, 2067.4399, 17.1517},
  36.     {-17.6648, 2006.1898, 16.8847},
  37.     {-60.6377, 1971.8846, 16.8866},
  38.     {-66.3311, 1724.0090, 16.8871},
  39.     {-28.5127, 1652.5846, 16.8825},
  40.     {263.8007, 1647.2498, 16.8831},
  41.     {315.9866, 1680.4749, 16.8836},
  42.     {318.8882, 1745.9812, 16.8884},
  43.     {365.6351, 1784.9834, 16.8830},
  44.     {370.0326, 1851.8794, 16.8843},
  45.     {421.7878, 1894.7731, 16.8864},
  46.     {423.9970, 2078.3047, 16.8850},
  47.     {376.8186, 2130.9014, 16.8826},
  48.     {-3.3853, 2119.1199, 16.8858},
  49.     {-12.3878, 2067.9426, 17.1481},
  50.     {-167.2211, 2042.6006, 15.3767},
  51.     {-107.8565, 1525.6746, 15.5774},
  52.     {-65.6314, 1326.2266, 11.0086},
  53.     {-73.2364, 1259.6481, 11.7067},
  54.     {-119.5829, 1254.8035, 17.6710},
  55.     {-110.5325, 1141.4126, 19.3998},
  56.     {-115.0757, 1086.3253, 19.3906},
  57.     {-109.3413, 951.7379, 20.2825},
  58.     {-26.4002, 947.0177, 18.7739},
  59.     {-23.1836, 924.7546, 20.5279},
  60.     {7.3780, 923.2450, 21.6015},
  61.     {8.3403, 983.5715, 19.1726},
  62.     {36.8004, 984.3917, 18.2175},
  63.     {34.7194, 1040.9800, 16.9427},
  64.     {-15.7136, 1045.7145, 19.2519},
  65.     {-15.4169, 1099.2161, 19.2566},
  66.     {-65.8205, 1098.3221, 19.2500},
  67.     {-64.2512, 1198.4069, 19.2242},
  68.     {-114.9314, 1199.3641, 19.2537},
  69.     {-120.0876, 1254.1786, 17.7139},
  70.     {-241.5951, 1238.8800, 23.2560},
  71.     {-398.2947, 1327.0133, 26.2985},
  72.     {-448.5366, 1486.2089, 34.2863},
  73.     {-428.6691, 1657.1395, 36.0266},
  74.     {-395.3008, 1756.5182, 43.1233},
  75.     {-382.0470, 1831.8517, 50.5951},
  76.     {-409.7466, 1917.4742, 57.4486},
  77.     {-442.0951, 1760.4911, 71.6906},
  78.     {-474.4391, 1951.5120, 84.9162},
  79.     {-384.3170, 2076.6882, 60.5730},
  80.     {-450.3127, 2033.6598, 60.3167},
  81.     {-471.3879, 2068.6365, 60.4068},
  82.     {-435.2260, 2122.1008, 46.3778},
  83.     {-426.7271, 2141.0144, 44.8369},
  84.     {-372.8344, 2165.6743, 41.8508},
  85.     {-392.3487, 2289.1582, 39.0986},
  86.     {-369.5579, 2349.9182, 29.3900},
  87.     {-378.5913, 2415.9641, 41.0825},
  88.     {-400.3170, 2458.0981, 42.1515},
  89.     {-342.6212, 2511.1987, 35.4335},
  90.     {-384.1227, 2573.3450, 40.4794},
  91.     {-421.4793, 2718.1890, 61.9085},
  92.     {-547.9167, 2716.5474, 65.3866},
  93.     {-623.2031, 2633.4917, 86.5642},
  94.     {-512.6873, 2427.9199, 56.6490},
  95.     {-403.0269, 2460.4395, 42.5379},
  96.     {-379.4317, 2419.8667, 41.4199},
  97.     {-382.9261, 2380.1145, 34.2511},
  98.     {-368.7681, 2344.0706, 29.7888},
  99.     {-394.6370, 2285.8176, 39.6389},
  100.     {-479.3115, 2302.0613, 61.4729},
  101.     {-590.0309, 2379.3293, 81.7542},
  102.     {-718.9361, 2455.6206, 123.1256},
  103.     {-695.4927, 2406.7642, 130.5795},
  104.     {-713.0059, 2387.9543, 128.1194},
  105.     {-743.9400, 2344.2690, 124.3624},
  106.     {-822.9233, 2356.9604, 120.5508},
  107.     {-794.1212, 2503.3750, 98.4590},
  108.     {-773.2552, 2558.5076, 85.7740},
  109.     {-735.7543, 2520.4641, 76.6193},
  110.     {-707.2684, 2522.9441, 74.4357},
  111.     {-586.7090, 2431.8799, 68.8785},
  112.     {-459.6766, 2446.3875, 48.2302},
  113.     {-402.2812, 2457.9377, 42.4187},
  114.     {-379.1075, 2419.0222, 41.3582},
  115.     {-384.4041, 2381.6633, 34.6374},
  116.     {-369.3444, 2348.8757, 29.4456},
  117.     {-392.5277, 2286.0078, 39.5470},
  118.     {-374.6805, 2162.8918, 41.9603},
  119.     {-430.0211, 2136.7861, 45.1605},
  120.     {-470.7299, 2073.2080, 59.9557},
  121.     {-453.5273, 2033.0168, 60.2652},
  122.     {-508.7905, 1988.9325, 59.8447},
  123.     {-707.8640, 2062.3945, 60.0413},
  124.     {-882.6657, 1983.7200, 59.8609},
  125.     {-858.5137, 1814.5343, 59.8391},
  126.     {-919.1517, 1791.9160, 59.8351},
  127.     {-1010.9431, 1854.6733, 62.1255},
  128.     {-1171.2224, 1796.7264, 39.7713},
  129.     {-1030.1288, 1727.2352, 30.7332},
  130.     {-923.9425, 1718.1063, 27.4339},
  131.     {-846.3175, 1582.9999, 25.4597},
  132.     {-842.1508, 1415.3525, 13.2692},
  133.     {-728.6545, 1236.8206, 13.0633},
  134.     {-626.4410, 1211.2676, 11.2483},
  135.     {-576.9376, 1116.4608, 10.5597},
  136.     {-626.5583, 1066.9999, 11.6603},
  137.     {-708.9901, 1032.6641, 11.7937},
  138.     {-721.4108, 942.1447, 11.7928},
  139.     {-736.4824, 767.0458, 18.0900},
  140.     {-760.4346, 720.6406, 17.8275},
  141.     {-634.5916, 646.0507, 16.2948},
  142.     {-356.6280, 551.8482, 16.0665},
  143.     {-243.5455, 537.0562, 13.4849},
  144.     {-125.8687, 534.7529, 6.8293},
  145.     {-139.5634, 477.4754, 11.7536},
  146.     {-204.4163, 234.0669, 11.7363},
  147.     {-281.9970, 40.7338, 0.7381},
  148.     {-308.2919, -147.0981, 0.7380},
  149.     {-186.9246, -337.5111, 0.7381},
  150.     {-71.2279, -434.1797, 0.7381},
  151.     {34.8012, -518.2227, 9.6671},
  152.     {33.7570, -641.6093, 2.6699},
  153.     {-33.4605, -804.1238, 10.3777},
  154.     {-92.3932, -925.0240, 18.6895},
  155.     {-124.5911, -985.3041, 25.4328},
  156.     {-88.3483, -1037.8085, 23.3246},
  157.     {-86.0268, -1102.6621, 3.0998},
  158.     {-141.4267, -1251.2079, 2.3563},
  159.     {-135.3133, -1447.3495, 2.3553},
  160.     {-25.2352, -1516.0520, 1.4801},
  161.     {-47.2224, -1587.7247, 2.7378},
  162.     {-157.9227, -1628.8599, 2.9364},
  163.     {-246.3678, -1700.3357, 2.1716},
  164.     {-270.5235, -1827.8643, 17.5008},
  165.     {-277.2839, -1907.0021, 26.6756},
  166.     {-330.4329, -1914.9656, 12.0752},
  167.     {-436.5369, -1917.5955, 6.0335},
  168.     {-461.9475, -2018.5398, 45.4415},
  169.     {-581.1581, -2029.6005, 46.1506},
  170.     {-675.7419, -1990.7527, 24.3672},
  171.     {-671.8813, -1906.9576, 7.9833},
  172.     {-686.4479, -1861.8348, 13.4398},
  173.     {-805.8774, -1898.2999, 9.8988},
  174.     {-830.0934, -2032.7970, 23.5928},
  175.     {-809.4908, -2168.4463, 21.8762},
  176.     {-945.7052, -2193.8604, 37.1393},
  177.     {-960.4169, -2294.1165, 54.9649},
  178.     {-939.3588, -2350.1143, 58.6873},
  179.     {-862.9333, -2412.3557, 55.7973},
  180.     {-778.3489, -2457.1165, 73.3964},
  181.     {-727.4724, -2371.8508, 47.7266},
  182.     {-660.3845, -2359.1477, 35.6966},
  183.     {-580.1542, -2369.5225, 27.5983},
  184.     {-622.2806, -2431.5032, 30.6902},
  185.     {-669.7758, -2501.8806, 39.5234},
  186.     {-717.6393, -2623.2239, 76.4584},
  187.     {-765.8481, -2682.2200, 83.9212},
  188.     {-828.4394, -2683.4229, 94.3931},
  189.     {-921.9073, -2666.5056, 84.6733},
  190.     {-1031.0133, -2682.2600, 49.0513},
  191.     {-1116.7500, -2656.7500, 17.1898},
  192.     {-1172.2695, -2639.8604, 11.4176},
  193.     {-1229.8696, -2638.7432, 8.8095},
  194.     {-1302.2876, -2635.1135, 10.7334},
  195.     {-1377.6473, -2630.8311, 29.7285},
  196.     {-1459.7495, -2633.6128, 39.6752},
  197.     {-1544.9243, -2633.9429, 52.6062},
  198.     {-1684.3109, -2600.3438, 34.2736},
  199.     {-1768.0189, -2501.7507, 8.2690},
  200.     {-1841.4791, -2454.7561, 28.2002},
  201.     {-1894.6873, -2422.9575, 32.1016},
  202.     {-1942.3892, -2456.8806, 30.4177},
  203.     {-2020.9010, -2510.9089, 32.2357},
  204.     {-1958.6921, -2556.8494, 38.3815},
  205.     {-1874.2275, -2532.2915, 44.3478},
  206.     {-1756.2885, -2590.2480, 50.9604},
  207.     {-1557.7035, -2778.2979, 47.3722},
  208.     {-1391.2428, -2869.9299, 50.4393},
  209.     {-1194.2031, -2855.3875, 67.5749},
  210.     {-963.3413, -2850.5776, 67.3880},
  211.     {-756.5721, -2766.4011, 74.3386},
  212.     {-598.5874, -2747.7532, 66.9425},
  213.     {-305.2773, -2805.2854, 56.0411},
  214.     {-163.7755, -2824.8335, 40.6429},
  215.     {-52.5434, -2755.5083, 40.5496},
  216.     {-57.8492, -2555.1086, 41.6194},
  217.     {-167.9094, -2416.4763, 35.5465},
  218.     {-298.6412, -2258.5505, 29.3591},
  219.     {-350.1202, -2100.5334, 27.9847},
  220.     {-371.6060, -1968.3761, 27.8126},
  221.     {-315.6837, -1758.8584, 15.6683},
  222.     {-284.3117, -1643.4879, 15.1196},
  223.     {-95.2045, -1406.3168, 12.0437},
  224.     {-56.5715, -1322.8999, 8.7075},
  225.     {-101.0582, -1292.7904, 4.1182},
  226.     {-145.4855, -1358.6056, 1.9810},
  227.     {-110.1547, -1482.0712, 2.3553},
  228.     {-23.7832, -1516.8418, 1.4796},
  229.     {-79.7605, -1619.3715, 3.0648},
  230.     {-201.4006, -1636.3112, 2.7463},
  231.     {-253.7977, -1736.6241, 3.5854},
  232.     {-279.1429, -1905.9796, 26.6127}
  233. };
  234. // =========================================================================================
  235.  
  236.  
  237. // Cuando el jugador se conecta al servidor, se CARGA un textdraw que se establecerá en la esquina inferior derecha de la pantalla que es un contador de checkpoints. Únicamente es cargado, más no es visible.
  238. // ========================================================================================
  239. public OnPlayerConnect(playerid)
  240. {
  241.     new td_counter[15];
  242.     format(td_counter, sizeof(td_counter), "%i/%i", playerInfo[playerid][checkpointsPassed], sizeof(checkpointsRace) - 1);
  243.     playerInfo[playerid][counterCheckpoints] = CreatePlayerTextDraw(playerid, 612.000000, 411.000000, td_counter);
  244.     PlayerTextDrawFont(playerid, playerInfo[playerid][counterCheckpoints], t_TEXT_DRAW_FONT:1);
  245.     PlayerTextDrawLetterSize(playerid, playerInfo[playerid][counterCheckpoints], 0.504166, 1.950000);
  246.     PlayerTextDrawTextSize(playerid, playerInfo[playerid][counterCheckpoints], 400.000000, 17.000000);
  247.     PlayerTextDrawSetOutline(playerid, playerInfo[playerid][counterCheckpoints], 1);
  248.     PlayerTextDrawSetShadow(playerid, playerInfo[playerid][counterCheckpoints], 0);
  249.     PlayerTextDrawAlignment(playerid, playerInfo[playerid][counterCheckpoints], t_TEXT_DRAW_ALIGN:3);
  250.     PlayerTextDrawColour(playerid, playerInfo[playerid][counterCheckpoints], -1);
  251.     PlayerTextDrawBackgroundColour(playerid, playerInfo[playerid][counterCheckpoints], 255);
  252.     PlayerTextDrawBoxColour(playerid, playerInfo[playerid][counterCheckpoints], 50);
  253.     PlayerTextDrawUseBox(playerid, playerInfo[playerid][counterCheckpoints], false);
  254.     PlayerTextDrawSetProportional(playerid, playerInfo[playerid][counterCheckpoints], true);
  255.     PlayerTextDrawSetSelectable(playerid, playerInfo[playerid][counterCheckpoints], false);
  256.  
  257.     return 1;
  258. }
  259. // ========================================================================================
  260.  
  261. // Aquí, comienzo a incorporar operaciones de suma y resta al contador de checkpoints y otras variables por una razón específica. El array que contiene las coordenadas de los checkpoints de la carrera (checkpointsRace) incluye unas coordenadas que no se utilizan como checkpoint: específicamente, la primera de todas. Esta línea contiene 4 valores (coordX, coordY, coordZ, angle), a diferencia de las otras que tienen solo 3. Estas coordenadas representan el punto donde el jugador aparecerá al inicio de la carrera. Un ejemplo de lo que estoy describiendo se encuentra en la parte de: "checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX]" ubicada en la línea 292. En esta línea, los parámetros de coordenadas requeridos por la función "SetPlayerRaceCheckpoint" dependen de la variable del jugador "checkpointsPassed", que inicialmente está en 0. Sin embargo, se le suma "+ 1" para indicar que las coordenadas del primer checkpoint que se tendrán en cuenta son las de la segunda línea del array "checkpointsRace", es decir, la primera línea que contiene únicamente 3 valores.
  262.  
  263. CMD:unir(playerid)
  264. {
  265.     if(playerInfo[playerid][joiningRace] == JOINED_PLAYER)
  266.     {
  267.         SendClientMessage(playerid, -1, "ERROR: Actualmente estás dentro de una carrera.");
  268.         return 1;
  269.     }
  270.    
  271.     PlayerTextDrawShow(playerid, playerInfo[playerid][counterCheckpoints]); // Ésta es la función que hace visible el textdraw cargado en el callback de "OnPlayerConnect".
  272.     GetPlayerName(playerid, playerInfo[playerid][playerName], MAX_PLAYER_NAME);
  273.    
  274.     playerInfo[playerid][vehicleRacePlayer] =
  275.         CreateVehicle(562,
  276.         checkpointsRace[0][coordX],
  277.         checkpointsRace[0][coordY],
  278.         checkpointsRace[0][coordZ],
  279.         checkpointsRace[0][angle],
  280.         1, 0, 0, false);
  281.  
  282.     SetVehicleVirtualWorld(playerInfo[playerid][vehicleRacePlayer], 1);
  283.     SetPlayerVirtualWorld(playerid, 1);
  284.     PutPlayerInVehicle(playerid, playerInfo[playerid][vehicleRacePlayer], 0);
  285.     TogglePlayerGhostMode(playerid, true);
  286.     DisableRemoteVehicleCollisions(playerid, true);
  287.     SetCameraBehindPlayer(playerid);
  288.    
  289.     playerInfo[playerid][joiningRace] = JOINED_PLAYER;
  290.  
  291.     SetPlayerRaceCheckpoint(playerid, t_CP_TYPE:0,
  292.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
  293.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
  294.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
  295.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordX],
  296.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordY],
  297.     checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordZ],
  298.     5);
  299.    
  300.     return 1;
  301. }
  302.  
  303. public OnPlayerEnterRaceCheckpoint(playerid)
  304. {
  305.     playerInfo[playerid][checkpointsPassed]++;
  306.     DisablePlayerRaceCheckpoint(playerid);
  307.     UpdateCounterCheckpoint(playerid);
  308.    
  309.     /* En esta sección, he implementado dos condicionales para manejar dos tipos de checkpoints. El array "checkpointsRace" consta de un total de 200 líneas. Sin embargo, es importante señalar que una de estas líneas no corresponde a un checkpoint, sino a la posición donde el jugador será spawneado, como mencioné anteriormente.
  310.  
  311.     Por lo tanto, de las 200 líneas originales, restamos 1 para obtener 199 checkpoints. A su vez, el checkpoint 199 se considera la meta, lo que significa que en realidad tenemos 198 checkpoints de tipo "normal" (aquellos con un triángulo de dirección en su interior, son manejados mediante "t_CP_TYPE:0").
  312.  
  313.     La siguiente línea utiliza "sizeof(checkpointsRace) - 2" para ajustar la condición, asegurando que cualquier checkpoint menor a 198 spawneará un checkpoint de tipo normal. Esta lógica refleja la cantidad real de checkpoints utilizados en el juego, excluyendo el punto de spawn y la meta.
  314.  
  315.     En resumen, el tamaño del array "checkpointsRace" se reduce en 2 para tener en cuenta la línea de spawn y el checkpoint de la meta. */
  316.     if(playerInfo[playerid][checkpointsPassed] < sizeof(checkpointsRace) - 2)
  317.     {
  318.         SetPlayerRaceCheckpoint(playerid,
  319.         t_CP_TYPE:0,
  320.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
  321.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
  322.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
  323.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordX],
  324.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordY],
  325.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordZ],
  326.         5);
  327.         return 1;
  328.     }
  329.  
  330.     // En esta otra condición, se espera que cuando alcances el checkpoint 198, es decir, cuando hayas pasado o tomado 198 checkpoints (almacenados en la variable "checkpointsPassed"), se genere un checkpoint de tipo meta (t_CP_TYPE:1).
  331.     if(playerInfo[playerid][checkpointsPassed] == sizeof(checkpointsRace) - 2)
  332.     {
  333.         SetPlayerRaceCheckpoint(playerid,
  334.         t_CP_TYPE:1,
  335.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
  336.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
  337.         checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
  338.         0,
  339.         0,
  340.         0,
  341.         5);
  342.         return 1;
  343.     }
  344.  
  345.     GivePlayerMoney(playerid, 5000);
  346.     DestroyVehicle(playerInfo[playerid][vehicleRacePlayer]);
  347.     SetPlayerVirtualWorld(playerid, 0);
  348.     TogglePlayerGhostMode(playerid, false);
  349.     DisableRemoteVehicleCollisions(playerid, false);
  350.     SetPlayerPos(playerid, -302.4741, 1509.9989, 75.3594);
  351.     SetPlayerFacingAngle(playerid, 183.1553);
  352.     SetCameraBehindPlayer(playerid);
  353.     PlayerTextDrawHide(playerid, playerInfo[playerid][counterCheckpoints]);
  354.     GameTextForPlayer(playerid, "Has ganado +5000$", 3000, 3);
  355.  
  356.     playerInfo[playerid][joiningRace] = LOBBY_PLAYER;
  357.     playerInfo[playerid][checkpointsPassed] = RESTAURED;
  358.     UpdateCounterCheckpoint(playerid);
  359.  
  360.     return 1;
  361. }
  362.  
  363. public UpdateCounterCheckpoint(playerid)
  364. {
  365.     new td_update[15];
  366.     format(td_update, sizeof(td_update), "%i/%i", playerInfo[playerid][checkpointsPassed], sizeof(checkpointsRace) - 1);
  367.     PlayerTextDrawSetString(playerid, playerInfo[playerid][counterCheckpoints], td_update);
  368.     return 1;
  369. }
Tags: race
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement