OnPlayerPickup and for loops? Good combination or not?
#1

Hello, I'm using 2 for loops in my car dealership, to either check the names and the pickup id's this is what I got on OnPlayerPickUpPickup

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i; i < sizeof(DealerShips); i++)
    {
        if(pickupid == DealerShips[i][PickupID]) break;
            new VehiclesString[250];
            for(new d; d < sizeof(DealerShipVehicles); d++)
            {
                if(DealerShipVehicles[d][DealershipNumber] == DealerShips[i][DealerShipID])
                {
                    new vModel = DealerShipVehicles[d][VModel];
                    format(VehiclesString, sizeof(VehiclesString), "%s(%d)\n",VehicleFriendlyNames[vModel-400],DealerShipVehicles[d][VPrice]);
                }
            }
            ShowPlayerDialog(playerid, dealership1, DIALOG_STYLE_LIST, DealerShips[i][DealershipName], VehiclesString, "Buy", "Cancel");
    }
    return 1;
}
And here is the loading part of the pickups:
pawn Код:
public LoadDealerships(playerid)
{
    for(new i; i < sizeof(DealerShips); i++)
    {
        new string[128];
        DealerShips[i][PickupID] = CreateDynamicPickup(1239,23,DealerShips[i][LocX],DealerShips[i][LocY],DealerShips[i][LocZ]);
        format(string, sizeof(string), "{FFFF00}%s", DealerShips[i][DealershipName]);
        DealerShips[i][labeltext] = Create3DTextLabel(string,0xFFFFFFFF,DealerShips[i][LocX],DealerShips[i][LocY],DealerShips[i][LocZ],15.0,0,0);
    }
    print("Dealerships has been loaded");
    return 1;
}
Now here is the problem when In-game and trying to pickup that pickup, it doesn't show me the dialog with the vehicle names that it should.

Anyone has a clue why this is happening and if it's smart to do 2 loops?

-Kevin
Reply
#2

This is a problem

if(pickupid == DealerShips[i][PickupID]) break;

You want it to do the other loop once it is found then return 1; when all the code is finished that will stop all looping.
Reply
#3

So basically this will do it:

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i; i < sizeof(DealerShips); i++)
    {
        if(pickupid == DealerShips[i][PickupID])
        {
            new VehiclesString[250];
            for(new d; d < sizeof(DealerShipVehicles); d++)
            {
                if(DealerShipVehicles[d][DealershipNumber] == DealerShips[i][DealerShipID])
                {
                    new vModel = DealerShipVehicles[d][VModel];
                    format(VehiclesString, sizeof(VehiclesString), "%s(%d)\n",VehicleFriendlyNames[vModel-400],DealerShipVehicles[d][VPrice]);
                }
            }
            ShowPlayerDialog(playerid, dealership1, DIALOG_STYLE_LIST, DealerShips[i][DealershipName], VehiclesString, "Buy", "Cancel");
            return 1; // this will do it basically?
        }
    }
    return 1;
}
Reply
#4

Yep.
Reply
#5

That should do it back to your original question, this shouldn't really cause any problems in terms of looping since you have a stop mechanism to stop looping once the condition your looking for is found and completed.
Reply
#6

Still no dialog that shows up... Also the pickup dissapears when I enter in it. Which also shouldn't be the case.

Reply
#7

Hmmmm put print() debug messages in like this....

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    print("OnPlayerPickUpPickup::Level 1");
    for(new i; i < sizeof(DealerShips); i++)
    {
        if(pickupid == DealerShips[i][PickupID])
        {
            print("OnPlayerPickUpPickup::Level 2");
            new VehiclesString[250];
            for(new d; d < sizeof(DealerShipVehicles); d++)
            {
                if(DealerShipVehicles[d][DealershipNumber] == DealerShips[i][DealerShipID])
                {
                    print("OnPlayerPickUpPickup::Level 3");
                    new vModel = DealerShipVehicles[d][VModel];
                    format(VehiclesString, sizeof(VehiclesString), "%s(%d)\n",VehicleFriendlyNames[vModel-400],DealerShipVehicles[d][VPrice]);
                }
            }
            print("OnPlayerPickUpPickup::Level 4");
            ShowPlayerDialog(playerid, dealership1, DIALOG_STYLE_LIST, DealerShips[i][DealershipName], VehiclesString, "Buy", "Cancel");
            return 1; // this will do it basically?
        }
    }
    return 1;
}
That will show you exactly where your code is stopping.
Reply
#8

Gives me the OnPlayerPickUpPickup::Level 1 and nothing else.
Reply
#9

Then the problem is here, if(pickupid == DealerShips[i][PickupID]) can we see your AddDealerShip() function ?
Reply
#10

pawn Код:
public LoadDealerships(playerid)
{
    for(new i; i < sizeof(DealerShips); i++)
    {
        new string[128];
        DealerShips[i][PickupID] = CreateDynamicPickup(1239,23,DealerShips[i][LocX],DealerShips[i][LocY],DealerShips[i][LocZ],0);
        format(string, sizeof(string), "{FFFF00}%s", DealerShips[i][DealershipName]);
        DealerShips[i][labeltext] = Create3DTextLabel(string,0xFFFFFFFF,DealerShips[i][LocX],DealerShips[i][LocY],DealerShips[i][LocZ],15.0,0,0);
    }
    print("Dealerships has been loaded");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)