PDA

View Full Version : [Help] How to create races?


Dragonic
31/07/2015, 02:40 AM
So, how can I create races with checkpoints? Like if a player type /race, he'll be teleported to a specific location and then the checkpoints will be shown for him and all that stuff, when he pass through one CP another will appear (hope you get the point).

!damo!spiderman
31/07/2015, 02:45 AM
http://wiki.sa-mp.com/wiki/OnPlayerCommandText
http://wiki.sa-mp.com/wiki/SetVehiclePos
http://wiki.sa-mp.com/wiki/Function:SetPlayerCheckpoint
http://wiki.sa-mp.com/wiki/OnPlayerEnterCheckpoint

Dragonic
31/07/2015, 03:04 AM
Can you give me an example on how to put this together?

!damo!spiderman
31/07/2015, 04:42 AM
Do you know any scripting at all?

Basically have an array of your points for the checkpoints, have a variable which tracks each players checkpoint id. When the player enters the command set their vehicle position to where the race is, then set the first checkpoint. When they go through a checkpoint the function OnPlayerEnterCheckpoint will be called, just increase their checkpoint id by 1 then set their new checkpoint and so on until the end

Dragonic
31/07/2015, 10:29 AM
Do you know any scripting at all?

Yes, a bit... I'm trying to learn. About the teleport and stuff its fine, but I don't know how to make the lines for when a player enters the first CP it starts to show the second...

ognyanov
31/07/2015, 10:54 AM
pff you can use filterscripts for races,just search and you will find some.Good luck!!!..

Dragonic
31/07/2015, 12:32 PM
I tried a few, none worked... I'm trying something else

PMH
31/07/2015, 02:43 PM
I tried a few, none worked... I'm trying something else

Use Rryder's racing filterscript. Its the best one out there wothout any bigs. U gotta search it though

Dragonic
31/07/2015, 03:32 PM
I tried! But when I downloaded it only gave me .pwn and when I tried to compile it I received 2 errors

Dragonic
31/07/2015, 07:08 PM
Tried Ryder's once again... Dunno what happend but it don't create the race...
Can someone please give me an example on how to when the player go through one CP, another will appear..

x3378
31/07/2015, 07:49 PM
It is not difficult, I will try to give you a clear example.


#include <a_samp>

new g_ProgresInRace[MAX_PLAYERS]; // This variable identifies the progress in the race.
new bool:g_PlayerInRace[MAX_PLAYERS]; // This variable identifies a participant in a race.


static const Float:checkpoints[10][3] = // checkpoints of the race.
{
// fX fY fZ
{00.00, 00.00, 00.00}, // checkpoint 1 (ID:0)
{00.00, 00.00, 00.00}, // checkpoint 2 (ID:1)
{00.00, 00.00, 00.00}, // checkpoint 3 (ID:2)
{00.00, 00.00, 00.00}, // checkpoint 4 (ID:3)
{00.00, 00.00, 00.00}, // checkpoint 5 (ID:4)
{00.00, 00.00, 00.00}, // checkpoint 6 (ID:5)
{00.00, 00.00, 00.00}, // checkpoint 7 (ID:6)
{00.00, 00.00, 00.00}, // checkpoint 8 (ID:7)
{00.00, 00.00, 00.00}, // checkpoint 9 (ID:8)
{00.00, 00.00, 00.00} // checkpoint 10. (ID:9)
};

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/race", cmdtext, true, 5) == 0)
{
// We check to see if the player already participating in a race.
if (g_PlayerInRace[playerid] == true)
return SendClientMessage(playerid, -1, "You are already participating in a race.");

// Get the position of the player to create the vehicle close to your position.
new
Float:fX, Float:fY, Float:fZ;
GetPlayerPos(playerid, fX, fY, fZ);

// We create the vehicle and set driver of the vehicle to the player.
new vehicle = CreateVehicle(411, fX, fY, fZ, 6.0, random(20), random(20), 60, 0);
SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
PutPlayerInVehicle(playerid, vehicle, 0);

//We establish the progress of the race in 0 and add positive value to the variable that identifies if the player is in a race.
g_ProgresInRace[playerid] = 0;
g_PlayerInRace[playerid] = true;

// Set first checkpoint of the race(checkpoints[i][0,1,2(fX, fY, fZ)]).
SetPlayerRaceCheckpoint(playerid, 0, checkpoints[0][0], checkpoints[0][1], checkpoints[0][2], checkpoints[1][0], checkpoints[1][1], checkpoints[1][2], 12.5);
return 1;
}
return 0;
}

