Help with a loop.
#1

So I have this code:

pawn Код:
if(strcmp(cmdtext, "/deleteusercar", true) == 0)
    {
        new vehid = GetPlayerVehicleID(playerid);
        for(new i = 0; i < sizeof(CarInfo); i++)
        {
            if(vehid != CarInfo[i][ownedvehicle])
            {
                SendClientMessage(playerid, COLOR_GREY, "* This car is not owned by a player.");
                return 1;
            }
            else {
                CarInfo[vehid][vModel] = 0;
                CarInfo[vehid][vLocationx] = 0;
                CarInfo[vehid][vLocationy] = 0;
                CarInfo[vehid][vLocationz] = 0;
                CarInfo[vehid][vAngle] = 0;
                CarInfo[vehid][vColorOne] = 0;
                CarInfo[vehid][vColorTwo] = 0;
                CarInfo[vehid][vOwner] = 0;
                CarInfo[vehid][vValue] = 0;
                CarInfo[vehid][vLicense] = 0;
                CarInfo[vehid][vOwned] = 0;
                CarInfo[vehid][vLock] = 0;
                CarInfo[vehid][vMod1] = 0;
                CarInfo[vehid][vMod2] = 0;
                CarInfo[vehid][vMod3] = 0;
                CarInfo[vehid][vMod4] = 0;
                CarInfo[vehid][vMod5] = 0;
                CarInfo[vehid][vMod6] = 0;
                CarInfo[vehid][vMod7] = 0;
                CarInfo[vehid][vMod8] = 0;
                CarInfo[vehid][vMod9] = 0;
                CarInfo[vehid][vMod10] = 0;
                CarInfo[vehid][vMod11] = 0;
                CarInfo[vehid][vMod12] = 0;
                CarInfo[vehid][vMod13] = 0;
                CarInfo[vehid][vMod14] = 0;
                CarInfo[vehid][vMod15] = 0;
                CarInfo[vehid][vMod16] = 0;
                CarInfo[vehid][vMod17] = 0;
                CarInfo[vehid][vPlate] = 0;
                DestroyVehicle(vehid);
                SaveCars();
                SendClientMessage(playerid, COLOR_GREY, "* This car has been deleted !");
            }
        }
        return 1;
    }
But it doesn't work. I know I haven't done it properly but I'm not sure how to do it properly, you see I loop through CarInfo. createvehicle comes from the enum, it's how the cars id is defined. So I need it to ask, if the vehid is ANY "CarInfo[i][createvehicle]".
Reply
#2

So wait, what happens exactly? Does it say The car has been deleted, or that the car is not owned ?

-- looks like one problem is that return 1; .. idk if the code below it works properly though.
Reply
#3

Alright so it deletes the car, gives me BOTH messages, but the cars enum info isn't set back to 0.
Reply
#4

try
pawn Код:
if(strcmp(cmdtext, "/deleteusercar", true) == 0)
    {
        new vehid = GetPlayerVehicleID(playerid);
        for(new i = 0; i < sizeof(CarInfo); i++)
        {
            if(vehid == CarInfo[i][ownedvehicle])
            {
                CarInfo[vehid][vModel] = 0;
                CarInfo[vehid][vLocationx] = 0;
                CarInfo[vehid][vLocationy] = 0;
                CarInfo[vehid][vLocationz] = 0;
                CarInfo[vehid][vAngle] = 0;
                CarInfo[vehid][vColorOne] = 0;
                CarInfo[vehid][vColorTwo] = 0;
                CarInfo[vehid][vOwner] = 0;
                CarInfo[vehid][vValue] = 0;
                CarInfo[vehid][vLicense] = 0;
                CarInfo[vehid][vOwned] = 0;
                CarInfo[vehid][vLock] = 0;
                CarInfo[vehid][vMod1] = 0;
                CarInfo[vehid][vMod2] = 0;
                CarInfo[vehid][vMod3] = 0;
                CarInfo[vehid][vMod4] = 0;
                CarInfo[vehid][vMod5] = 0;
                CarInfo[vehid][vMod6] = 0;
                CarInfo[vehid][vMod7] = 0;
                CarInfo[vehid][vMod8] = 0;
                CarInfo[vehid][vMod9] = 0;
                CarInfo[vehid][vMod10] = 0;
                CarInfo[vehid][vMod11] = 0;
                CarInfo[vehid][vMod12] = 0;
                CarInfo[vehid][vMod13] = 0;
                CarInfo[vehid][vMod14] = 0;
                CarInfo[vehid][vMod15] = 0;
                CarInfo[vehid][vMod16] = 0;
                CarInfo[vehid][vMod17] = 0;
                CarInfo[vehid][vPlate] = 0;
                DestroyVehicle(vehid);
                SaveCars();
                SendClientMessage(playerid, COLOR_GREY, "* This car has been deleted !");
                return 1; //if we find the car end the command
            }
        }
        //if the makes it to these lines then it didnt find the car
        SendClientMessage(playerid, -1, "Not an owned car!");
        return 1;
    }
