SA-MP Forums Archive
Checkpoints - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Checkpoints (/showthread.php?tid=623879)



Checkpoints - JaKe Elite - 07.12.2016

So I have this arrays of checkpoints I have made. How can I use them under the callback OnPlayerEnterRaceCheckpoint (detecting which is the last checkpoint)

PHP код:
new const Float:g_arrCheckpoints[][] = { 
    {
3199.9063, -1603.036911.0098},
    {
3199.8782, -1577.855511.2266},
    {
3199.8042, -1554.796511.0993},
    {
3199.8364, -1544.165611.0098},
    {
3200.2439, -1533.098611.0098},
    {
3222.5374, -1533.317711.2266},
    {
3241.9172, -1533.023111.0098},
    {
3242.0122, -1516.835911.6601},
    {
3241.9187, -1501.17296.0084},
    {
3242.0002, -1486.09426.2266},
    {
3241.7668, -1472.20897.3302},
    {
3241.9143, -1463.218910.5974},
    {
3241.7896, -1452.305914.5464},
    {
3241.8970, -1436.910020.2788},
    {
3241.7861, -1427.054811.2403},
    {
3241.5625, -1407.291011.7712},
    {
3217.9495, -1407.560411.0993},
    {
3217.0859, -1394.650811.0084},
    {
3217.6970, -1382.260411.0084},
    {
3241.9387, -1382.033110.9599}
}; 



Re: Checkpoints - jlalt - 07.12.2016

You can use sizeof to get size of an arry so you would know what is in it on last or to check last data in it saved at which slot...

https://sampwiki.blast.hk/wiki/Sizeof


Re: Checkpoints - JaKe Elite - 07.12.2016

I tried doing this

PHP код:
public OnPlayerEnterRaceCheckpoint(playerid)
{
    
gCheckpoint[playerid] ++;

    if (
gCheckpoint[playerid] < sizeof(g_arrCheckpoints))
    {
        
SetPlayerRaceCheckpoint(playerid0g_arrCheckpoints[gCheckpoint[playerid]][0], g_arrCheckpoints[gCheckpoint[playerid]][1], g_arrCheckpoints[gCheckpoint[playerid]][2], g_arrCheckpoints[gCheckpoint[playerid]+1][0], g_arrCheckpoints[gCheckpoint[playerid]+1][1], g_arrCheckpoints[gCheckpoint[playerid]+1][2], 5.0);
    }
    else
    {
        
SetPlayerRaceCheckpoint(playerid1g_arrCheckpoints[gCheckpoint[playerid]][0], g_arrCheckpoints[gCheckpoint[playerid]][1], g_arrCheckpoints[gCheckpoint[playerid]][2], 0.00.00.05.0);
    }
    return 
1;

But it gave me crashdetector warnings;

Код:
[12:20:29] [debug] Run time error 4: "Array index out of bounds"
[12:20:29] [debug]  Attempted to read/write array element at index 20 in array of size 20
[12:20:29] [debug] AMX backtrace:
[12:20:29] [debug] #0 000249f4 in ?? (... <1 argument>) at C:\Documents and Settings\Ramos\My Documents\Pawn Scripting\gamemodes\3.pwn:923
[12:20:29] [debug] #1 00008760 in public OnPlayerEnterRaceCheckpoint (playerid=0) at C:\Documents and Settings\Ramos\My Documents\Pawn Scripting\pawno\include\YSI\y_hooks/impl.inc:1232



Re: Checkpoints - Konstantinos - 07.12.2016

You should first check and then increase. I had an example for a single race: http://forum.sa-mp.com/showpost.php?...02&postcount=2


Re: Checkpoints - JaKe Elite - 07.12.2016

Worked, Thanks Konstantinos & jlait