Loop & Case (doesn't work properly)
#1

I've been developing a CnR Server, and I wanted my code as optimize and simplest way it could be, I'm trying to use a loop & a case, but it doesn't work properly for some reason

Everytime I enter a checkpoint, it sends me to this location
pawn Код:
case 47:
{
    TogglePlayerControllable(playerid, 0);
    GameTextForPlayer(playerid, "- Objects Loading -~n~ - Please Wait -", 3000, 0);
    LoadObjectForPlayer(playerid);
    SetPlayerVirtualWorld(playerid, 1);
    SetPlayerPos(playerid,2181.0850,-1009.9630,1021.6880+1);
    SetCameraBehindPlayer(playerid);
}
Global Variable
pawn Код:
new
    eCheckpoints[ 49 ]
;
OnPlayerEnterDynamicCP Callback
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    for(new o = 0; o < sizeof(eCheckpoints); o++)
    {
        switch(eCheckpoints[o])
        {
            case 0:
            {
                SetPlayerInterior(playerid, 10);
                SetPlayerPos(playerid, 2017.3734,1017.7369,996.8750);
                SetPlayerFacingAngle(playerid, 93.6272);
                SetCameraBehindPlayer(playerid);
            }
            case 1:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(playerid, -1548.5518,1054.6681,7.1875);
                SetPlayerFacingAngle(playerid, 96.1336);
                SetCameraBehindPlayer(playerid);
            }
            case 2:
            {
                SetPlayerInterior(playerid, 3);
                SetPlayerVirtualWorld(playerid, 2);
                SetPlayerPos(playerid, 418.652984,-82.639793,1001.804687);
                SetCameraBehindPlayer(playerid);
            }
            case 3:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1566.500488,1127.886596,7.187500);
            }
            case 4:
            {
                SetPlayerInterior(playerid, 16);
                SetPlayerPos(playerid,-201.232803, -22.764419, 1002.273437);
                SetCameraBehindPlayer(playerid);
            }
            case 5:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(playerid, -1567.018920,1113.483642,7.187500);
            }
            case 6:
            {
                SetPlayerInterior(playerid, 5);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 371.322540,-130.185256,1001.492187);
                SetCameraBehindPlayer(playerid);
            }
            case 7:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid,-1724.202026,1360.259155,7.187500);
                SetCameraBehindPlayer(playerid);
            }
            case 8:
            {
                SetPlayerInterior(playerid, 5);
                SetPlayerVirtualWorld(playerid, 2);
                SetPlayerPos(playerid, 371.322540,-130.185256,1001.492187);
                SetCameraBehindPlayer(playerid);
            }
            case 9:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1805.955566,943.366821,24.890625);
                SetCameraBehindPlayer(playerid);
            }
            case 10:
            {
                SetPlayerInterior(playerid,10);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid,365.353576,-73.941848,1001.507812);
                SetCameraBehindPlayer(playerid);
            }
            case 11:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2358.691162,1005.521423,50.695312);
                SetCameraBehindPlayer(playerid);
            }
            case 12:
            {
                SetPlayerInterior(playerid,10);
                SetPlayerVirtualWorld(playerid, 2);
                SetPlayerPos(playerid, 365.353576,-73.941848,1001.507812);
                SetCameraBehindPlayer(playerid);
            }
            case 13:
            {
                SetPlayerInterior(playerid,0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1910.093261,830.862243,35.171875);
                SetCameraBehindPlayer(playerid);
            }
            case 14:
            {
                SetPlayerInterior(playerid,10);
                SetPlayerVirtualWorld(playerid, 3);
                SetPlayerPos(playerid, 365.353576,-73.941848,1001.507812);
                SetCameraBehindPlayer(playerid);
            }
            case 15:
            {
                SetPlayerInterior(playerid,0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2333.946289,-166.696685,35.554687);
                SetCameraBehindPlayer(playerid);
            }
            case 16:
            {
                SetPlayerInterior(playerid, 15);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 207.737991,-109.019996,1005.132812);
                SetCameraBehindPlayer(playerid);
            }
            case 17:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2376.078857,909.827209,45.445312);
                SetCameraBehindPlayer(playerid);
            }
            case 18:
            {
                SetPlayerInterior(playerid, 9);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 366.034881,-9.723926,1001.851562);
                SetCameraBehindPlayer(playerid);
            }
            case 19:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1816.083129,616.693908,35.171875);
                SetCameraBehindPlayer(playerid);
            }
            case 20:
            {
                SetPlayerInterior(playerid, 9);
                SetPlayerVirtualWorld(playerid, 2);
                SetPlayerPos(playerid, 366.034881,-9.723926,1001.851562);
                SetCameraBehindPlayer(playerid);
            }
            case 21:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2671.512939,261.794616,4.632812);
                SetCameraBehindPlayer(playerid);
            }
            case 22:
            {
                SetPlayerInterior(playerid, 9);
                SetPlayerVirtualWorld(playerid, 3);
                SetPlayerPos(playerid, 366.034881,-9.723926,1001.851562);
                SetCameraBehindPlayer(playerid);
            }
            case 23:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1547.742797,1213.344848,7.381250);
                SetCameraBehindPlayer(playerid);
            }
            case 24:
            {
                SetPlayerInterior(playerid, 3);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 418.652984,-82.639793,1001.804687);
                SetCameraBehindPlayer(playerid);
            }
            case 25:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2568.885742,243.841949,10.245244);
                SetCameraBehindPlayer(playerid);
            }
            case 26:
            {
                SetPlayerInterior(playerid, 17);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 493.390991,-22.722799,1000.679687);
                SetCameraBehindPlayer(playerid);
            }
            case 27:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2554.313232,192.769332,6.138108);
                SetCameraBehindPlayer(playerid);
            }
            case 28:
            {
                SetPlayerInterior(playerid, 18);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 161.391006,-93.159156,1001.804687);
                SetCameraBehindPlayer(playerid);
            }
            case 29:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1884.214599,864.275878,35.171875);
                SetCameraBehindPlayer(playerid);
            }
            case 30:
            {
                SetPlayerInterior(playerid, 5);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 223.455154,-8.655437,1002.210937);
                SetCameraBehindPlayer(playerid);
            }
            case 31:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -1696.291748,950.331848,24.890625);
                SetCameraBehindPlayer(playerid);
            }
            case 32:
            {
                SetPlayerInterior(playerid, 6);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, -2237.194580,136.381866,1035.414062);
                SetCameraBehindPlayer(playerid);
            }
            case 33:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2245.604003,128.278411,35.320312);
                SetCameraBehindPlayer(playerid);
            }
            case 34:
            {
                SetPlayerInterior(playerid, 11);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 501.980987,-69.150199,998.757812);
                SetCameraBehindPlayer(playerid);
            }
            case 35:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2244.593994,-88.143310,35.320312);
                SetCameraBehindPlayer(playerid);
            }
            case 36:
            {
                SetPlayerInterior(playerid, 6);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, 772.816467,-47.107429,1000.592712);
                SetCameraBehindPlayer(playerid);
            }
            case 37:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2267.978271,-155.794982,35.320312);
                SetCameraBehindPlayer(playerid);
            }
            case 38:
            {
                SetPlayerInterior(playerid, 3);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, -2029.798339,-106.675910,1035.171875);
                SetCameraBehindPlayer(playerid);
            }
            case 39:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2026.583007,-98.837745,35.164062);
                SetCameraBehindPlayer(playerid);
            }
            case 40:
            {
                SetPlayerInterior(playerid, 1);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, 286.339660,-38.591598,1001.515625);
                SetCameraBehindPlayer(playerid);
            }
            case 41:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2626.847412,211.390502,4.592437);
                SetCameraBehindPlayer(playerid);
            }
            case 42:
            {
                SetPlayerPos(playerid, -2640.762939,1406.682006,906.460937);
                SetPlayerInterior(playerid, 3);
                SetCameraBehindPlayer(playerid);
                SetPlayerVirtualWorld(playerid, 1);
            }
            case 43:
            {
                SetPlayerPos(playerid, -2623.578125,1409.178100,7.101562);
                SetPlayerInterior(playerid, 0);
                SetCameraBehindPlayer(playerid);
                SetPlayerVirtualWorld(playerid, 0);
            }
            case 44:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(playerid, -2760.666503,375.002685,4.917655);
                SetCameraBehindPlayer(playerid);
            }
            case 45:
            {
                SetPlayerInterior(playerid, 0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, -2029.4733,-124.0944,35.2107);
                SetCameraBehindPlayer(playerid);
            }
            case 46:
            {
                SetPlayerInterior(playerid, 3);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid, -2029.7303,-117.3965,1035.1719);
                SetCameraBehindPlayer(playerid);
            }
            case 47:
            {
                TogglePlayerControllable(playerid, 0);
                GameTextForPlayer(playerid, "- Objects Loading -~n~ - Please Wait -", 3000, 0);
                LoadObjectForPlayer(playerid);
                SetPlayerVirtualWorld(playerid, 1);
                SetPlayerPos(playerid,2181.0850,-1009.9630,1021.6880+1);
                SetCameraBehindPlayer(playerid);
            }
            case 48:
            {
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid,-2169.6025,252.0992,35.3325);
                SetCameraBehindPlayer(playerid);
            }
        }
    }
    return 1;
}
EDIT: I have to sleep now, so I won't be able to reply on this thread, I'll take a look tommorow and reply.
Reply
#2

pawn Код:
if(eCheckpoints[0] <= checkpointid <= eCheckpoints[sizeof(eCheckpoints)-1])
{
    new CP = checkpointid - eCheckpoints[0];
    switch(CP)
    {
        case 0:
        case 1:
        ...
    }
}
or

pawn Код:
for(new o = 0; o < sizeof(eCheckpoints); o++)
{
    if(checkpointid == eCheckpoints[o])
    {
        switch(o)
        {
            case 0:
            ...
        }
        break;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)