04.01.2010, 08:13
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
pawn Код:
stock CreateCheckpoint(playerid = -1, Float:cpX, Float:cpY, Float:cpZ, Float:cpSize, Float:viewdist)
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;
}
Firstly the timer (Place it under OnGameModeInit or under OnFilterScriptInit):
pawn Код:
SetTimer("Stream", 300, true);
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;
}
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
if(PlayerCP[playerid] != -1) return OnPlayerEnterStreamedCheckpoint(playerid, PlayerCP[playerid]);
return 1;
}
stock OnPlayerEnterStreamedCheckpoint(playerid, CPID)
{
}
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...
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...
}
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;
}
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;
}
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;
}
Enjoy, post any questions etc .