Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Checkpoint Control by Rafelder
- (c) by Rafelder
- You're not allowed to edit the code without permission of me!
- */
- /*
- native CreateCheckpoint(Float:X, Float:Y, Float:Z, Float:size = 2.0, Float:distance = 9999.9, name[MAX_NAME_CHAR] = " ", bool:enable = true)
- native DestroyCheckpoint(cpid)
- native IsValidCheckpoint(cpid)
- native EnabledCheckpointForPlayer(playerid, cpid, bool:enable) - cpid -1 = all
- native EnabledCheckpointForAll(cpid, bool:enable) - cpid -1 = all
- native SetCheckpointPos(cpid, Float:X, Float:Y, Float:Z) - cpid -1 = all
- native SetCheckpointSize(cpid, Float:size = 2.0) - cpid -1 = all
- native SetCheckpointSpawnDistance(cpid, Float:distance = 9999.9) - cpid -1 = all
- native SetCheckpointName(cpid, name[] = " ") - cpid -1 = all
- native GetCheckpointPos(cpid, &Float:X, &Float:Y, &Float:Z)
- native GetCheckpointSize(cpid)
- native GetCheckpointSpawnDistance(cpid)
- native GetCheckpointName(cpid)
- native IsCheckpointEnabledForPlayer(playerid, cpid) - cpid -1 = all
- native IsCheckpointEnabledForAll(cpid) - cpid -1 = all
- native IsPlayerInAnyCheckpoint(playerid) - playerid -1 = all
- native IsPlayerInCheckpoint(playerid, cpid) - playerid -1 = all
- native GetPlayerCheckpoint(playerid)
- native CPC_OnPlayerConnect(playerid)
- native CPC_OnPlayerEnterCheckpoint(playerid)
- native CPC_OnPlayerLeaveCheckpoint(playerid)
- Callbacks:
- native OnPlayerEnterCheckpointEx(playerid, cpid, name[])
- native OnPlayerLeaveCheckpointEx(playerid, cpid, name[])
- */
- #define MAX_CHECKPOINTS 1024
- #define MAX_NAME_CHAR 64
- enum CP_Info
- {
- bool:Enabled,
- Float:Xc,
- Float:Yc,
- Float:Zc,
- Float:sizec,
- Float:disc,
- namec[MAX_NAME_CHAR]
- }
- new Checkpoint[MAX_CHECKPOINTS][CP_Info];
- enum PL_Info
- {
- bool:Enabled
- }
- new PlayerCPInfo[MAX_PLAYERS][MAX_CHECKPOINTS][PL_Info];
- new LastCheckpointEnter[MAX_PLAYERS];
- new LastCheckpointLeave[MAX_PLAYERS];
- new CheckpointP[MAX_PLAYERS];
- new Count[MAX_CHECKPOINTS];
- new CP, Timer_Enable;
- forward CheckpointUpdate();
- forward OnPlayerEnterCheckpointEx(playerid, cpid, name[]);
- forward OnPlayerLeaveCheckpointEx(playerid, cpid, name[]);
- public CheckpointUpdate()
- {
- new Checkp, Checkp2, Float:dist;
- for(new playerid=0; playerid<1; playerid++)
- {
- if(!IsPlayerInAnyCheckpoint(playerid))
- {
- LastCheckpointEnter[playerid] = -1;
- LastCheckpointLeave[playerid] = -1;
- }
- DisablePlayerCheckpoint(playerid);
- if(GetEnabledCheckpoints(playerid) != 0)
- {
- Checkp = GetNearestCheckpoint(playerid, dist);
- if(dist <= Checkpoint[Checkp][disc])
- {
- SetPlayerCheckpoint(playerid, Checkpoint[Checkp][Xc], Checkpoint[Checkp][Yc], Checkpoint[Checkp][Zc], Checkpoint[Checkp][sizec]);
- CheckpointP[playerid] = Checkp;
- }
- else
- {
- Checkp2 = GetNearestCheckpoint(playerid, dist, Checkp);
- if(dist <= Checkpoint[Checkp2][disc])
- {
- SetPlayerCheckpoint(playerid, Checkpoint[Checkp2][Xc], Checkpoint[Checkp2][Yc], Checkpoint[Checkp2][Zc], Checkpoint[Checkp2][sizec]);
- CheckpointP[playerid] = Checkp2;
- }
- }
- }
- }
- return 1;
- }
- stock CreateCheckpoint(Float:X, Float:Y, Float:Z, Float:size = 2.0, Float:distance = 9999.9, name[MAX_NAME_CHAR] = " ", bool:enable = true)
- {
- CP = GetFirstArraySize(Count, sizeof(Count), 0);
- if(CP == MAX_CHECKPOINTS) return 0;
- if(Timer_Enable == 0)
- {
- SetTimer("CheckpointUpdate", 200, 1);
- Timer_Enable = 1;
- }
- Count[CP] = 1;
- Checkpoint[CP][Enabled] = true;
- Checkpoint[CP][Xc] = X;
- Checkpoint[CP][Yc] = Y;
- Checkpoint[CP][Zc] = Z;
- Checkpoint[CP][sizec] = size;
- Checkpoint[CP][disc] = distance;
- format(Checkpoint[CP][namec], MAX_NAME_CHAR, "%s", name);
- EnableCheckpointForAll(CP, enable);
- return CP;
- }
- stock DestroyCheckpoint(cpid)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- Count[cpid] = 0;
- Checkpoint[CP][Enabled] = false;
- Checkpoint[CP][Xc] = 0.0;
- Checkpoint[CP][Yc] = 0.0;
- Checkpoint[CP][Zc] = 0.0;
- Checkpoint[CP][sizec] = 0.0;
- Checkpoint[CP][disc] = 0.0;
- format(Checkpoint[CP][namec], MAX_NAME_CHAR, "%s", " ");
- Count[cpid] = 0;
- return 1;
- }
- stock IsValidCheckpoint(cpid)
- {
- return Checkpoint[cpid][Enabled];
- }
- stock SetCheckpointPos(cpid, Float:X, Float:Y, Float:Z)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- Checkpoint[cpid][Xc] = X;
- Checkpoint[cpid][Yc] = Y;
- Checkpoint[cpid][Zc] = Z;
- }
- else
- {
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- Checkpoint[i][Xc] = X;
- Checkpoint[i][Yc] = Y;
- Checkpoint[i][Zc] = Z;
- }
- }
- return 1;
- }
- stock GetCheckpointPos(cpid, &Float:X, &Float:Y, &Float:Z)
- {
- X = Checkpoint[cpid][Xc];
- Y = Checkpoint[cpid][Yc];
- Z = Checkpoint[cpid][Zc];
- }
- stock SetCheckpointSize(cpid, Float:size = 2.0)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- Checkpoint[cpid][sizec] = size;
- }
- else
- {
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- Checkpoint[i][sizec] = size;
- }
- }
- return 1;
- }
- stock GetCheckpointSize(cpid)
- {
- return Checkpoint[cpid][sizec];
- }
- stock SetCheckpointSpawnDistance(cpid, Float:distance = 9999.9)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- Checkpoint[cpid][disc] = distance;
- }
- else
- {
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- Checkpoint[i][disc] = distance;
- }
- }
- return 1;
- }
- stock GetCheckpointSpawnDistance(cpid)
- {
- return Checkpoint[cpid][disc];
- }
- stock SetCheckpointName(cpid, name[] = " ")
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- format(Checkpoint[cpid][namec], MAX_NAME_CHAR, "%s", name);
- }
- else
- {
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- format(Checkpoint[i][namec], MAX_NAME_CHAR, "%s", name);
- }
- }
- return 1;
- }
- stock GetCheckpointName(cpid)
- {
- return Checkpoint[cpid][name];
- }
- stock GetPlayerCheckpoint(playerid)
- {
- if(IsPlayerInCheckpoint(playerid)) return CheckpointP[playerid];
- return -1;
- }
- stock IsPlayerInCheckpointEx(playerid, cpid)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- if(playerid != -1)
- {
- if(IsPlayerInCheckpoint(playerid) && CheckpointP[playerid] == cpid) return 1;
- return 0;
- }
- else
- {
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(!IsPlayerInCheckpoint(i) || CheckpointP[i] != cpid) return 0;
- }
- return 1;
- }
- }
- stock IsPlayerInAnyCheckpoint(playerid)
- {
- if(playerid != -1)
- {
- if(IsPlayerInCheckpoint(playerid)) return 1;
- return 0;
- }
- else
- {
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(!IsPlayerInCheckpoint(i)) return 0;
- }
- return 1;
- }
- }
- stock EnableCheckpointForPlayer(playerid, cpid, bool:enable)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- PlayerCPInfo[playerid][cpid][Enabled] = enable;
- }
- else
- {
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- PlayerCPInfo[playerid][i][Enabled] = enable;
- }
- }
- return 1;
- }
- stock EnableCheckpointForAll(cpid, bool:enable)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- PlayerCPInfo[i][cpid][Enabled] = enable;
- }
- }
- else
- {
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- for(new a=0; a<MAX_CHECKPOINTS; a++)
- {
- PlayerCPInfo[i][a][Enabled] = enable;
- }
- }
- }
- return 1;
- }
- stock IsCheckpointEnabledForPlayer(playerid, cpid)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- return PlayerCPInfo[playerid][cpid][Enabled];
- }
- else
- {
- if(GetEnabledCheckpoints(playerid) == GetValidCheckpoints()) return 1;
- }
- return 0;
- }
- stock IsCheckpointEnabledForAll(cpid)
- {
- if(cpid != -1)
- {
- if(!IsValidCheckpoint(cpid)) return 0;
- for(new i=0; i<MAX_PLAYERS(); i++)
- {
- if(PlayerCPInfo[i][cpid][Enabled] == false) return 0;
- }
- return 1;
- }
- else
- {
- if(GetEnabledCheckpoints(-1) == (GetValidCheckpoints()*GetOnlinePlayers())) return 1;
- }
- return 0;
- }
- stock CPC_OnPlayerEnterCheckpoint(playerid)
- {
- if(CheckpointP[playerid] != LastCheckpointEnter[playerid])
- {
- LastCheckpointEnter[playerid] = CheckpointP[playerid];
- OnPlayerEnterCheckpointEx(playerid, CheckpointP[playerid], Checkpoint[CheckpointP[playerid]][namec]);
- }
- }
- stock CPC_OnPlayerLeaveCheckpoint(playerid)
- {
- if(CheckpointP[playerid] != LastCheckpointLeave[playerid])
- {
- LastCheckpointLeave[playerid] = CheckpointP[playerid];
- OnPlayerLeaveCheckpointEx(playerid, CheckpointP[playerid], Checkpoint[CheckpointP[playerid]][namec]);
- }
- }
- stock CPC_OnPlayerConnect(playerid)
- {
- LastCheckpointEnter[playerid] = -1;
- LastCheckpointLeave[playerid] = -1;
- EnableCheckpointForPlayer(playerid, -1, true);
- CheckpointP[playerid] = -1;
- }
- stock GetOnlinePlayers()
- {
- new Counter;
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i)) Counter++;
- }
- return Counter;
- }
- stock GetValidCheckpoints()
- {
- new Counter = 0;
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- if(IsValidCheckpoint(i)) Counter++;
- }
- return Counter;
- }
- stock GetEnabledCheckpoints(playerid)
- {
- if(playerid != -1)
- {
- new Counter = 0;
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- if(IsValidCheckpoint(i))
- {
- if(PlayerCPInfo[playerid][i][Enabled] == true) Counter++;
- }
- }
- return Counter;
- }
- else
- {
- new Counter;
- for(new i=0; i<GetOnlinePlayers(); i++)
- {
- for(new a=0; a<MAX_CHECKPOINTS; a++)
- {
- if(IsValidCheckpoint(i))
- {
- if(PlayerCPInfo[i][a][Enabled] == true) Counter++;
- }
- }
- }
- return Counter;
- }
- }
- stock Float:GetDistanceToCheckpoint(playerid, cpid)
- {
- new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
- GetPlayerPos(playerid, x1, y1, z1);
- GetCheckpointPos(cpid, x2, y2, z2);
- return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- }
- stock GetNearestCheckpoint(playerid, &Float:distance, notallowed = -1)
- {
- new Float:dis = 9999999.9, Float:distancec, nearest;
- for(new i=0; i<MAX_CHECKPOINTS; i++)
- {
- if(IsValidCheckpoint(i))
- {
- if(IsCheckpointEnabledForPlayer(playerid, i))
- {
- if(i != notallowed)
- {
- distancec = GetDistanceToCheckpoint(playerid, i);
- if(distancec < dis) {dis = distancec, nearest = i;}
- }
- }
- }
- }
- distance = dis;
- return nearest;
- }
- stock GetFirstArraySize(array[], arraysize, size)
- {
- for(new i=0; i<arraysize; i++)
- {
- if(array[i] == size) return i;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement