Genuine Confusion
#1

I am genuinely baffled about how I'd go about doing this in my code, I have the code below, for displaying a dialog for the cars the player owns:

Код:
VehicleMenu(playerid)
{
	new str[500], cars = 0;
	for(new i = 0; i < sizeof(vInfo); i++)
	{
	    if(vInfo[i][vOwnerID] == pInfo[playerid][ID])
	    {
	        if(IsAnyPlayerInVehicle(vInfo[i][vCarID]) == 1) format(str, sizeof(str), "%s\n(%d): %s (In Use)", str, cars, vInfo[i][vName]);
	        else format(str, sizeof(str), "%s\n(%d): %s", str, cars, vInfo[i][vName]);
	        cars++;
	    }
	}
	if(cars == 0) SPD(playerid, dCars, DSM, "Vehicles", "You currently own no cars!", "Close", "");
	else SPD(playerid, dCars, DSL, "Vehicles", str, "Close", "");
}
(Apologies for any problems with indentation shown here, just because I copied it from my code.)

The issue I'm having, is not a 'code' syntax issue per se, I'm trying to reference each vehicle, but the problem I have, is that the player can own a LOT of vehicles (in excess of 10-20, even up to 100) the vehicles display fine on the menu from my knowledge on the matter, but because it's all procedural, how would I go about referencing any list items here? since I have no solid ones, but since all the basic formatting would be identical, would I do something like this?

Код:
switch(listitem)
{
    case 1..100:
    {
        // Code here
    }
}
I'm not entirely sure, I just need some guidance here.

The second question I have, is actually to do with the vehicles themselves, if that switch method IS the right way, how on Earth do I go about referencing the correct vehicle? This is my vehicle enumerator:

Код:
enum vData
{
	vID, // The vehicle ID ingame for reference in the script
	vCarID, // The vehicle ID ingame for reference in the script
	vModel, // The vehicle's model
	vName[60], // The vehicle's name
	vOwner[24], // Who owns the vehicle?
	vOwnerID, // What's the ID of the owner?
	Float:vLoc[4], // The 4 positions of the vehicle (X Y Z A)
	vCol1, // Car color 1
	vCol2, // Car color 2
	Text3D:vtextid,
	bool:vLocked
}
new vInfo[MAX_VEHICLES][vData]; // Variable for referencing the enumerator above
I would normally loop through all the vehicles until I found the one that matched the vehicle the player was in, and make sure they owned it, since the player has to be in the vehicle to do most other commands, but for this command, I can't really do that, since the player is rarely going to be in the cars they're looking at on the list, and the player can own multiple cars, the vID is more for the mysql database to uniquely reference each vehicle, and don't represent the vehicle ID for the player, and thus, I don't know how I'd go about doing this.

Now, don't get me wrong here. I don't want it done for me, not in the slightest, I just want some guidance.

Any help would be handy,
Thanks,
Zonoya.
Reply
#2

Apologies for the bump, but some help with this issue would be greatly appreciated.
Reply
#3

Well, that is pretty easy. You just have to create a multi dimensional array storing the vehicle ID for each listitem.

Some theory code here:
Код:
new DialogInfo[MAX_PLAYERS][100];

new count;
for( new i; I!=MAX_VEHICLES;i++)
{
//check if is owned by the player
DialogInfo[playerid][count] = i;
count++;
}

//on dialog response
new vehicleid = DialogInfo[playerid][listitem];
Reply
#4

Oh.... That's.... Really God damn simple actually, I can't believe I didn't think of that.

Thank you.

Oh, another question, though...

With the:

case 1..100

thing, is it possible to do like:

case 1..pInfo[playerid][CarSlots]

or something similar? That particular variable stores how many vehicles the player has, which would be all that shows on the dialog.

If not, that's fine, I can work with it, I'm just wondering.
Reply
#5

Well, you wouldn't need to use a switch or check any variable to obtain the correct ID as you're already obtaining it from the variable. However, it is not possible to do it using switch.

Do this:
Код:
if( variable >= 1 && variable <= pInfo[playerid][CarSlots] )
Change the "variable" name accordingly.
Reply
#6

Hmm, good to know, thank you for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)