Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <open.mp>
- #include <zcmd>
- #define LOBBY_PLAYER 0
- #define JOINED_PLAYER 1
- #define RESTAURED 0
- forward UpdateCounterCheckpoint(playerid);
- // ALMACÉN DE DATOS DE UN JUGADOR
- // =========================================================================================
- enum playerData {
- PlayerText:counterCheckpoints,
- playerName[MAX_PLAYER_NAME],
- vehicleRacePlayer,
- checkpointsPassed,
- joiningRace
- };
- new playerInfo[MAX_PLAYERS][playerData];
- // =========================================================================================
- // ALMACÉN DE COORDENADAS DE UNA CARRERA
- // =========================================================================================
- enum pointsRace {
- Float:coordX,
- Float:coordY,
- Float:coordZ,
- Float:angle
- };
- new checkpointsRace[][pointsRace] = {
- {138.3773, 1944.0968, 18.9926, 359.8733}, // POSICIÓN INICIAL: coordX, coordY, coordZ, angle
- {133.2255, 2052.2720, 16.4774},
- {-12.1056, 2067.4399, 17.1517},
- {-17.6648, 2006.1898, 16.8847},
- {-60.6377, 1971.8846, 16.8866},
- {-66.3311, 1724.0090, 16.8871},
- {-28.5127, 1652.5846, 16.8825},
- {263.8007, 1647.2498, 16.8831},
- {315.9866, 1680.4749, 16.8836},
- {318.8882, 1745.9812, 16.8884},
- {365.6351, 1784.9834, 16.8830},
- {370.0326, 1851.8794, 16.8843},
- {421.7878, 1894.7731, 16.8864},
- {423.9970, 2078.3047, 16.8850},
- {376.8186, 2130.9014, 16.8826},
- {-3.3853, 2119.1199, 16.8858},
- {-12.3878, 2067.9426, 17.1481},
- {-167.2211, 2042.6006, 15.3767},
- {-107.8565, 1525.6746, 15.5774},
- {-65.6314, 1326.2266, 11.0086},
- {-73.2364, 1259.6481, 11.7067},
- {-119.5829, 1254.8035, 17.6710},
- {-110.5325, 1141.4126, 19.3998},
- {-115.0757, 1086.3253, 19.3906},
- {-109.3413, 951.7379, 20.2825},
- {-26.4002, 947.0177, 18.7739},
- {-23.1836, 924.7546, 20.5279},
- {7.3780, 923.2450, 21.6015},
- {8.3403, 983.5715, 19.1726},
- {36.8004, 984.3917, 18.2175},
- {34.7194, 1040.9800, 16.9427},
- {-15.7136, 1045.7145, 19.2519},
- {-15.4169, 1099.2161, 19.2566},
- {-65.8205, 1098.3221, 19.2500},
- {-64.2512, 1198.4069, 19.2242},
- {-114.9314, 1199.3641, 19.2537},
- {-120.0876, 1254.1786, 17.7139},
- {-241.5951, 1238.8800, 23.2560},
- {-398.2947, 1327.0133, 26.2985},
- {-448.5366, 1486.2089, 34.2863},
- {-428.6691, 1657.1395, 36.0266},
- {-395.3008, 1756.5182, 43.1233},
- {-382.0470, 1831.8517, 50.5951},
- {-409.7466, 1917.4742, 57.4486},
- {-442.0951, 1760.4911, 71.6906},
- {-474.4391, 1951.5120, 84.9162},
- {-384.3170, 2076.6882, 60.5730},
- {-450.3127, 2033.6598, 60.3167},
- {-471.3879, 2068.6365, 60.4068},
- {-435.2260, 2122.1008, 46.3778},
- {-426.7271, 2141.0144, 44.8369},
- {-372.8344, 2165.6743, 41.8508},
- {-392.3487, 2289.1582, 39.0986},
- {-369.5579, 2349.9182, 29.3900},
- {-378.5913, 2415.9641, 41.0825},
- {-400.3170, 2458.0981, 42.1515},
- {-342.6212, 2511.1987, 35.4335},
- {-384.1227, 2573.3450, 40.4794},
- {-421.4793, 2718.1890, 61.9085},
- {-547.9167, 2716.5474, 65.3866},
- {-623.2031, 2633.4917, 86.5642},
- {-512.6873, 2427.9199, 56.6490},
- {-403.0269, 2460.4395, 42.5379},
- {-379.4317, 2419.8667, 41.4199},
- {-382.9261, 2380.1145, 34.2511},
- {-368.7681, 2344.0706, 29.7888},
- {-394.6370, 2285.8176, 39.6389},
- {-479.3115, 2302.0613, 61.4729},
- {-590.0309, 2379.3293, 81.7542},
- {-718.9361, 2455.6206, 123.1256},
- {-695.4927, 2406.7642, 130.5795},
- {-713.0059, 2387.9543, 128.1194},
- {-743.9400, 2344.2690, 124.3624},
- {-822.9233, 2356.9604, 120.5508},
- {-794.1212, 2503.3750, 98.4590},
- {-773.2552, 2558.5076, 85.7740},
- {-735.7543, 2520.4641, 76.6193},
- {-707.2684, 2522.9441, 74.4357},
- {-586.7090, 2431.8799, 68.8785},
- {-459.6766, 2446.3875, 48.2302},
- {-402.2812, 2457.9377, 42.4187},
- {-379.1075, 2419.0222, 41.3582},
- {-384.4041, 2381.6633, 34.6374},
- {-369.3444, 2348.8757, 29.4456},
- {-392.5277, 2286.0078, 39.5470},
- {-374.6805, 2162.8918, 41.9603},
- {-430.0211, 2136.7861, 45.1605},
- {-470.7299, 2073.2080, 59.9557},
- {-453.5273, 2033.0168, 60.2652},
- {-508.7905, 1988.9325, 59.8447},
- {-707.8640, 2062.3945, 60.0413},
- {-882.6657, 1983.7200, 59.8609},
- {-858.5137, 1814.5343, 59.8391},
- {-919.1517, 1791.9160, 59.8351},
- {-1010.9431, 1854.6733, 62.1255},
- {-1171.2224, 1796.7264, 39.7713},
- {-1030.1288, 1727.2352, 30.7332},
- {-923.9425, 1718.1063, 27.4339},
- {-846.3175, 1582.9999, 25.4597},
- {-842.1508, 1415.3525, 13.2692},
- {-728.6545, 1236.8206, 13.0633},
- {-626.4410, 1211.2676, 11.2483},
- {-576.9376, 1116.4608, 10.5597},
- {-626.5583, 1066.9999, 11.6603},
- {-708.9901, 1032.6641, 11.7937},
- {-721.4108, 942.1447, 11.7928},
- {-736.4824, 767.0458, 18.0900},
- {-760.4346, 720.6406, 17.8275},
- {-634.5916, 646.0507, 16.2948},
- {-356.6280, 551.8482, 16.0665},
- {-243.5455, 537.0562, 13.4849},
- {-125.8687, 534.7529, 6.8293},
- {-139.5634, 477.4754, 11.7536},
- {-204.4163, 234.0669, 11.7363},
- {-281.9970, 40.7338, 0.7381},
- {-308.2919, -147.0981, 0.7380},
- {-186.9246, -337.5111, 0.7381},
- {-71.2279, -434.1797, 0.7381},
- {34.8012, -518.2227, 9.6671},
- {33.7570, -641.6093, 2.6699},
- {-33.4605, -804.1238, 10.3777},
- {-92.3932, -925.0240, 18.6895},
- {-124.5911, -985.3041, 25.4328},
- {-88.3483, -1037.8085, 23.3246},
- {-86.0268, -1102.6621, 3.0998},
- {-141.4267, -1251.2079, 2.3563},
- {-135.3133, -1447.3495, 2.3553},
- {-25.2352, -1516.0520, 1.4801},
- {-47.2224, -1587.7247, 2.7378},
- {-157.9227, -1628.8599, 2.9364},
- {-246.3678, -1700.3357, 2.1716},
- {-270.5235, -1827.8643, 17.5008},
- {-277.2839, -1907.0021, 26.6756},
- {-330.4329, -1914.9656, 12.0752},
- {-436.5369, -1917.5955, 6.0335},
- {-461.9475, -2018.5398, 45.4415},
- {-581.1581, -2029.6005, 46.1506},
- {-675.7419, -1990.7527, 24.3672},
- {-671.8813, -1906.9576, 7.9833},
- {-686.4479, -1861.8348, 13.4398},
- {-805.8774, -1898.2999, 9.8988},
- {-830.0934, -2032.7970, 23.5928},
- {-809.4908, -2168.4463, 21.8762},
- {-945.7052, -2193.8604, 37.1393},
- {-960.4169, -2294.1165, 54.9649},
- {-939.3588, -2350.1143, 58.6873},
- {-862.9333, -2412.3557, 55.7973},
- {-778.3489, -2457.1165, 73.3964},
- {-727.4724, -2371.8508, 47.7266},
- {-660.3845, -2359.1477, 35.6966},
- {-580.1542, -2369.5225, 27.5983},
- {-622.2806, -2431.5032, 30.6902},
- {-669.7758, -2501.8806, 39.5234},
- {-717.6393, -2623.2239, 76.4584},
- {-765.8481, -2682.2200, 83.9212},
- {-828.4394, -2683.4229, 94.3931},
- {-921.9073, -2666.5056, 84.6733},
- {-1031.0133, -2682.2600, 49.0513},
- {-1116.7500, -2656.7500, 17.1898},
- {-1172.2695, -2639.8604, 11.4176},
- {-1229.8696, -2638.7432, 8.8095},
- {-1302.2876, -2635.1135, 10.7334},
- {-1377.6473, -2630.8311, 29.7285},
- {-1459.7495, -2633.6128, 39.6752},
- {-1544.9243, -2633.9429, 52.6062},
- {-1684.3109, -2600.3438, 34.2736},
- {-1768.0189, -2501.7507, 8.2690},
- {-1841.4791, -2454.7561, 28.2002},
- {-1894.6873, -2422.9575, 32.1016},
- {-1942.3892, -2456.8806, 30.4177},
- {-2020.9010, -2510.9089, 32.2357},
- {-1958.6921, -2556.8494, 38.3815},
- {-1874.2275, -2532.2915, 44.3478},
- {-1756.2885, -2590.2480, 50.9604},
- {-1557.7035, -2778.2979, 47.3722},
- {-1391.2428, -2869.9299, 50.4393},
- {-1194.2031, -2855.3875, 67.5749},
- {-963.3413, -2850.5776, 67.3880},
- {-756.5721, -2766.4011, 74.3386},
- {-598.5874, -2747.7532, 66.9425},
- {-305.2773, -2805.2854, 56.0411},
- {-163.7755, -2824.8335, 40.6429},
- {-52.5434, -2755.5083, 40.5496},
- {-57.8492, -2555.1086, 41.6194},
- {-167.9094, -2416.4763, 35.5465},
- {-298.6412, -2258.5505, 29.3591},
- {-350.1202, -2100.5334, 27.9847},
- {-371.6060, -1968.3761, 27.8126},
- {-315.6837, -1758.8584, 15.6683},
- {-284.3117, -1643.4879, 15.1196},
- {-95.2045, -1406.3168, 12.0437},
- {-56.5715, -1322.8999, 8.7075},
- {-101.0582, -1292.7904, 4.1182},
- {-145.4855, -1358.6056, 1.9810},
- {-110.1547, -1482.0712, 2.3553},
- {-23.7832, -1516.8418, 1.4796},
- {-79.7605, -1619.3715, 3.0648},
- {-201.4006, -1636.3112, 2.7463},
- {-253.7977, -1736.6241, 3.5854},
- {-279.1429, -1905.9796, 26.6127}
- };
- // =========================================================================================
- // 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.
- // ========================================================================================
- public OnPlayerConnect(playerid)
- {
- new td_counter[15];
- format(td_counter, sizeof(td_counter), "%i/%i", playerInfo[playerid][checkpointsPassed], sizeof(checkpointsRace) - 1);
- playerInfo[playerid][counterCheckpoints] = CreatePlayerTextDraw(playerid, 612.000000, 411.000000, td_counter);
- PlayerTextDrawFont(playerid, playerInfo[playerid][counterCheckpoints], t_TEXT_DRAW_FONT:1);
- PlayerTextDrawLetterSize(playerid, playerInfo[playerid][counterCheckpoints], 0.504166, 1.950000);
- PlayerTextDrawTextSize(playerid, playerInfo[playerid][counterCheckpoints], 400.000000, 17.000000);
- PlayerTextDrawSetOutline(playerid, playerInfo[playerid][counterCheckpoints], 1);
- PlayerTextDrawSetShadow(playerid, playerInfo[playerid][counterCheckpoints], 0);
- PlayerTextDrawAlignment(playerid, playerInfo[playerid][counterCheckpoints], t_TEXT_DRAW_ALIGN:3);
- PlayerTextDrawColour(playerid, playerInfo[playerid][counterCheckpoints], -1);
- PlayerTextDrawBackgroundColour(playerid, playerInfo[playerid][counterCheckpoints], 255);
- PlayerTextDrawBoxColour(playerid, playerInfo[playerid][counterCheckpoints], 50);
- PlayerTextDrawUseBox(playerid, playerInfo[playerid][counterCheckpoints], false);
- PlayerTextDrawSetProportional(playerid, playerInfo[playerid][counterCheckpoints], true);
- PlayerTextDrawSetSelectable(playerid, playerInfo[playerid][counterCheckpoints], false);
- return 1;
- }
- // ========================================================================================
- // 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.
- CMD:unir(playerid)
- {
- if(playerInfo[playerid][joiningRace] == JOINED_PLAYER)
- {
- SendClientMessage(playerid, -1, "ERROR: Actualmente estás dentro de una carrera.");
- return 1;
- }
- PlayerTextDrawShow(playerid, playerInfo[playerid][counterCheckpoints]); // Ésta es la función que hace visible el textdraw cargado en el callback de "OnPlayerConnect".
- GetPlayerName(playerid, playerInfo[playerid][playerName], MAX_PLAYER_NAME);
- playerInfo[playerid][vehicleRacePlayer] =
- CreateVehicle(562,
- checkpointsRace[0][coordX],
- checkpointsRace[0][coordY],
- checkpointsRace[0][coordZ],
- checkpointsRace[0][angle],
- 1, 0, 0, false);
- SetVehicleVirtualWorld(playerInfo[playerid][vehicleRacePlayer], 1);
- SetPlayerVirtualWorld(playerid, 1);
- PutPlayerInVehicle(playerid, playerInfo[playerid][vehicleRacePlayer], 0);
- TogglePlayerGhostMode(playerid, true);
- DisableRemoteVehicleCollisions(playerid, true);
- SetCameraBehindPlayer(playerid);
- playerInfo[playerid][joiningRace] = JOINED_PLAYER;
- SetPlayerRaceCheckpoint(playerid, t_CP_TYPE:0,
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordX],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordY],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordZ],
- 5);
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- playerInfo[playerid][checkpointsPassed]++;
- DisablePlayerRaceCheckpoint(playerid);
- UpdateCounterCheckpoint(playerid);
- /* 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.
- 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").
- 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.
- 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. */
- if(playerInfo[playerid][checkpointsPassed] < sizeof(checkpointsRace) - 2)
- {
- SetPlayerRaceCheckpoint(playerid,
- t_CP_TYPE:0,
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordX],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordY],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 2][coordZ],
- 5);
- return 1;
- }
- // 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).
- if(playerInfo[playerid][checkpointsPassed] == sizeof(checkpointsRace) - 2)
- {
- SetPlayerRaceCheckpoint(playerid,
- t_CP_TYPE:1,
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordX],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordY],
- checkpointsRace[playerInfo[playerid][checkpointsPassed] + 1][coordZ],
- 0,
- 0,
- 0,
- 5);
- return 1;
- }
- GivePlayerMoney(playerid, 5000);
- DestroyVehicle(playerInfo[playerid][vehicleRacePlayer]);
- SetPlayerVirtualWorld(playerid, 0);
- TogglePlayerGhostMode(playerid, false);
- DisableRemoteVehicleCollisions(playerid, false);
- SetPlayerPos(playerid, -302.4741, 1509.9989, 75.3594);
- SetPlayerFacingAngle(playerid, 183.1553);
- SetCameraBehindPlayer(playerid);
- PlayerTextDrawHide(playerid, playerInfo[playerid][counterCheckpoints]);
- GameTextForPlayer(playerid, "Has ganado +5000$", 3000, 3);
- playerInfo[playerid][joiningRace] = LOBBY_PLAYER;
- playerInfo[playerid][checkpointsPassed] = RESTAURED;
- UpdateCounterCheckpoint(playerid);
- return 1;
- }
- public UpdateCounterCheckpoint(playerid)
- {
- new td_update[15];
- format(td_update, sizeof(td_update), "%i/%i", playerInfo[playerid][checkpointsPassed], sizeof(checkpointsRace) - 1);
- PlayerTextDrawSetString(playerid, playerInfo[playerid][counterCheckpoints], td_update);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement