19.08.2009, 19:43
*-Multiple Checkpoints Tutorial-*
By: Yuryfury
What Is This Tutorial About?To add multiple checkpoints without a streamer! Why would you release a script using someone else's work when you don't have to?
Required Function(s):
GetDistanceToPoint
pawn Code:
stock Float: GetDistanceToPoint(playerid,Float: X2,Float:Y2 ,Float: Z2)
{
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
return floatsqroot ( floatpower ( floatabs ( floatsub ( X , X2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Y , Y2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Z , Z2 ) ) , 2 ) );
}
Step 1: Get The Coordinates For Your Checkpoints(Using /save in-game).
Step 2: Open up a new pawno file or an existing one.
Step 3: Towards the top(somewhere under #include <a_samp>) add the GetDistanceToPoint Function.
Step 4: Under OnPlayerConnect OnGameModeInit(Thanks to Donny) add a timer: SetTimer("CheckpointCheck",500,1); and forward it: forward CheckpointCheck();.
Step 5: Create A New Public Called CheckpointCheck at the bottom of your script:
pawn Code:
public CheckpointCheck()
{
for(new i; i<MAX_PLAYERS; i++)// a loop that goes though all players
{
if(IsPlayerConnected(i))//checks if the player is connected
{
}
}
return 1;
}
pawn Code:
public CheckpointCheck()
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetDistanceToPoint(i,X,Y,Z)<=10) //change 10 to what ever you want the "view distance" to be.
{
SetPlayerCheckpoint(i,-X,Y,Z,2);//Change 2 to what ever radius you want (of the checkpoint)
}
}
}
return 1;
}
Step 7: Now we want to disable the checkpoint when the player is not in the area:
pawn Code:
public CheckpointCheck()
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetDistanceToPoint(i,X,Y,Z)<=10) //change 10 to what ever you want hte "view distance" to be.
{
SetPlayerCheckpoint(i,-X,Y,Z,2);//Change 2 to what ever radius you want (of the checkpoint)
}
else
{
DisablePlayerCheckpoint(i);
}
}
}
return 1;
}
pawn Code:
public OnPlayerEnterCheckpoint(playerid)
{
if(GetDistanceToPoint(playerid,X,Y,Z)<=2)//the same X,Y,Z coords as the ones you put into the timer || the 2 should be your checkpoint radius
{
GameTextForPlayer(playerid,"You Entered A "Streamed" Checkpoint!",5000,3);
}
return 1;
}
Step 9: Your finished script should look something like this
And That's It! You Just Made Your Own "Checkpoint Streamer"! Feel Free To Use And Change It All You Want, You Don't Even Need To Put Me In The Credits(Unless you Want To :P)
If you have any problems ask here!
P.S: I understand that checkpoint streamers are a bit more efficient but here you don't need an extra include or filterscript. This is a lot easier especially if you are only making a small amount of checkpoints. And most importantly you made it so there is no mess with credits if you ever host or release a gamemode!