Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Hidden Checkpoints System
- By: Mansonh
- Dec 2009
- */
- #if defined _HiddenCPS_Included
- #endinput
- #endif
- #define _HiddenCPS_Included
- #define middleof(%1,%2) ((%1+%2)/2.0)
- #define MAX_HIDDEN_CPS (100+1)
- #define ENTER 0
- #define STOP 1
- //CALLBACKS when player enters, exists, or stops, moves in a hidden cp
- forward OnPlayerEnterHiddenCheckPoint(playerid, hcpid);
- forward OnPlayerExitHiddenCheckPoint(playerid, hcpid);
- forward OnPlayerStopInHiddenCheckPoint(playerid, hcpid);
- forward OnPlayerMoveInHiddenCheckPoint(playerid, hcpid);
- enum {
- INVALID_HCP = 0,
- SQUARE_HCP,
- CUBE_HCP,
- CIRCLE_HCP,
- CYLINDER_HCP,
- SPHERE_HCP
- }
- enum HCP_DATA{
- hcp_type,
- Float:hcp_X,
- Float:hcp_Y,
- Float:hcp_Z,
- Float:hcp_X2_WR,
- Float:hcp_Y2_L,
- Float:hcp_Z2,
- bool:multistop
- }
- new hiddenCPS[MAX_HIDDEN_CPS][HCP_DATA];
- new playerhcp[MAX_PLAYERS][2];
- new playerIgnoreHiddenCPS[MAX_PLAYERS][MAX_HIDDEN_CPS];
- new hcpsT = 1;
- //CONSTRUCTORS
- stock CreateHiddenCPSquare(Float:X1, Float:Y1, Float:X2, Float:Y2, bool:mstop = false){
- /* The coordinates are set this way by force, if other corners are chosen it resets them
- _________(X2,Y2)
- / x> /
- (X1,Y1)/_________/y^
- */
- if(X1==X2 || Y1==Y2) return -1;
- new hcpSlot;
- hcpSlot = GetAvailableHCPSlot();
- if(hcpSlot == -1) return -1;
- hiddenCPS[hcpSlot][hcp_type] = SQUARE_HCP;
- if(X1 < X2){hiddenCPS[hcpSlot][hcp_X] = X1; hiddenCPS[hcpSlot][hcp_X2_WR] = X2;}
- else{hiddenCPS[hcpSlot][hcp_X] = X2; hiddenCPS[hcpSlot][hcp_X2_WR] = X1;}
- if(Y1 < Y2){hiddenCPS[hcpSlot][hcp_Y] = Y1; hiddenCPS[hcpSlot][hcp_Y2_L] = Y2;}
- else{hiddenCPS[hcpSlot][hcp_Y] = Y2; hiddenCPS[hcpSlot][hcp_Y2_L] = Y1;}
- return hcpSlot;
- }
- stock CreateHiddenCPCube(Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2, bool:mstop = false){
- /* The coordinates are set this way by force, if other corners are chosen it resets them
- _________(X2,Y2,Z2)
- /| /|
- /________ / |z^
- | |_ _ _ |_ |
- | / x> | /
- (X1,Y1,Z1)|/________|/y^
- */
- if(X1==X2 || Y1==Y2 || Z1==Z2) return -1;
- new hcpSlot;
- hcpSlot = GetAvailableHCPSlot();
- if(hcpSlot == -1) return -1;
- hiddenCPS[hcpSlot][hcp_type] = CUBE_HCP;
- if(X1 < X2){hiddenCPS[hcpSlot][hcp_X] = X1; hiddenCPS[hcpSlot][hcp_X2_WR] = X2;}
- else{hiddenCPS[hcpSlot][hcp_X] = X2; hiddenCPS[hcpSlot][hcp_X2_WR] = X1;}
- if(Y1 < Y2){hiddenCPS[hcpSlot][hcp_Y] = Y1; hiddenCPS[hcpSlot][hcp_Y2_L] = Y2;}
- else{hiddenCPS[hcpSlot][hcp_Y] = Y2; hiddenCPS[hcpSlot][hcp_Y2_L] = Y1;}
- if(Z1 < Z2){hiddenCPS[hcpSlot][hcp_Z] = Z1; hiddenCPS[hcpSlot][hcp_Z2] = Z2;}
- else{hiddenCPS[hcpSlot][hcp_Z] = Z2; hiddenCPS[hcpSlot][hcp_Z2] = Z1;}
- hiddenCPS[hcpSlot][multistop] = mstop;
- return hcpSlot;
- }
- stock CreateHiddenCPCircle(Float:X, Float:Y, Float:R, bool:mstop = false){
- /* _____
- / \
- (X1,Y1)-|--->+(R)-|
- \ _____ /
- */
- if(R==0.0) return -1;
- new hcpSlot;
- hcpSlot = GetAvailableHCPSlot();
- if(hcpSlot == -1) return -1;
- hiddenCPS[hcpSlot][hcp_type] = CIRCLE_HCP;
- hiddenCPS[hcpSlot][hcp_X] = X1;
- hiddenCPS[hcpSlot][hcp_Y] = Y1;
- hiddenCPS[hcpSlot][hcp_X2_WR] = R;
- return hcpSlot;
- }
- stock CreateHiddenCPCylinder(Float:X, Float:Y, Float:Z, Float:R, Float:H, bool:mstop = false){
- /* _____
- / \ _
- | -(R)-| \
- |\_______/| |
- | _____ | >(H) z^
- |/ x> \| |
- (X1,Y1,Z1)-|--->+ y^ | _/
- \_______/
- */
- if(R==0.0 || H==0.0) return -1;
- new hcpSlot;
- hcpSlot = GetAvailableHCPSlot();
- if(hcpSlot == -1) return -1;
- hiddenCPS[hcpSlot][hcp_type] = CYLINDER_HCP;
- hiddenCPS[hcpSlot][hcp_X] = X1;
- hiddenCPS[hcpSlot][hcp_Y] = Y1;
- hiddenCPS[hcpSlot][hcp_Z] = Z1;
- hiddenCPS[hcpSlot][hcp_X2_WR] = R;
- hiddenCPS[hcpSlot][hcp_Z2] = Z1+H;
- return hcpSlot;
- }
- stock CreateHiddenCPSphere(Float:X, Float:Y, Float:Z, Float:R, bool:mstop = false){
- /* A Sphere is the same as a circle its just how its used
- .-----.
- / z^ \
- (X1,Y1,Z1)-|---->*.(R) |
- \ x> y^`./
- `'-----'
- */
- if(R==0.0) return -1;
- new hcpSlot;
- hcpSlot = GetAvailableHCPSlot();
- if(hcpSlot == -1) return -1;
- hiddenCPS[hcpSlot][hcp_type] = SPHERE_HCP;
- hiddenCPS[hcpSlot][hcp_X] = X1;
- hiddenCPS[hcpSlot][hcp_Y] = Y1;
- hiddenCPS[hcpSlot][hcp_Z] = Z1;
- hiddenCPS[hcpSlot][hpc_X2_R] = R;
- return hcpSlot;
- }
- //DESTRUCTOR
- stock DestroyHiddenCheckPoint(hcpid){
- hiddenCPS[hcpid][hcp_type] = INVALID_HCP;
- while(hiddenCPS[hcpid][hcpsT-1] == INVALID_HCP) hcpsT--;
- }
- //HELPER FUNCTIONS
- stock IsValidHiddenCP(hcpid){
- return (hiddenCPS[hcpid][hcp_type] != INVALID_HCP);
- }
- stock GetAvailableHCPSlot(){
- new s;
- for(s=1; s<hcpsT; s++)
- {
- if(hiddenCPS[s][hcp_type] == INVALID_HCP)
- {
- return s;
- }
- }
- if(hcpsT == MAX_HIDDEN_CPS) return -1;
- hcpsT++;
- return s;
- }
- stock bool:PlayerStopped(playerid){
- new Float:Xv, Float:Yv, Float:Zv;
- new vehicleid = GetPlayerVehicleID(playerid);
- if(vehicleid !=0)
- {
- GetVehicleVelocity(vehicleid, Xv, Yv, Zv);
- return (floatsqroot(floatadd(floatadd(floatpower(Xv, 2), floatpower(Yv, 2)), floatpower(Zv, 2))) == 0.0);
- }else{
- GetPlayerVelocity(playerid, Xv, Yv, Zv);
- return (floatadd(floatadd(floatpower(Xv, 2), floatpower(Yv, 2)), floatpower(Zv, 2)) == 0.0);
- }
- }
- //PLAYER HCPS
- stock IsPlayerInHiddenCP(playerid, hcpid){
- if(!IsValidHiddenCP(hcpid) || playerIgnoreHiddenCPS[playerid][INVALID_HCP] != 0 || playerIgnoreHiddenCPS[playerid][hcpid] != 0) return 0;
- new Float:X, Float:Y, Float:Z;
- GetPlayerPos(playerid, X, Y, Z);
- switch (hiddenCPS[hcpid][hcp_type])
- {
- case SQUARE_HCP:
- {
- return (X > hiddenCPS[hcpid][hcp_X] && X < hiddenCPS[hcpid][hcp_X2_WR] && Y > hiddenCPS[hcpid][hcp_Y] && Y < hiddenCPS[hcpid][hcp_Y2_L]);
- }
- case CUBE_HCP:
- {
- return (X > hiddenCPS[hcpid][hcp_X] && X < hiddenCPS[hcpid][hcp_X2_WR] && Y > hiddenCPS[hcpid][hcp_Y] && Y < hiddenCPS[hcpid][hcp_Y2_L] && Z > hiddenCPS[hcpid][hcp_Z] && Z < hiddenCPS[hcpid][hcp_Z2]);
- }
- case CIRCLE_HCP:
- {
- return (IsPlayerInRangeOfPoint(playerid, hiddenCPS[hcpid][hcp_X2_WR], hiddenCPS[hcpid][hcp_X], hiddenCPS[hcpid][hcp_Y], Z));
- }
- case CYLINDER_HCP:
- {
- return (Z > hiddenCPS[hcpid][hcp_Z] && Z < hiddenCPS[hcpid][hcp_Z2] && IsPlayerInRangeOfPoint(playerid, hiddenCPS[hcpid][hcp_X2_WR], hiddenCPS[hcpid][hcp_X], hiddenCPS[hcpid][hcp_Y], Z));
- }
- case SPHERE_HCP:
- {
- return (IsPlayerInRangeOfPoint(playerid, hiddenCPS[hcpid][hcp_X2_WR], hiddenCPS[hcpid][hcp_X], hiddenCPS[hcpid][hcp_Y], Z));
- }
- }
- return 0;
- }
- stock IsPlayerInAnyHiddenCP(playerid){
- if (IsValidHiddenCP(playerhcp[playerid][ENTER]) && playerIgnoreHiddenCPS[playerid][INVALID_HCP] == 0 && playerIgnoreHiddenCPS[playerid][playerhcp[playerid][ENTER]] != 0) return playerhcp[playerid][ENTER];
- return 0;
- }
- stock IsAnyPlayerInHiddenCP(hcpid){
- for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
- {
- if(IsPlayerInHiddenCP(playerid, hcpid) != 0) return 1;
- }
- return 0;
- }
- //IGNORE FLAGS
- //causese players to ignore hcps, 0 don't ignore -1 always ignore, 1,2,3,+ ignore once,twice,thrice etc
- stock PlayerIngoreHiddenCP(playerid, hcpid, ignorerate=-1){
- playerIgnoreHiddenCPS[playerid][hcpid] = ignorerate;
- }
- stock PlayerIgnoreAllHiddenCPS(playerid, ignorerate=-1){
- playerIgnoreHiddenCPS[playerid][INVALID_HCP] = ignorerate; //ignore all
- }
- stock PlayerIgnoreAllButHiddenCP(playerid, hcpid, ignorerate=-1){
- for(new h=1; h < hcpsT; h++)
- {
- if(h == hcpid) continue;
- playerIgnoreHiddenCPS[playerid][h] = ignorerate;
- }
- playerIgnoreHiddenCPS[playerid][INVALID_HCP] = 0; //don't ignore all
- }
- stock SetHiddenCPMultiStop(hcpid, bool:mstop=true){
- hiddenCPS[hcpid][multistop] = mstop;
- }
- stock AllPlayersIgnoreHiddenCP(hcpid, ignorerate=-1){
- for(new playerid=0; playerid < MAX_PLAYERS; playerid++)
- {
- PlayerIgnoreHiddenCP(playerid, hcpid, ignorerate);
- }
- }
- stock DisableHiddenCP(hcpid){
- AllPlayersIgnoreHiddenCP(hcpid);
- }
- //GET/SET
- stock GetCentreofHiddenCP(hcpid, &Float:X, &Float:Y, &Float:Z){
- switch (hiddenCPS[hcpid][hcp_type])
- {
- case INVALID_HCP: return 0;
- case SQUARE_HCP:
- {
- X = middleof(hiddenCPS[hcpid][hcp_X], hiddenCPS[hcpid][hcp_X2_WR]);
- Y = middleof(hiddenCPS[hcpid][hcp_Y], hiddenCPS[hcpid][hcp_Y2_L]);
- Z = 0.0;
- }
- case CUBE_HCP:
- {
- X = middleof(hiddenCPS[hcpid][hcp_X], hiddenCPS[hcpid][hcp_X2_WR]);
- Y = middleof(hiddenCPS[hcpid][hcp_Y], hiddenCPS[hcpid][hcp_Y2_L]);
- Z = middleof(hiddenCPS[hcpid][hcp_Z], hiddenCPS[hcpid][hcp_Z2]);
- }
- case CIRCLE_HCP:
- {
- X = hcp_X,
- Y = hcp_Y,
- Z = 0.0;
- }
- case CYLINDER_HCP:
- {
- X = hcp_X,
- Y = hcp_Y,
- Z = middleof(hiddenCPS[hcpid][hcp_Z], hiddenCPS[hcpid][hcp_Z2]);
- }
- case SPHERE_HCP:
- {
- X = hiddenCPS[hcpid][hcp_X];
- Y = hiddenCPS[hcpid][hcp_Y];
- Z = hiddenCPS[hcpid][hcp_Z];
- }
- }
- return 1;
- }
- //TIMER
- forward HiddenCPTimer();
- public HiddenCPTimer(){
- //SendClientMessageToAll(0xFF0000AA, "HiddenCPTimerTest");
- new playerhcpid = INVALID_HCP, bool:callback, bool:isStopped;
- for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
- {
- if(!IsPlayerConnected(playerid)) continue;
- new Float:X, Float:Y, Float:Z;
- GetPlayerPos(playerid, X, Y, Z);
- playerhcpid = playerhcp[playerid][ENTER];
- if(playerhcpid != INVALID_HCP)
- {
- callback = (playerIgnoreHiddenCPS[playerid][INVALID_HCP] == 0 && playerIgnoreHiddenCPS[playerid][playerhcpid] == 0);
- printf("current callback %d", callback);
- if(IsPlayerInHiddenCP(playerid, playerhcpid))
- {
- isStopped = IsPlayerStopped(playerid);
- if(playerhcp[playerid][STOP] == INVALID_HCP && isStopped)
- {
- playerhcp[playerid][STOP] = playerhcpid;
- if(callback) OnPlayerStopInHiddenCheckPoint(playerid, playerhcpid);
- SendClientMessage(playerid, 0xFF0000AA, "You have stopped in checkpoint");
- }else if(hiddenCPS[playerhcpid][multistop] && playerhcp[playerid][STOP] != INVALID_HCP && !isStopped)
- {
- playerhcp[playerid][STOP] = INVALID_HCP;
- SendClientMessage(playerid, 0xFF0000AA, "You have moved again in checkpoint ");
- if(callback) OnPlayerMoveInHiddenCheckPoint(playerid, playerhcpid);
- }
- return 1;//Player is still in cp
- }else{
- if(callback) OnPlayerExitHiddenCheckPoint(playerid, playerhcpid);
- SendClientMessage(playerid, 0xFF0000AA, "You have left checkpoint");
- if(playerIgnoreHiddenCPS[playerid][INVALID_HCP] > 0) playerIgnoreHiddenCPS[playerid][INVALID_HCP]--;
- if(playerIgnoreHiddenCPS[playerid][playerhcpid] > 0) playerIgnoreHiddenCPS[playerid][playerhcpid]--;
- playerhcp[playerid][ENTER] = INVALID_HCP;
- playerhcp[playerid][STOP] = INVALID_HCP;
- }
- continue;
- }
- for(new hcpid=1; hcpid<hcpsT; hcpid++)
- {
- if(IsPlayerInHiddenCP(playerid,hcpid))
- {
- callback = (playerIgnoreHiddenCPS[playerid][INVALID_HCP] == 0 && playerIgnoreHiddenCPS[playerid][hcpid] == 0);
- printf("current callback %d", callback);
- playerhcp[playerid][ENTER] = hcpid;
- if(callback) OnPlayerEnterHiddenCheckPoint(playerid, hcpid);
- SendClientMessage(playerid, 0xFF0000AA, "You have entered checkpoint hcpid");
- if(IsPlayerStopped(playerid))
- {
- playerhcp[playerid][STOP] = hcpid;
- if(callback) OnPlayerStopInHiddenCheckPoint(playerid, hcpid);
- SendClientMessage(playerid, 0xFF0000AA, "You have stopped in checkpoint hcpid");
- }
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment