OnPlayerPickup and for loops? Good combination or not? -
SomebodyAndMe - 16.05.2013
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
Re: OnPlayerPickup and for loops? Good combination or not? -
Pottus - 16.05.2013
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.
Re: OnPlayerPickup and for loops? Good combination or not? -
SomebodyAndMe - 16.05.2013
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;
}
AW: OnPlayerPickup and for loops? Good combination or not? -
Blackazur - 16.05.2013
Yep.
Re: OnPlayerPickup and for loops? Good combination or not? -
Pottus - 16.05.2013
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.
Re: OnPlayerPickup and for loops? Good combination or not? -
SomebodyAndMe - 16.05.2013
Still no dialog that shows up... Also the pickup dissapears when I enter in it. Which also shouldn't be the case.
Re: OnPlayerPickup and for loops? Good combination or not? -
Pottus - 16.05.2013
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.
Re: OnPlayerPickup and for loops? Good combination or not? -
SomebodyAndMe - 16.05.2013
Gives me the OnPlayerPickUpPickup::Level 1 and nothing else.
Re: OnPlayerPickup and for loops? Good combination or not? -
Pottus - 16.05.2013
Then the problem is here, if(pickupid == DealerShips[i][PickupID]) can we see your AddDealerShip() function ?
Re: OnPlayerPickup and for loops? Good combination or not? -
SomebodyAndMe - 16.05.2013
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;
}