14.11.2015, 20:59
(
Последний раз редактировалось AnthonyDaSexy; 01.08.2016 в 15:51.
)
Checkpoint.inc
The idea was inspired by this include: https://sampforum.blast.hk/showthread.php?tid=251483. It is however recreated from scratch and uses static variables instead of PVars, also some of the functions are gone as I saw no use for them, but can be added if the demand is high. The checkpoints are completely serversided and can be assigned to an id for easier management in OnPlayerEnterCheckpoint. Assigning an id to the checkpoint is optional but highly recommended. All of your old checkpoint codes are compatible with a slight modifiaction, look for the OnPlayerEnterCheckpoint callback in the example script given at the end of this thread.
Functions
List of all the functions within the include file. Full explanation on each of the functions can be found in the include file.
Callbacks
These callbacks have been added to the include and can be very useful.
Hooked Callbacks
These callbacks have been hooked to detect if the checkpoint is valid.
Download Links
You can either download this include from solidfiles or copy it from pastebin. Credits
List of names that is worth given credits to for this include.
This is an example script to demonstrate the usage of the include. It has been written as a filterscript so it is easily compilable and quickly to setup on any server.
The idea was inspired by this include: https://sampforum.blast.hk/showthread.php?tid=251483. It is however recreated from scratch and uses static variables instead of PVars, also some of the functions are gone as I saw no use for them, but can be added if the demand is high. The checkpoints are completely serversided and can be assigned to an id for easier management in OnPlayerEnterCheckpoint. Assigning an id to the checkpoint is optional but highly recommended. All of your old checkpoint codes are compatible with a slight modifiaction, look for the OnPlayerEnterCheckpoint callback in the example script given at the end of this thread.
Functions
List of all the functions within the include file. Full explanation on each of the functions can be found in the include file.
pawn Код:
native SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
native DisablePlayerCheckpoint(playerid);
native IsValidCheckpoint(playerid);
native GetPlayerCheckpointId(playerid);
native GetPlayerCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
native GetPlayerCheckpointSize(playerid, &Float:size);
native IsPlayerInRangeOfCheckpoint(playerid, Float:range);
native Float:GetPlayerDistanceFromCheckpoint(playerid);
// Added in version 1.2.0, will not work in earlier versions.
native SetPlayerRaceCheckpoint(playerid, type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
native DisablePlayerRaceCheckpoint(playerid);
native IsValidRaceCheckpoint(playerid);
native GetPlayerRaceCheckpointId(playerid);
native GetPlayerRaceCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
native GetPlayerRaceCheckpointNextPos(playerid, &Float:nextx, &Float:nexty, &Float:nextz);
native GetPlayerRaceCheckpointSize(playerid, &Float:size);
native IsPlayerInRangeOfRaceCheckpoint(playerid, Float:range);
native Float:GetDistanceFromRaceCheckpoint(playerid);
These callbacks have been added to the include and can be very useful.
pawn Код:
// Added in version 1.1.0, will not work in earlier versions.
native OnPlayerCheckpointSet(playerid);
native OnPlayerCheckpointDisable(playerid);
// Added in version 1.2.0, will not work in earlier versions.
native OnPlayerRaceCheckpointSet(playerid);
native OnPlayerRaceCheckpointDisable(playerid);
These callbacks have been hooked to detect if the checkpoint is valid.
pawn Код:
native OnPlayerConnect(playerid);
native OnPlayerEnterCheckpoint(playerid);
native OnPlayerLeaveCheckpoint(playerid);
// Added in version 1.2.0.
native OnPlayerEnterRaceCheckpoint(playerid);
native OnPlayerLeaveRaceCheckpoint(playerid);
You can either download this include from solidfiles or copy it from pastebin. Credits
List of names that is worth given credits to for this include.
- SA:MP Team - For creating and updating SA:MP obviously.
- Ash. - The include was inspired by his.
- Yashas - His modified version of zcmd (izcmd) was used in the example script.
This is an example script to demonstrate the usage of the include. It has been written as a filterscript so it is easily compilable and quickly to setup on any server.
pawn Код:
#define FILTERSCRIPT
#include <a_samp>
#undef MAX_PLAYERS
#define MAX_PLAYERS 50
#include <izcmd>
#include <checkpoint>
#define CHECKPOINT_OLD_1 0
#define CHECKPOINT_OLD_2 1
enum {
CHECKPOINT_UNUSED,
CHECKPOINT_DEAGLE,
CHECKPOINT_M4,
CHECKPOINT_CASH
};
new playerCheckpoint[MAX_PLAYERS] = {-1, ...};
public OnFilterScriptInit() {
print("Checkpoint:Example script initialized.");
for(new i = GetPlayerPoolSize(); i != -1; i--) {
if(!IsPlayerConnected(i) || IsPlayerNPC(i))
continue;
OnPlayerConnect(i);
}
return 1;
}
public OnFilterScriptExit() {
print("Checkpoint: Example script exited.");
for(new i = GetPlayerPoolSize(); i != -1; i--) {
if(!IsPlayerConnected(i) || IsPlayerNPC(i))
continue;
OnPlayerDisconnect(i, -1);
}
return 1;
}
public OnPlayerConnect(playerid) {
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Welcome, this server is running the example script.");
playerCheckpoint[playerid] = -1;
return 1;
}
public OnPlayerDisconnect(playerid, reason) {
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Bye, see you later.");
DisablePlayerCheckpoint(playerid);
return 1;
}
CMD:oldcp1(playerid, params[]) {
if(!SetPlayerCheckpoint(playerid, 5.0000, 5.0000, 2.0000, 5))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, could not set the checkpoint.");
playerCheckpoint[playerid] = CHECKPOINT_OLD_1;
return CMD_SUCCESS;
}
CMD:oldcp2(playerid, params[]) {
if(!SetPlayerCheckpoint(playerid, 0.0000, 0.0000, 2.0000, 5))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, could not set the checkpoint.");
playerCheckpoint[playerid] = CHECKPOINT_OLD_2;
return CMD_SUCCESS;
}
CMD:deagle(playerid, params[]) {
if(!SetPlayerCheckpoint(playerid, 20.0000, 20.0000, 2.0000, 5, CHECKPOINT_DEAGLE))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, could not set the checkpoint.");
return CMD_SUCCESS;
}
CMD:m4(playerid, params[]) {
if(!SetPlayerCheckpoint(playerid, 15.0000, 15.0000, 2.0000, 5, CHECKPOINT_M4))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, could not set the checkpoint.");
return CMD_SUCCESS;
}
CMD:rich(playerid, params[]) {
if(!SetPlayerCheckpoint(playerid, 10.0000, 10.0000, 2.0000, 5, CHECKPOINT_CASH))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, could not set the checkpoint.");
return CMD_SUCCESS;
}
CMD:cphelp(playerid, params[]) {
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{696969}Checkpoint Help", "{1E90FF}==================================================\n{696969}Checkpoints:\n{FFFFFF}* /oldcp1, /oldcp2, /deagle, /m4, /rich\n\n{696969}Commands:\n{FFFFFF}* /cpdisable, /cpvalid, /cppos, /cpsize, /cprange, /cpdistance\n{1E90FF}==================================================", "Ok", "");
return CMD_SUCCESS;
}
CMD:cpdisable(playerid, params[]) {
if(!DisablePlayerCheckpoint(playerid))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, no checkpoint has been set.");
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Successfully disabled the checkpoint.");
return CMD_SUCCESS;
}
CMD:cpvalid(playerid, params[]) {
if(!IsValidCheckpoint(playerid))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, checkpoint is invalid.");
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Success, checkpoint is valid.");
return CMD_SUCCESS;
}
CMD:cppos(playerid, params[]) {
new
Float:x,
Float:y,
Float:z
;
if(!GetPlayerCheckpointPos(playerid, x, y, z))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, no checkpoint has been set.");
new
cpString[80 + 1]
;
format(cpString, sizeof(cpString), "{1E90FF}Checkpoint:{BEBEBE} x = %f | y = %f | z = %f.", x, y, z);
SendClientMessage(playerid, -1, cpString);
return CMD_SUCCESS;
}
CMD:cpsize(playerid, params[]) {
new
Float:size
;
if(!GetPlayerCheckpointSize(playerid, size))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, no checkpoint has been set.");
new
cpString[64 + 1]
;
format(cpString, sizeof(cpString), "{1E90FF}Checkpoint:{BEBEBE} The checkpoint size is: %f.", size);
SendClientMessage(playerid, -1, cpString);
return CMD_SUCCESS;
}
CMD:cprange(playerid, params[]) {
if(!IsValidCheckpoint(playerid))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, no checkpoint has been set.");
if(!IsPlayerInRangeOfCheckpoint(playerid, 10.0000))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, not within 10 yards of the checkpoint.");
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Success, you are within 10 yards of the checkpoint.");
return CMD_SUCCESS;
}
CMD:cpdistance(playerid, params[]) {
new
Float:distance
;
if(!(distance = GetPlayerDistanceFromCheckpoint(playerid)))
return SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Error, no checkpoint has been set.");
new
cpString[73 + 1]
;
format(cpString, sizeof(cpString), "{1E90FF}Checkpoint:{BEBEBE} Distance to checkpoint is %.0f meters.", distance);
SendClientMessage(playerid, -1, cpString);
return CMD_SUCCESS;
}
public OnPlayerEnterCheckpoint(playerid) {
new
checkpointid
;
if((checkpointid = GetPlayerCheckpointId(playerid)) == CHECKPOINT_UNUSED) {
// Old checkpoint code here.
if(IsPlayerInRangeOfPoint(playerid, 5.0000, 5.0000, 5.0000, 2.0000) && playerCheckpoint[playerid] == CHECKPOINT_OLD_1) {
SetPlayerHealth(playerid, 100.0);
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} You have been healed.");
}
else if(IsPlayerInRangeOfPoint(playerid, 5.0000, 0.0000, 0.0000, 2.0000) && playerCheckpoint[playerid] == CHECKPOINT_OLD_2) {
SetPlayerArmour(playerid, 99.0);
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} You have received armour.");
}
DisablePlayerCheckpoint(playerid);
playerCheckpoint[playerid] = -1;
return 1;
}
// New checkpoint code here.
switch(checkpointid)
{
case CHECKPOINT_DEAGLE:
{
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Enjoy your Deagle with 9999 ammo.");
GivePlayerWeapon(playerid, WEAPON_DEAGLE, 9999);
DisablePlayerCheckpoint(playerid);
return 1;
}
case CHECKPOINT_M4:
{
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} Enjoy your M4 with 9999 ammo.");
GivePlayerWeapon(playerid, WEAPON_M4, 9999);
DisablePlayerCheckpoint(playerid);
return 1;
}
case CHECKPOINT_CASH:
{
SendClientMessage(playerid, -1, "{1E90FF}Checkpoint:{BEBEBE} You are now $1,000,000 richer.");
GivePlayerMoney(playerid, 1000000);
DisablePlayerCheckpoint(playerid);
return 1;
}
}
return 0;
}