Reply
#5

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
try
pawn Код:
if(strcmp(cmdtext, "/deleteusercar", true) == 0)
    {
        new vehid = GetPlayerVehicleID(playerid);
        for(new i = 0; i < sizeof(CarInfo); i++)
        {
            if(vehid == CarInfo[i][ownedvehicle])
            {
                CarInfo[vehid][vModel] = 0;
                CarInfo[vehid][vLocationx] = 0;
                CarInfo[vehid][vLocationy] = 0;
                CarInfo[vehid][vLocationz] = 0;
                CarInfo[vehid][vAngle] = 0;
                CarInfo[vehid][vColorOne] = 0;
                CarInfo[vehid][vColorTwo] = 0;
                CarInfo[vehid][vOwner] = 0;
                CarInfo[vehid][vValue] = 0;
                CarInfo[vehid][vLicense] = 0;
                CarInfo[vehid][vOwned] = 0;
                CarInfo[vehid][vLock] = 0;
                CarInfo[vehid][vMod1] = 0;
                CarInfo[vehid][vMod2] = 0;
                CarInfo[vehid][vMod3] = 0;
                CarInfo[vehid][vMod4] = 0;
                CarInfo[vehid][vMod5] = 0;
                CarInfo[vehid][vMod6] = 0;
                CarInfo[vehid][vMod7] = 0;
                CarInfo[vehid][vMod8] = 0;
                CarInfo[vehid][vMod9] = 0;
                CarInfo[vehid][vMod10] = 0;
                CarInfo[vehid][vMod11] = 0;
                CarInfo[vehid][vMod12] = 0;
                CarInfo[vehid][vMod13] = 0;
                CarInfo[vehid][vMod14] = 0;
                CarInfo[vehid][vMod15] = 0;
                CarInfo[vehid][vMod16] = 0;
                CarInfo[vehid][vMod17] = 0;
                CarInfo[vehid][vPlate] = 0;
                DestroyVehicle(vehid);
                SaveCars();
                SendClientMessage(playerid, COLOR_GREY, "* This car has been deleted !");
                return 1; //if we find the car end the command
            }
        }
        //if the makes it to these lines then it didnt find the car
        SendClientMessage(playerid, -1, "Not an owned car!");
        return 1;
    }
It works but it isn't saving the CarInfo enum, so it doesn't fully delete. Hm.
Reply
#6

well I left the enum stuff default, but maybe you need to change vehid to i?
Reply
#7

No because then it'd change every single car from the CarInfo?
Reply
#8

I can't see why it would not be setting it.

Trying have those values read out to game or file or something directly after changing them (just a few) and see what happens.

Also what happens if you clear out that enum after you delete and save?
Reply
#9

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
No because then it'd change every single car from the CarInfo?
No...
by doing
if(vehid == CarInfo[i][ownedvehicle])

in the loop it checks if your current vehicle is the owned one at the index of i, so everything in that check would only related to that vehicleid.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)