[Tutorial] [TUT]Basic Checkpoint Streamer
#1

Basic Checkpoint Streamer
This is my 4th TUT, Enjoy .

As always, lets start off with the defines:
pawn Код:
#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 Код:
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 Код:
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 Код:
SetTimer("Stream", 300, true);
OK, now the actual streaming function:
pawn Код:
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 Код:
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 Код:
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 Код:
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 Код:
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 Код:
#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 Код:
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 .
Reply
#2

Very nice again
Reply
#3

nice tutorial
Reply
#4

Very nice again
Reply
#5

Once again this is nice
Reply
#6

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.
Reply
#7

interesting and nice
Reply
#8

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?
Reply
#9

How to make to checkpoint will be just for ONE player not for evryone.... what i need to put instead of -1 ??
Reply
#10

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.
Reply
#11

Quote:
Originally Posted by [HiC
TheKiller ]
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.
Ok its work...Can you help me whit destroy checkpints whit command...Something like this....

pawn Код:
if(strcmp("/quit", cmdtext, true, 10) == 0)
  {
    CPDisabled[CPiD] = 44;
     CPDisabled[CPiD] = 45;
     CPDisabled[CPiD] = 46;
     CPDisabled[CPiD] = 47;
     CPDisabled[CPiD] = 48;
     CPDisabled[CPiD] = 49;
     CPDisabled[CPiD] = 50;
     CPDisabled[CPiD] = 51;
     CPDisabled[CPiD] = 52;
And i get this error
C:\Users\NASTIE\Desktop\ExtremeFun\filterscripts\C heckpoint.pwn(602) : error 017: undefined symbol "CPiD"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

But when i type that command, checkpoints are still visible on map... Can you help me...
Reply
#12

bump
Reply
#13

Nice this is just what i have been looking for.
Reply
#14

Quote:
Originally Posted by [EFS
]
Quote:
Originally Posted by [HiC
TheKiller ]
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.
Ok its work...Can you help me whit destroy checkpints whit command...Something like this....

pawn Код:
if(strcmp("/quit", cmdtext, true, 10) == 0)
  {
    CPDisabled[CPiD] = 44;
     CPDisabled[CPiD] = 45;
     CPDisabled[CPiD] = 46;
     CPDisabled[CPiD] = 47;
     CPDisabled[CPiD] = 48;
     CPDisabled[CPiD] = 49;
     CPDisabled[CPiD] = 50;
     CPDisabled[CPiD] = 51;
     CPDisabled[CPiD] = 52;
And i get this error
C:\Users\NASTIE\Desktop\ExtremeFun\filterscripts\C heckpoint.pwn(602) : error 017: undefined symbol "CPiD"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

But when i type that command, checkpoints are still visible on map... Can you help me...
Can someone help me?
Reply
#15

Quote:
Originally Posted by [EFS
]
Quote:
Originally Posted by [EFS
]
Quote:
Originally Posted by [HiC
TheKiller ]
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.
Ok its work...Can you help me whit destroy checkpints whit command...Something like this....

pawn Код:
//code
And i get this error
C:\Users\NASTIE\Desktop\ExtremeFun\filterscripts\C heckpoint.pwn(602) : error 017: undefined symbol "CPiD"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

But when i type that command, checkpoints are still visible on map... Can you help me...
Can someone help me?
Isnt it CPID ?

And what should the code do ?

If you want to disable the checkpoints you need to do
pawn Код:
CPDisabled[THE_CHECKPOINT_ID] = true;
or just
pawn Код:
DestroyCheckpoint(THE_CHECKPOINT_ID); //DestroyCheckpoint function is posted in the first post
@TheKiller
The first OnPlayerEnterStreamedCheckpoint uses CPID (which should be CPiD)
Reply
#16

Not BAD but i make this command

pawn Код:
if(strcmp("/otkaz1", cmdtext, true, 10) == 0)
  {
    if(kam1[playerid] == 0 ) return SendClientMessage(playerid ,0xFF0000FF, "Nisi zaposlen!");
    else
    {
    SendClientMessage(playerid, 0xFF5A00FF, "------------------------------------------------");
    SendClientMessage(playerid, 0xFFFFFFFF, "Dao si otkaz.");
    SendClientMessage(playerid, 0xFFFFFFFF, "Vise ne radis kao vozac kamiona!");
    SendClientMessage(playerid, 0xFFFFFFFF, ".:: EFS ::.");
    SendClientMessage(playerid, 0xFF5A00FF, "------------------------------------------------");
    new
    string[128],
    name[MAX_PLAYER_NAME];
      GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof string,"%s je dao otkaz",name);
    SendClientMessageToAll(0x6400FFFF,string);
   
    // Unisti!
    DestroyCheckpoint(44);
    DestroyCheckpoint(45);
    DestroyCheckpoint(46);
    DestroyCheckpoint(47);
    DestroyCheckpoint(48);
    DestroyCheckpoint(49);
    DestroyCheckpoint(50);
    DestroyCheckpoint(51);
    DestroyCheckpoint(52);
    DestroyCheckpoint(53);
   
    // DISABLE!
    CPDisabled[44] = true;
    CPDisabled[45] = true;
    CPDisabled[46] = true;
    CPDisabled[47] = true;
    CPDisabled[48] = true;
    CPDisabled[49] = true;
    CPDisabled[50] = true;
    CPDisabled[51] = true;
    CPDisabled[52] = true;
    CPDisabled[53] = true;

    }
    return 1;
  }
And when i type that command i still see checkpoint on the map.... please help
Reply
#17

Quote:
Originally Posted by ♣ Joker ♠
Quote:
Originally Posted by [EFS
]
Quote:
Originally Posted by [EFS
]
Quote:
Originally Posted by [HiC
TheKiller ]
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.
Ok its work...Can you help me whit destroy checkpints whit command...Something like this....

pawn Код:
//code
And i get this error
C:\Users\NASTIE\Desktop\ExtremeFun\filterscripts\C heckpoint.pwn(602) : error 017: undefined symbol "CPiD"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

But when i type that command, checkpoints are still visible on map... Can you help me...
Can someone help me?
Isnt it CPID ?

And what should the code do ?

If you want to disable the checkpoints you need to do
pawn Код:
CPDisabled[THE_CHECKPOINT_ID] = true;
or just
pawn Код:
DestroyCheckpoint(THE_CHECKPOINT_ID); //DestroyCheckpoint function is posted in the first post
@TheKiller
The first OnPlayerEnterStreamedCheckpoint uses CPID (which should be CPiD)
Done

Quote:
Originally Posted by [EFS
]
Not BAD but i make this command

pawn Код:
if(strcmp("/otkaz1", cmdtext, true, 10) == 0)
  {
    if(kam1[playerid] == 0 ) return SendClientMessage(playerid ,0xFF0000FF, "Nisi zaposlen!");
    else
    {
    SendClientMessage(playerid, 0xFF5A00FF, "------------------------------------------------");
    SendClientMessage(playerid, 0xFFFFFFFF, "Dao si otkaz.");
    SendClientMessage(playerid, 0xFFFFFFFF, "Vise ne radis kao vozac kamiona!");
    SendClientMessage(playerid, 0xFFFFFFFF, ".:: EFS ::.");
    SendClientMessage(playerid, 0xFF5A00FF, "------------------------------------------------");
    new
    string[128],
    name[MAX_PLAYER_NAME];
      GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof string,"%s je dao otkaz",name);
    SendClientMessageToAll(0x6400FFFF,string);
   
    // Unisti!
    DestroyCheckpoint(44);
    DestroyCheckpoint(45);
    DestroyCheckpoint(46);
    DestroyCheckpoint(47);
    DestroyCheckpoint(48);
    DestroyCheckpoint(49);
    DestroyCheckpoint(50);
    DestroyCheckpoint(51);
    DestroyCheckpoint(52);
    DestroyCheckpoint(53);
   
    // DISABLE!
    CPDisabled[44] = true;
    CPDisabled[45] = true;
    CPDisabled[46] = true;
    CPDisabled[47] = true;
    CPDisabled[48] = true;
    CPDisabled[49] = true;
    CPDisabled[50] = true;
    CPDisabled[51] = true;
    CPDisabled[52] = true;
    CPDisabled[53] = true;

    }
    return 1;
  }
And when i type that command i still see checkpoint on the map.... please help
I would recommend you do it like this.
pawn Код:
new CP1 = CreateCheckpoint(....);
DestroyCheckpoint(CP1);
And there was a problem where it would only disable on the next stream but it shouldn't really matter.
Reply
#18

nice work i hope its work for me
Reply
#19

Sorry for bumping an old topic, but when I enter a checkpoint it will spam me every second.

So if I sent a message it would re-appear every second while inside the checkpoint.
Reply
#20

W00T!
Reply


Forum Jump:


Users browsing this thread: 21 Guest(s)