help regarding a system
#4

1)

pawn Код:
#define MAX_DROPPED_GPARTS 10
static GunParts[MAX_DROPPED_GPARTS][GunPart];
which is basically
pawn Код:
static GunParts[10][GunPart];
now in the command:
pawn Код:
for(new i = 0; i < sizeof(crateLocations); i++)
            {
                if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
                {
you made a loop with sizeof(crateLocations), which is

pawn Код:
static crateLocations[][GunPartsCoords] = {
    {2834.8857, -2386.6113, 17.5051}, // 0
    {2842.3608, -2500.4163, 17.5051}, // 1
    {2823.5750, -2474.1826, 12.0983}, // 2
    {2837.7878, -2449.3562, 19.9220}, // 3
    {2846.3259, -2447.9080, 19.9220}, // 4
    {2842.2053, -2500.4648, 17.5051} // 5
};
6, because crateLocations has 6 rows of coordinates you made for picking up parts.

So the loop will be repeated only 6 times, not 10 times as the GunParts[10] first dimension index is.

Fix this code so the loop checks all available coordinates for picking up the parts and also checks all available indexes of GunParts:

pawn Код:
CMD:takegunpart(playerid, params[])
{
    /*if(pInfo[playerid][pFamily] > 0)
    {
        if(pInfo[playerid][pRank] >= 5)
        {*/

            new pickedmsg[30];
            for(new i = 0; i < sizeof(crateLocations); i++)
            {
                if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
                {
                    if(if(GunParts[i][gDropped]==0)
                    {
                        format(pickedmsg, sizeof(pickedmsg), "Skipped because GunParts[%i][gDropped]==0",i); // I added this message for debugging purposes
                        SendClientMessage(playerid, -1, pickedmsg);
                    }
                    if(GunParts[i][gDropped] == 0) continue;
                    new gunpartamount = random (6);
                    //PlayerInfo[playerid][Gunparts] += gunpartamount;
                    format(pickedmsg, sizeof(pickedmsg), "You've picked %i gun parts.", gunpartamount);
                    SendClientMessage(playerid, -1, pickedmsg);
                    GunParts[i][gDropped] = 0;
                    return 1;
                }

            }
        /*}
    }*/

    return 1;
}
2) Don't create variables in loops.
Reply


Messages In This Thread
help regarding a system - by TroubleFingers - 27.03.2017, 12:40
Re: help regarding a system - by Unte99 - 27.03.2017, 12:49
Re: help regarding a system - by TroubleFingers - 27.03.2017, 12:53
Re: help regarding a system - by Unte99 - 27.03.2017, 15:35
Re: help regarding a system - by TroubleFingers - 28.03.2017, 11:52
Re: help regarding a system - by Unte99 - 28.03.2017, 11:57
Re: help regarding a system - by TroubleFingers - 28.03.2017, 12:25
Re: help regarding a system - by Unte99 - 28.03.2017, 12:46
Re: help regarding a system - by TroubleFingers - 28.03.2017, 13:00
Re: help regarding a system - by Unte99 - 28.03.2017, 13:07

Forum Jump:


Users browsing this thread: 4 Guest(s)