Help with a loop. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with a loop. (
/showthread.php?tid=285043)
Help with a loop. -
Jack_Leslie - 22.09.2011
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]".
Re: Help with a loop. -
PrawkC - 22.09.2011
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.
Re: Help with a loop. -
Jack_Leslie - 22.09.2011
Alright so it deletes the car, gives me BOTH messages, but the cars enum info isn't set back to 0.
Re: Help with a loop. -
PrawkC - 22.09.2011
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;
}
Re: Help with a loop. -
Jack_Leslie - 22.09.2011
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.
Re: Help with a loop. -
PrawkC - 22.09.2011
well I left the enum stuff default, but maybe you need to change vehid to i?
Re: Help with a loop. -
Jack_Leslie - 22.09.2011
No because then it'd change every single car from the CarInfo?
Re: Help with a loop. -
GrimR - 22.09.2011
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?
Re: Help with a loop. -
PrawkC - 22.09.2011
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.