[Include] Checkpoint.inc - More checkpoint functions and features.
#1

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.
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);
Callbacks
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);
Hooked Callbacks
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);
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. 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;
}
Reply
#2

Nice one.
Reply
#3

nice job bro
keep it up
Reply
#4

New update! Version 1.1.0
pawn Код:
// Changelog 1.1.0 - 15.11.2015, 12:29 (Timezone: UTC+1)
Added two new callbacks, OnPlayerCheckpointSet and OnPlayerCheckpointDisable.
You can find description on the two callbacks inside the include file.
Reply
#5

Nice!
Reply
#6

New update! Version 1.2.0
pawn Код:
// Changelog 1.2.0 - 21.11.2015, 03:14PM (Timezone: GMT+1)

// New functions:
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:GetPlayerDistanceFromRaceCheckpoint(playerid);

// New callbacks:
native OnPlayerRaceCheckpointSet(playerid);
native OnPlayerRaceCheckpointDisable(playerid)

// New hooked callbacks:
native OnPlayerEnterRaceCheckpoint(playerid);
native OnPlayerLeaveRaceCheckpoint(playerid)
You can find description on all the functions and callbacks in the include file.

Hotfix! Version 1.2.1
pawn Код:
// Changelog 1.2.1 - 21.11.2015, 04:26PM (Timezone: GMT+1)
Fixed warnings on compile.
Reply
#7

Took a peak and this stood out.

Код:
if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid) || playerid == INVALID_PLAYER_ID || 0 > playerid || playerid > MAX_PLAYERS)
Absolutely no point of these checks, in those cases IsPlayerConnected() is going to return 0 so why even bother making three useless checks ?
Код:
playerid == INVALID_PLAYER_ID || 0 > playerid || playerid > MAX_PLAYERS
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Took a peak and this stood out.

Код:
if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid) || playerid == INVALID_PLAYER_ID || 0 > playerid || playerid > MAX_PLAYERS)
Absolutely no point of these checks, in those cases IsPlayerConnected() is going to return 0 so why even bother making three useless checks ?
Код:
playerid == INVALID_PLAYER_ID || 0 > playerid || playerid > MAX_PLAYERS
You are right, I don't know what I was thinking when I did that. Fixed in version 1.2.2. Thanks for pointing it out.
Reply
#9

Код:
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(449) : error 075: input line too long (after substitutions)
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(450) : error 017: undefined symbol "c"
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(451) : error 017: undefined symbol "pSize"
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(451) : warning 217: loose indentation
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(451) : error 029: invalid expression, assumed zero
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(451) : error 029: invalid expression, assumed zero
C:\Users\startklaar\Desktop\LvCnr\pawno\include\lvcnr/Checkpoint.inc(451) : fatal error 107: too many error messages on one line
Hmm i've checked the code but idk whats wrong hehe

Код:
445 :stock IsValidRaceCheckpoint(playerid) {
446:
447:	if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
448:		return 0;
449:
450:	if(playerRaceCheckpointData[playerid][cpId] == INVALID_CHECKPOINT_ID && playerRaceCheckpointData[playerid][cpType] == INVALID_CHECKPOINT_ID && playerRaceCheckpointData[playerid][cpX] == 0.0000 && playerRaceCheckpointData[playerid][cpY] == 0.0000 && playerRaceCheckpointData[playerid][cpZ] == 0.0000 && playerRaceCheckpointData[playerid][cpNextX] == 0.0000 && playerRaceCheckpointData[playerid][cpNextY] == 0.0000 && playerRaceCheckpointData[playerid][cpNextZ] == 0.0000 && playerRaceCheckpointData[playerid][cpSize] == 0.0000)

451:		return 0;
452:
453:	return 1;
454: }
Reply
#10

Use Zeex's compiler to increase the max input line length.

https://sampforum.blast.hk/showthread.php?pid=2768123#pid2768123
Reply
#11

Lol, thats funny, because i put it on a blank script, nothing changed yet.
Only added this include, and comes up with a few errors :3
To bad tho..
Reply
#12

Not bad, could be a ton of use to me!
Reply
#13

Good job i like it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)