SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/01/2010, 09:13 AM   #1
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,076
Reputation: 406
Default [TUT]Basic Checkpoint Streamer

Basic Checkpoint Streamer

This is my 4th TUT, Enjoy .

As always, lets start off with the defines:
pawn Code:
#define MAX_CPS 500 //Change it if you need more or less

enum Info //CP ENUM
{
  Float:CPX, //Xpos
  Float:CPY, //Ypos
  Float:CPZ, //Zpos
  Float:Size, //Size of the CP
  Float:Viewdist //Viewdistance
};

new CPID = -1; //CPID
new PlayerCP[MAX_PLAYERS] = -1; //PlayerCheckpoints (Only one can be active at once).
new CPinfo[MAX_CPS][Info]; //CPINFO
new CPActive[MAX_PLAYERS][MAX_CPS]; //CPActive for player
new CPDisabled[MAX_CPS]; //For disabling checkpoints

Now with all those boring defines over and done with lets get on to the function.

pawn Code:
stock CreateCheckpoint(playerid = -1, Float:cpX, Float:cpY, Float:cpZ, Float:cpSize, Float:viewdist)

Playerid - playerid of the checkpoint, Use -1 if the checkpoint is going to be for everyone. (If left black it's for everyone).
cpX - Xpos of the CP.
cpY - Ypos of the CP.
cpZ - Zpos of the CP.
cpSize - Checkpoint size.
viewdist - The view distance of the checkpoint.

OK, now for the actual function:

pawn Code:
stock CreateCheckpoint(playerid, Float:cpX, Float:cpY, Float:cpZ, Float:cpSize, Float:viewdist = 35.0)
{
  CPID ++; //CPID
  CPinfo[CPID][CPX] = cpX; //CPX Pos
  CPinfo[CPID][CPY] = cpY; //CPY Pos
  CPinfo[CPID][CPZ] = cpZ; //CPZ Pos
  CPinfo[CPID][Size] = cpSize; //Checkpoint Size
  CPinfo[CPID][Viewdist] = viewdist; //View distance
  if(playerid != -1)
  {
    CPActive[playerid][CPID] ++; //Makes the player able to view that checkpoint
  }
  if(playerid == -1)
  {
    for(new i; i<MAX_PLAYERS; i++)
    {
      CPActive[i][CPID] ++;
    }
  }
  return CPID;
}

Now that that is over and done with lets start streaming!

Firstly the timer (Place it under OnGameModeInit or under OnFilterScriptInit):
pawn Code:
SetTimer("Stream", 300, true);

OK, now the actual streaming function:
pawn Code:
forward Stream();
public Stream()
{
    for(new i; i < MAX_PLAYERS; i ++) //Loops through 500 players
    {
      if(IsPlayerConnected(i)) //Brings the 500 players down to the online ones
      {
        PlayerCP[i] = -1;
        for(new j; j < CPID + 1; j ++) //Loops through all CP's
            {
                if(CPDisabled[j] == 0) //Checks if the CP is disabled.
                {
                    if(IsPlayerInRangeOfPoint(i, CPinfo[j][Viewdist], CPinfo[j][CPX], CPinfo[j][CPY], CPinfo[j][CPZ]) && CPActive[i][j] == 1) //Is the player in range of a CP
                {
                SetPlayerCheckpoint(i, CPinfo[j][CPX], CPinfo[j][CPY], CPinfo[j][CPZ], CPinfo[j][Size]);//Sets the player checkpoint
                PlayerCP[i] = j; //Sets the player checkpoint to that in the variable.
                        printf("PCP:%d", j);
           }
                }
            }
            if(PlayerCP[i] == -1) //If there is no CP close enough
            {
                print("NAHBRO");
                PlayerCP[i] = -1; //PlayerCP isn't anything
            DisablePlayerCheckpoint(i); //Disable any checkpoint visible.
            continue;
      }
        }
  }
  return 1;
}

Now we have one last thing that is needed, what happens when we enter the Checkpoints.

pawn Code:
public OnPlayerEnterCheckpoint(playerid)
{
  if(PlayerCP[playerid] != -1) return OnPlayerEnterStreamedCheckpoint(playerid, PlayerCP[playerid]);
  return 1;
}

stock OnPlayerEnterStreamedCheckpoint(playerid, CPID)
{
 
}

For every checkpoint you must assign a variable to it E.g.

pawn Code:
new CPS1, CPS2, CPS3;
CPS1 = CreateCheckpoint(-1, 1000, 1000, 25, 3, 50);
CPS2 = CreateCheckpoint(-1, 1000, 1100, 25, 3, 50);
CPS3 = CreateCheckpoint(-1, 1000, 1200, 25, 3, 50);
//Etc...

So now we have a ID assigned, we can do this under our OnPlayerEnterStreamedCheckpoint function:

pawn Code:
stock OnPlayerEnterStreamedCheckpoint(playerid, CPiD)
{
  if(CPiD == CPS1)
  {
    GameTextForPlayer(playerid, "You have entered checkpoint 1!", 3000, 3);
  }
  if(CPiD == CPS2)
  {
    GameTextForPlayer(playerid, "You have entered checkpoint 2!", 3000, 3);
  }
  if(CPiD == CPS3)
  {
    GameTextForPlayer(playerid, "You have entered checkpoint 3!", 3000, 3);
  }
  //ETC...
}

Now here is a few functions that you might find useful:

pawn Code:
stock DestroyCheckpoint(CPiD) //Destory's a checkpoint
{
    CPDisabled[CPiD] = 1;
    for(new i; i< MAX_PLAYERS; i++)
    {
      if(PlayerCP[i] == CPiD)
      {
        DisablePlayerCheckpoint(i);
      }
    }
}


stock TogglePlayerCheckpoint(playerid, CPiD, toggled) //Toggles a checkpoint for a player 0 = Not active, 1 = active :)
{
  CPActive[playerid][CPiD] = toggled;
}

So, the overall script should look something like this:

pawn Code:
#include <a_samp>

#define MAX_CPS 500 //Change it if you need more or less

enum Info //CP ENUM
{
  Float:CPX, //Xpos
  Float:CPY, //Ypos
  Float:CPZ, //Zpos
  Float:Size, //Size of the CP
  Float:Viewdist //Viewdistance
};

new CPID = -1; //CPID
new PlayerCP[MAX_PLAYERS] = -1; //PlayerCheckpoints (Only one can be active at once).
new CPinfo[MAX_CPS][Info]; //CPINFO
new CPActive[MAX_PLAYERS][MAX_CPS]; //CPActive for player
new CPDisabled[MAX_CPS]; //For disabling checkpoints

stock CreateCheckpoint(playerid, Float:cpX, Float:cpY, Float:cpZ, Float:cpSize, Float:viewdist = 35.0)
{
  CPID ++; //CPID
  CPinfo[CPID][CPX] = cpX; //CPX Pos
  CPinfo[CPID][CPY] = cpY; //CPY Pos
  CPinfo[CPID][CPZ] = cpZ; //CPZ Pos
  CPinfo[CPID][Size] = cpSize; //Checkpoint Size
  CPinfo[CPID][Viewdist] = viewdist; //View distance
  if(playerid != -1)
  {
    CPActive[playerid][CPID] ++; //Makes the player able to view that checkpoint
  }
  if(playerid == -1)
  {
    for(new i; i<MAX_PLAYERS; i++)
    {
      CPActive[i][CPID] ++;
    }
  }
  return CPID;
}
new CPS1, CPS2, CPS3;
public OnFilterScriptInit()
{
  SetTimer("Stream", 1000, true);
  CPS1 = CreateCheckpoint(-1, 2317.130615, 692.398498, 11.460937, 3.0, 30.0);
  CPS2 = CreateCheckpoint(-1, 2396.482666, 691.487060, 11.453125, 3.0, 30.0);
  CPS3 = CreateCheckpoint(-1, 2396.482666, 697.487060, 11.453125, 3.0, 30.0);
    return 1;
}

forward Stream();
public Stream()
{
    for(new i; i < MAX_PLAYERS; i ++) //Loops through 500 players
    {
      if(IsPlayerConnected(i)) //Brings the 500 players down to the online ones
      {
        PlayerCP[i] = -1;
        for(new j; j < CPID + 1; j ++) //Loops through all CP's
            {
                if(CPDisabled[j] == 0) //Checks if the CP is disabled.
                {
                    if(IsPlayerInRangeOfPoint(i, CPinfo[j][Viewdist], CPinfo[j][CPX], CPinfo[j][CPY], CPinfo[j][CPZ]) && CPActive[i][j] == 1) //Is the player in range of a CP
                {
                SetPlayerCheckpoint(i, CPinfo[j][CPX], CPinfo[j][CPY], CPinfo[j][CPZ], CPinfo[j][Size]);//Sets the player checkpoint
                PlayerCP[i] = j; //Sets the player checkpoint to that in the variable.
                        printf("PCP:%d", j);
           }
                }
            }
            if(PlayerCP[i] == -1) //If there is no CP close enough
            {
                print("NAHBRO");
                PlayerCP[i] = -1; //PlayerCP isn't anything
            DisablePlayerCheckpoint(i); //Disable any checkpoint visible.
            continue;
      }
        }
  }
  return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
  if(PlayerCP[playerid] != -1) return OnPlayerEnterStreamedCheckpoint(playerid, PlayerCP[playerid]);
  return 1;
}

stock OnPlayerEnterStreamedCheckpoint(playerid, CPiD)
{
    printf("CPID: %d", CPiD);
    if(CPiD == CPS1)
    {
      GameTextForPlayer(playerid, "CP1", 2000, 3);
    }
    if(CPiD == CPS2)
    {
      GameTextForPlayer(playerid, "CP2", 2000, 3);
    }
    if(CPiD == CPS3)
    {
      GameTextForPlayer(playerid, "CP3", 2000, 3);
    }
    return 1;
}

stock DestroyCheckpoint(CPiD) //Destory's a checkpoint
{
    CPDisabled[CPiD] = 1;
}

stock TogglePlayerCheckpoint(playerid, CPiD, toggled) //Toggles a checkpoint for a player 0 = Not active, 1 = active :)
{
  CPActive[playerid][CPiD] = toggled;
}

Some more functions

pawn Code:
stock GetPlayerCheckpointID(playerid)
{
  return PlayerCP[playerid];
}

stock IsAnyoneStreamingCP(CPiD)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(PlayerCP[i] == CPiD) return i;
  }
  return 0;
}

