Array Check
#1

Hey!

I have an array full with checkpoints, how can I check if I enter a CP that is in the array?
(Without a 'for cycle', because it's under OnPlayerEnterDynamicCP and may crash the server if sb do it again and again in a short period of time..)

Thanks
Nonameman
Reply
#2

Here are some examples, hope they help you...

pawn Код:
new ExCPS[6];

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    for(new x=0; x<sizeof(ExCPS)-1, x++)
    {
        if(checkpointid == ExCPS[x])
        {
            new str[40];
            format(str, sizeof(str), "You entered CP ID %d", x);
            SendClientMessage(playerid, 0xFAFAFAFA, str);
            break;
        }
    }
    return 1;
}
pawn Код:
new ExCPS[6];

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == ExCPS[0])
    {
        SendClientMessage(playerid, 0xFAFAFAFA, "You entered a checkpoint");
    }
    else if(checkpointid == ExCPS[1])
    {
        SendClientMessage(playerid, 0xFAFAFAFA, "You entered a checkpoint");
    }
    else if(checkpointid == ExCPS[2])
    {
        SendClientMessage(playerid, 0xFAFAFAFA, "You entered a checkpoint");
    }
    else if(checkpointid == ExCPS[3])
    {
        SendClientMessage(playerid, 0xFAFAFAFA, "You entered a checkpoint");
    }
    //And so on...
    return 1;
}
Reply
#3

Okey, Thanks.
So no other way to do it
Reply
#4

No problem. Not that I can think of at least. :P
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)