SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 19/08/2009, 07:43 PM   #1
Yuryfury
Huge Clucker
 
Join Date: Sep 2008
Posts: 250
Reputation: 26
Default [TUT]Multiple Checkpoints Without Streamer!

*-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 ) );
}

Steps:
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;
}

Step 6: Get The coordinates of your first checkpoint from your save file and replace X,Y,Z with them:
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;
}
Explanation: Here we check the players distance to the checkpoint's location. If he is closer or exactly 10 coordinates away the checkpoint is shown.

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;
}

Step 8: To make the checkpoint do something we add these lines under OnPlayerEnterCheckpoint(playerid);
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;
}
Explanation: Here once again we check the players distance from the checkpoint. If the player is less or exactly 2 coordinates away then this function is called(GameTextForPlayer)

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!
Yuryfury is offline   Reply With Quote
Old 19/08/2009, 08:26 PM   #2
burgershot
Little Clucker
 
Join Date: Jul 2009
Posts: 14
Reputation: 0
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Thanks a lot for sending me the link!
burgershot is offline   Reply With Quote
Old 19/08/2009, 10:19 PM   #3
Yuryfury
Huge Clucker
 
Join Date: Sep 2008
Posts: 250
Reputation: 26
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Quote:
Originally Posted by burgershot
Thanks a lot for sending me the link!
happy to help
Yuryfury is offline   Reply With Quote
Old 20/08/2009, 12:11 AM   #4
*James*
Little Clucker
 
Join Date: Aug 2009
Posts: 16
Reputation: 0
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Thanks alot, ive been looking for something like this

only 1 question= i am a newb scripter and i wanted to know where this goes or how to make it a function

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 ) );
}
SOLVED nvm tnx
*James* is offline   Reply With Quote
Old 20/08/2009, 02:05 AM   #5
Yuryfury
Huge Clucker
 
Join Date: Sep 2008
Posts: 250
Reputation: 26
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Quote:
Originally Posted by *James*
Thanks alot, ive been looking for something like this

only 1 question= i am a newb scripter and i wanted to know where this goes or how to make it a function

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 ) );
}
SOLVED nvm tnx
Good to see that you got it working, and thanks!

P.S: Thanks to you I noticed that I forgot to put the function in the example script
Yuryfury is offline   Reply With Quote
Old 29/08/2009, 06:11 AM   #6
Shubham
Big Clucker
 
Shubham's Avatar
 
Join Date: Apr 2009
Location: India
Posts: 84
Reputation: -1
Default Re: [TUT]Multiple Checkpoints Without Streamer!

nice man
i like it
Shubham is offline   Reply With Quote
Old 29/08/2009, 08:01 PM   #7
Yuryfury
Huge Clucker
 
Join Date: Sep 2008
Posts: 250
Reputation: 26
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Quote:
Originally Posted by Shubham_Mathur
nice man
i like it
thanks! :P
Yuryfury is offline   Reply With Quote
Old 29/08/2009, 08:17 PM   #8
GTA_Rules
Huge Clucker
 
Join Date: Aug 2008
Posts: 456
Reputation: 3
Default Re: [TUT]Multiple Checkpoints Without Streamer!

Love the idea. Nice work
GTA_Rules is offline   Reply With Quote
Old 29/08/2009, 08:24 PM   #9
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default Re: [TUT]Multiple Checkpoints Without Streamer!

nice tutorial now the beginners will understand how streamers accually work


[TUT]Multipile Checkpoints Without Streamer!
Quote:
That's it! you just made your own checkpoint streamer
lol
ғαιιοцт is offline   Reply With Quote
Old 29/08/2009, 08:30 PM   #10
Donny_k
Gangsta
 
Donny_k's Avatar
 
Join Date: May 2006
Posts: 786
Reputation: 4
Default Re: [TUT]Multiple Checkpoints Without Streamer!

This is far from what I'd call a tutorial and some of that code is very inefficient IMHO.

No offence, just my two cents.
__________________
We don't stop playing because we grow old, we grow old because we stop playing.
Donny_k is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Whats the fastest Streamer for race checkpoints w00tNew Help Archive 1 31/05/2010 06:13 AM
how to: multiple checkpoints? KDlivest954 Help Archive 6 01/04/2010 02:27 AM
Multiple Checkpoints Ironboy500 Help Archive 0 31/10/2009 08:15 AM
Multiple checkpoints JoeDaDude Help Archive 1 25/05/2009 11:07 PM
multiple checkpoints StrickenKid Help Archive 0 04/02/2009 12:24 AM


All times are GMT. The time now is 06:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.