Do I have to type this 10 times or is there an easier way?
#1

Hi there, basically. I'm re-writing this system I am making the maximum vehicle slots based upon the player level. i.e Level 10 = 10 vehicles max. Instead of adding 10 slots, I'm simply setting the owner of the vehicle on the vehicle table.

Is there a way I can check without a mass of if statements in the command and just check how many times it needs to be done or do I have to do this like below?

(this is to display all owned vehicles).

pawn Код:
if(VehicleSlot1[playerid] != 0)
    {
        new name1 = GetVehicleModel(VehicleSlot1[playerid]) - 400;
        format(second, sizeof(second), "%s - ID(%d) - Slot: 1 - Plate: %s\n",VehicleNames[name1], VehicleSlot1[playerid], VehPlate[VehicleSlot1[playerid]]);
        strcat(string, second);
    }
    if(VehicleSlot2[playerid] != 0)
    {
        new name2 = GetVehicleModel(VehicleSlot2[playerid]) - 400;
        format(second, sizeof(second), "%s - ID(%d) - Slot: 2 - Plate: %s\n",VehicleNames[name2], VehicleSlot2[playerid], VehPlate[VehicleSlot2[playerid]]);
        strcat(string, second);
    }
    if(VehicleSlot3[playerid] != 0)
    {
        new name3 = GetVehicleModel(VehicleSlot3[playerid]) - 400;
        format(second, sizeof(second), "%s - ID(%d) - Slot: 3 - Plate: %s", VehicleNames[name3], VehicleSlot3[playerid], VehPlate[VehicleSlot3[playerid]]);
        strcat(string, second);
    }
Reply
#2

I would still have to type it 10 times though?

I plan to send it all as ONE string, so say there was more than like 3 do I have to make a massive sized string?
Reply
#3

No, you would do it like this:
pawn Код:
#define MAX_SLOTS 10
//...
for(new s = 1; s < MAX_SLOTS; s++)
//..
VehicleSlot[SLOT_ID][playerid] // so u replace SLOT_ID with s
Reply
#4

Max Slots is defined by player level, that's what is confusing me. Also, Do I have to create a massive string, I mean If I want this:

pawn Код:
format(second, sizeof(second), "%s - ID(%d) - Slot: 1 - Plate: %s\n",VehicleNames[name1], VehicleSlot1[playerid], VehPlate[VehicleSlot1[playerid]]);
        strcat(string, second);
Say there was 10 in the one message?
Reply
#5

Mmmh,
pawn Код:
for(new s = 1; s < PlayerLevel[playerid]; s++)
?
And that with the string, you have to test.. well, the loop is calling 10 times (with MAX_SLOTS defined 10), so 10 times the message but I don't think that you need a big string.
Reply
#6

It has to get the vehicle, not the amount aha! As in....

VEHICLE 1
VEHICLE 2

etc

I need it to search through all of the vehicles that are owned by the player ie

pawn Код:
if(VehOwner[v] == PlayerSQLID[playerid])
{
    //Do the messages here, but I don't know how I can do it for every vehicle without creating a string format 10 times

}
The player might not own 10 vehicles or the amount their level equals, you see?

So if Level = 5 they have 5 slots etc but I don't know how to make it check how many the player owns without using if statements like

if(vehownedamount == 5)
{
}
if(vehownedamount == 6)

etc
Reply
#7

https://sampwiki.blast.hk/wiki/Control_Structures#Loops

Should read that quick guide on how loops work and what do they do.
Reply
#8

I understand how loops work etc, just I'm not sure how to create a String for each and every result without actually doing if(amount == 1) CODE HERE if amount == 2 etc.


Do I have to create a string for EACH result or can I create one and use it for all?
Reply
#9

If you are using MySQL, you can query the vehicles that player owns from the database and make the loop go through via row count so it'd always get the exact number.
Reply
#10

I know how to loop through them all, it's just basically do I have to type this:
pawn Код:
format(second, sizeof(second), "%s - ID(%d) - Slot: 1 - Plate: %s\n",VehicleNames[name1], VehicleSlot1[playerid], VehPlate[VehicleSlot1[playerid]]);
        strcat(string, second);
Do I have to type this part 10 times as there is a maximum of 10 slots if the player level == 10.
Not every player is level 10, what I mean is there a way I can make this string be created depending on the amount of levels?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)