// This public function is called when a player enters a race checkpoint.
public OnPlayerEnterRaceCheckpoint(playerid)
{
// We check to see if the player already participating in a race.
if (g_PlayerInRace[playerid] == true)
{
// It is participant and entered into a checkpoint, therefore we will add +1 to your progress.
g_ProgresInRace[playerid] = g_ProgresInRace[playerid] +1;

// This is to save space.
new slot = g_ProgresInRace[playerid];

/*
We check that the checkpoint is not the penultimate, so that we can create the final checkpoint as type finish.
If it is 7 or less we will be adding a checkpoint next type.
*/
if (g_ProgresInRace[playerid] <= 7){
SetPlayerRaceCheckpoint(playerid, 0, checkpoints[(slot)][0], checkpoints[(slot)][1], checkpoints[(slot)][2], checkpoints[(slot)+1][0], checkpoints[(slot)+1][1], checkpoints[(slot)+1][2], 12.5);
}
/*
We check to see if the checkpoint is the penultimate(8 0 - 9), if so add the following checkpoint as finish type.
*/
else if (g_ProgresInRace[playerid] == 8){
SetPlayerRaceCheckpoint(playerid, 1, checkpoints[(slot)][0], checkpoints[(slot)][1], checkpoints[(slot)][2], 00.00, 00.00, 00.00, 12.5);
}
/*
If it was the last checkpoint(9 ) we will finish the race of the player, this will happen when entering the last checkpoint.
*/
else if (g_ProgresInRace[playerid] == 9){

/*
We restarted their statistics!
*/
g_ProgresInRace[playerid] = 0;
g_PlayerInRace[playerid] = false;
SendClientMessage(playerid, -1, "You've completed the race!");
}
}
return true;
}

Dragonic
01/08/2015, 12:57 AM
I recieve alot of "Tag Mismatch" when I put the coords of the checkpoints

{1557,34,25}, // checkpoint 1 (ID:0)
{1548,-151,13}, // checkpoint 2 (ID:1)
{1261,-152,39}, // checkpoint 3 (ID:2)
{872,-91,28}, // checkpoint 4 (ID:3)
{304,-375,10}, // checkpoint 5 (ID:4)
{189,-214,2}, // checkpoint 6 (ID:5)
{231,46,3}, // checkpoint 7 (ID:6)
{-776,158,7}, // checkpoint 8 (ID:7)
{-673,57,32}, // checkpoint 9 (ID:8)
{-675,-18,72} // checkpoint 10. (ID:9)
{-340,-134,63}, // checkpoint 11 (ID:10)
{-541,-188,79} // checkpoint 12. (ID:11)

C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(17) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(17) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(17) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(18) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(18) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(18) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(19) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(19) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(19) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(20) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(20) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(20) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(21) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(21) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(21) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(22) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(22) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(22) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(23) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(23) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(23) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(24) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(24) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(24) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(25) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(25) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(25) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(26) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(26) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(26) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(27) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(27) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(27) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(28) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(28) : warning 213: tag mismatch
C:\Users\Dragonic\Desktop\SA-MP\gamemodes\DR-CITY-GAMEMODE.pwn(28) : warning 213: tag mismatch

SpikeSpigel
01/08/2015, 01:05 AM
I recieve alot of "Tag Mismatch" when I put the coords of the checkpoints

You need 3 parameters, not 2.

Dragonic
01/08/2015, 01:12 AM
Hehe, I've figured that out. Also, theres a way to if a player leaves his car during the race, the checkpoints will disappear and a gametext will be shown for the player "You've been disqualified!"?

SpikeSpigel
01/08/2015, 01:14 AM
Yes. You can use IsPlayerInAnyVehicle function.

Dragonic
01/08/2015, 01:43 AM
You can use IsPlayerInAnyVehicle function.

But it'll display the message when any player leaves any vehicle in any part of the server. I'm new to scripting, can't think about anything that makes the message only be displayed when the player leaves a car with an active checkpoint. If you know something that do that it would be nice (:

Dragonic
01/08/2015, 02:56 AM
I managed to made it:

public OnPlayerExitVehicle(playerid, vehicleid)
{
if (g_PlayerInRace[playerid] == true)
{
DisablePlayerRaceCheckpoint(playerid);
GameTextForPlayer(playerid, "~r~Disqualified!", 5000, 4);
}
return 1;
}

Dragonic
02/08/2015, 01:30 AM
What if I want to make another race? I'm trying to make another based on the same script but it just don't happen, I think it conflicts with the 1st race...

Can someone help me based on x3378 code?