If you want better indentation that is posted here, http://www.datafilehost.com/download-6801bbd1.html - Outdated.

Enjoy, post any questions etc .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 04/01/2010, 09:53 AM   #2
V1ceC1ty
High-roller
 
V1ceC1ty's Avatar
 
Join Date: Oct 2008
Location: West Australia
Posts: 1,874
Reputation: 223
Default Re: [TUT]Basic Checkpoint Streamer

Very nice again
__________________
do not play samp anymore pls go away
V1ceC1ty is offline   Reply With Quote
Old 04/01/2010, 10:16 AM   #3
Deat_Itself
Gangsta
 
Join Date: May 2009
Location: UAE (Abudhabi,Shahama)
Posts: 605
Reputation: 4
Default Re: [TUT]Basic Checkpoint Streamer

nice tutorial
Deat_Itself is offline   Reply With Quote
Old 04/01/2010, 10:45 AM   #4
[03]Garsino
Guest
 
Posts: n/a
Default Re: [TUT]Basic Checkpoint Streamer

Very nice again
  Reply With Quote
Old 04/01/2010, 03:57 PM   #5
HydraX
Gangsta
 
Join Date: Mar 2009
Location: Don`t stalk me..
Posts: 967
Reputation: 18
Default Re: [TUT]Basic Checkpoint Streamer

Once again this is nice
__________________
kthxbai.
http://pastebin.com/cLxes1HM

West Coast Generation - Alpha [0.3e]
108.213.37.171:7777
HydraX is offline   Reply With Quote
Old 04/01/2010, 07:23 PM   #6
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,076
Reputation: 406
Default Re: [TUT]Basic Checkpoint Streamer

Quote:
Originally Posted by V1ceC1ty
Very nice again
Quote:
Originally Posted by _Saif_
nice tutorial
Quote:
Originally Posted by [03
Garsino ]
Very nice again
Quote:
Originally Posted by HydraX
Once again this is nice
Thanks.
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 06/01/2010, 02:38 PM   #7
SegaX
Little Clucker
 
Join Date: Dec 2009
Posts: 32
Reputation: 0
Default Re: [TUT]Basic Checkpoint Streamer

interesting and nice
SegaX is offline   Reply With Quote
Old 30/03/2010, 09:26 PM   #8
Epic Shower
Big Clucker
 
Join Date: Feb 2010
Posts: 89
Reputation: 0
Default Re: [TUT]Basic Checkpoint Streamer

Hey.
Destroying the checkpoint isn't working or am i doing something wrong?
Can you please post here the code to make a checkpoint disappear, once a player goes in it?
Epic Shower is offline   Reply With Quote
Old 06/04/2010, 10:21 PM   #9
DarkPower
Gangsta
 
DarkPower's Avatar
 
Join Date: Feb 2010
Posts: 674
Reputation: 7
Default Re: [TUT]Basic Checkpoint Streamer

How to make to checkpoint will be just for ONE player not for evryone.... what i need to put instead of -1 ??
DarkPower is offline   Reply With Quote
Old 06/04/2010, 10:32 PM   #10
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,076
Reputation: 406
Default Re: [TUT]Basic Checkpoint Streamer

Quote:
Originally Posted by [EFS
]
How to make to checkpoint will be just for ONE player not for evryone.... what i need to put instead of -1 ??
Their playerid.
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller 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
[Tutorial] [TUT]Basic Icon streamer! [HiC]TheKiller Tutorials 19 29/06/2012 07:40 PM
[Tutorial] [TUT]Basic Object Streamer [HiC]TheKiller Tutorials 33 19/02/2012 02:25 PM
[Include] [INC]YCP - Yaheli's Checkpoint Streamer - OnPlayerUpdate CP Streamer! Yaheli_Faro Includes 46 20/04/2010 02:53 PM
Could i do this with checkpoint streamer? Torran Help Archive 1 12/04/2010 10:43 AM
How to use checkpoint streamer ruckfules99 Help Archive 5 06/02/2010 01:46 PM


All times are GMT. The time now is 06:17 PM.


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