stock updatecarid(){ while(something){ // update the cars ids! } }
format(queryString, sizeof(queryString), "DELETE FROM vehicles WHERE vehicleID = %d", GetPlayerVehicleID(playerid)); mysql_query(queryString);
I want to be able to delete cars ingame using a command like /deletecar. The command does that:
Код:
format(queryString, sizeof(queryString), "DELETE FROM vehicles WHERE vehicleID = %d", GetPlayerVehicleID(playerid)); mysql_query(queryString); Another solution it would be if I would be able to delete the fifth row. Don't know if that's something that you can do in SA:MP. |
if you want to do something in sa-mp what you can do is make a variable array sized [MAX_VEHICLES] and assign each vehicleid the database id so you can quicly delete from the database.
|
vehicleVariables[x][vVehicleScriptID] = CreateVehicle(vehicleVariables[x][vVehicleModelID], vehicleVariables[x][vVehiclePosition][0], vehicleVariables[x][vVehiclePosition][1], vehicleVariables[x][vVehiclePosition][2], vehicleVariables[x][vVehicleRotation], vehicleVariables[x][vVehicleColour][0], vehicleVariables[x][vVehicleColour][1], 60000);
format(query, sizeof(query), "DELETE FROM `vehicles` WHERE ID=%d", vehicleVariables[vehicleid][ID]); mysql_query(query);
Could you please tell me how exactly would I do that?
The vehicle are spawned using Код HTML:
vehicleVariables[x][vVehicleScriptID] = CreateVehicle(vehicleVariables[x][vVehicleModelID], vehicleVariables[x][vVehiclePosition][0], vehicleVariables[x][vVehiclePosition][1], vehicleVariables[x][vVehiclePosition][2], vehicleVariables[x][vVehicleRotation], vehicleVariables[x][vVehicleColour][0], vehicleVariables[x][vVehicleColour][1], 60000); |
enum Vehicle_E
{
VID,
ModelID,
Owner[32],
OwnerType,
Color1,
Color2,
PaintJobID,
Float:Spawn[3],
Float:Angle,
Float:Fuel,
Price,
Text3D:LabelID,
InteriorID,
VirtualWorld,
V_Size,
Components[14],
bool:IsTrailer,
bool:IsPlane,
bool:IsHeli,
bool:IsTruck,
bool:IsBoat
};
new Vehicle[MAX_VEHICLES ][Vehicle_E];
forward OnQueryFinish(query[],resultid, extraid, connectionHandle);
public OnQueryFinish(query[],resultid, extraid, connectionHandle)
{
switch(resultid)
{
case LOAD_VEHICLES:
{
mysql_store_result();
new id = 0//,unused
;
new vid,ot,mid,tmpid,colors[2],pjid,Float:spwn[5],pricx,interior,world,componenty[14];
while(mysql_fetch_row_format(GlobalString2048))
{
//id++;
sscanf(GlobalString2048,"p<|>ddddddds[32]fffffddddddddddddddddd",
vid,//Vehicle[id][VID],
ot,//Vehicle[id][OwnerType],
mid,//Vehicle[id][ModelID],
tmpid,//unused,
colors[0],//Vehicle[id][Color1],
colors[1],//Vehicle[id][Color2],
pjid,//Vehicle[id][PaintJobID],
GlobalString32,//Vehicle[id][Owner],
spwn[0],//Vehicle[id][Spawn][0],
spwn[1],//Vehicle[id][Spawn][1],
spwn[2],//Vehicle[id][Spawn][2],
spwn[3],//Vehicle[id][Angle],
spwn[4],//Vehicle[id][Fuel],
pricx,//Vehicle[id][Price],
interior,//Vehicle[id][InteriorID],
world,//Vehicle[id][VirtualWorld],
componenty[0],
componenty[1],
componenty[2],
componenty[3],
componenty[4],
componenty[5],
componenty[6],
componenty[7],
componenty[8],
componenty[9],
componenty[10],
componenty[11],
componenty[12],
componenty[13]
);
tmpid = CreateNormalVehicle(mid,spwn[0],spwn[1],spwn[2],spwn[3],colors[0],colors[1],999999999);
Vehicle[tmpid][Components] = componenty;
LoadCarComponents(tmpid);
SetVehicleVirtualWorld(tmpid,world);
LinkVehicleToInterior(tmpid,interior);
mysql_query(sprintf("update `vehicles` set `tmp_vehice_id` = %d WHERE `v_id` = %d",tmpid,vid));
Vehicle[tmpid][VID] = vid;
Vehicle[tmpid][OwnerType]=ot;
//if(Vehicle[tmpid][OwnerType] != 0)
//{
// Vehicle[tmpid][LabelID] = Create3DTextLabel(sprintf("%s\nOwner: %s",aVehicleNames[mid-400],GlobalString32), 0x008080FF, 0.0, 0.0, 0.0, 35.0, 0, 0);
// Attach3DTextLabelToVehicle(Vehicle[tmpid][LabelID],tmpid,0.0,0.0,0.0);
//}
//else
//{
Vehicle[tmpid][LabelID] = Text3D:(-1);
//}
Vehicle[tmpid][ModelID]=mid;
Vehicle[tmpid][Color1]=colors[0];
Vehicle[tmpid][Color2]=colors[1];
Vehicle[tmpid][PaintJobID]=pjid;
Vehicle[tmpid][Owner]=GlobalString32;
Vehicle[tmpid][Spawn][0]=spwn[0];
Vehicle[tmpid][Spawn][1]=spwn[1];
Vehicle[tmpid][Spawn][2]=spwn[2];
Vehicle[tmpid][Angle]=spwn[3];
Vehicle[tmpid][Fuel]=spwn[4];
Vehicle[tmpid][Price]=pricx;
Vehicle[tmpid][InteriorID]=interior;
Vehicle[tmpid][VirtualWorld]=world;
id++;
}
if(id == 0)
{
mysql_free_result();
print("No vehicles loaded... inserting default vehicles");
InsertDefaultVehicles();
return 1;
}
printf("Loaded %d vehicles",id);
mysql_free_result();
}
}
return 1;
}
stock InsertDefaultVehicles()
{
if(!fexist("vehicles.dat"))
{
print("Cannot find 'vehicles.dat' in scriptfiles folder. No vehicles on server will be available. Quiting...");
SendRconCommand("exit");
return 0;
}
new File:fh = fopen("vehicles.dat",io_read);
new modelid,Float:Position[4],Color_x[2];
while(fread(fh,GlobalString256))
{
//print(GlobalString256);
sscanf(GlobalString256,"p<,>dffffdd",modelid,Position[0],Position[1],Position[2],Position[3],Color_x[0],Color_x[1]);
mysql_query(sprintf("INSERT INTO `vehicles` (model_id,spawnx,spawny,spawnz,angle,color_1,color_2) VALUES (%d,%f,%f,%f,%f,%d,%d)",modelid,Position[0],Position[1],Position[2],Position[3],Color_x[0],Color_x[1]));
//print(sprintf("INSERT INTO `vehicles` (model_id,spawnx,spawny,spawnz,angle,color_1,color_2) VALUES (%d,%f,%f,%f,%f,%d,%d)",modelid,Position[0],Position[1],Position[2],Position[3],Color_x[0],Color_x[1]));
}
print("Saving vehicles...");
new tx = GetTickCount();
while(GetTickCount()-tx < 2000){}//give the time to mysql plugin to execute all queries
print("Loading vehicles...");
mysql_query(sprintf("SELECT * FROM `vehicles` LIMIT %d",MAX_VEHICLES-1),LOAD_VEHICLES);
return 1;
}
stock LinkVehicleToInteriorEx(vehicleid,interiorid)
{
mysql_query(sprintf("update `vehicles` set `interior` = %d WHERE `v_id` = %d",interiorid,Vehicle[vehicleid][VID]));
Vehicle[vehicleid][InteriorID] = interiorid;
return LinkVehicleToInterior(vehicleid,interiorid);
}
stock SetVehicleVirtualWorldEx(vehicleid,worldid)
{
mysql_query(sprintf("update `vehicles` set `world` = %d WHERE `v_id` = %d",worldid,Vehicle[vehicleid][VID]));
Vehicle[vehicleid][VirtualWorld] = worldid;
return SetVehicleVirtualWorld(vehicleid,worldid);
}
stock ChangeVehicleColorEx(vehicleid,color1,color2)
{
Vehicle[vehicleid][Color1] = color1;
Vehicle[vehicleid][Color2] = color2;
mysql_query(sprintf("update `vehicles` set `color_1` = %d,`color_2` = 5d WHERE `v_id` = %d",color1,color2,Vehicle[vehicleid][VID]));
return ChangeVehicleColor(vehicleid,color1,color2);
}
//#define ChangeVehicleColor ChangeVehicleColorEx
stock ChangeVehiclePaintJobEx(vehicleid,paintjobid)
{
mysql_query(sprintf("update `vehicles` set `paintjob` = %d WHERE `v_id` = %d",paintjobid,Vehicle[vehicleid][VID]));
Vehicle[vehicleid][PaintJobID] = paintjobid;
return ChangeVehiclePaintJob(vehicleid,paintjobid);
}
stock CreateVehicleEx(vehicletype,Float:x,Float:y,Float:z,Float:rotation,color1,color2,respawn_delay=999999999,_OwnerType=0,_PaintJobID=0,const _Owner[]="SERVER",Float:_fuel=100.0,_Price=0,_InteriorID=0,_VirtualWorld=0)
{
RecieverID = CreateVehicle(vehicletype,x,y,z,rotation,color1,color2,respawn_delay);
Vehicle[RecieverID][V_Size] = ReturnVehicleSize(vehicletype);
mysql_function_query(1,
sprintf("INSERT INTO `vehicles` (model_id,spawnx,spawny,spawnz,angle,color_1,color_2,owner_type,paintjob,owner,fuel,price,interior,world) VALUES (%d,%f,%f,%f,%f,%d,%d,%d,%d,'%s',%f,%d,%d,%d)",vehicletype,x,y,z,rotation,color1,color2,_OwnerType,_PaintJobID,_Owner,_fuel,_Price,_InteriorID,_VirtualWorld),
false,"CreateNewMYSQLVehicle", "iiffffiiiisfiii",RecieverID,vehicletype,x,y,z,rotation,color1,color2,_OwnerType,_PaintJobID,_Owner,_fuel,_Price,_InteriorID,_VirtualWorld);
return RecieverID;
}
stock DestroyVehicleEx(vehicleid)
{
Vehicle[vehicleid][VID] = (-1);
return DestroyVehicle(vehicleid);
}
#define DestroyVehicle DestroyVehicleEx
stock RemoveVehicleFromServer(vehicleid = -1,const _Owner[] = "",bool:CaseInsensetive=true)
{
if(vehicleid != (-1))
{
mysql_query(sprintf("DELETE FROM `vehicles` WHERE `v_id` = %d",Vehicle[vehicleid][VID]));
DestroyVehicle(vehicleid);
}
else
{
for(new i = 0; i < MAX_VEHICLES; ++i)
{
if(Vehicle[vehicleid][VID] == (-1))continue;
if(!strcmp(Vehicle[i][Owner],_Owner,CaseInsensetive))
{
DestroyVehicle(i);
}
}
mysql_function_query(1,sprintf("DELETE FROM `vehicles` WHERE `owner` = '%s'",_Owner));
}
return 1;
}
//forward SaveCarComponents(vehicleid);
stock SaveCarComponents(vehicleid)
{
Vehicle[vehicleid][Components][0] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_SPOILER);
Vehicle[vehicleid][Components][1] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_HOOD);
Vehicle[vehicleid][Components][2] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_ROOF);
Vehicle[vehicleid][Components][3] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_SIDESKIRT);
Vehicle[vehicleid][Components][4] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_LAMPS);
Vehicle[vehicleid][Components][5] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_NITRO);
Vehicle[vehicleid][Components][6] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_EXHAUST);
Vehicle[vehicleid][Components][7] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_WHEELS);
Vehicle[vehicleid][Components][8] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_STEREO);
Vehicle[vehicleid][Components][9] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_HYDRAULICS);
Vehicle[vehicleid][Components][10] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_FRONT_BUMPER);
Vehicle[vehicleid][Components][11] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_REAR_BUMPER);
Vehicle[vehicleid][Components][12] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_VENT_RIGHT);
Vehicle[vehicleid][Components][13] = GetVehicleComponentInSlot( vehicleid, CARMODTYPE_VENT_LEFT);
mysql_query(
sprintf("update `vehicles` set spoiler = %d, hood = %d, roof = %d, sideskirt = %d, lamps = %d, nitro = %d, exhaust = %d, wheels = %d, stereo = %d, hydraulics = %d, frontbumper = %d, rearbumper = %d, ventright = %d, ventleft = %d, paintjob WHERE `v_id` = %d",Vehicle[vehicleid][Components][0],Vehicle[vehicleid][Components][1],Vehicle[vehicleid][Components][2],Vehicle[vehicleid][Components][3],Vehicle[vehicleid][Components][4],Vehicle[vehicleid][Components][5],Vehicle[vehicleid][Components][6],Vehicle[vehicleid][Components][7],Vehicle[vehicleid][Components][8],Vehicle[vehicleid][Components][9],Vehicle[vehicleid][Components][10],Vehicle[vehicleid][Components][11],Vehicle[vehicleid][Components][12],Vehicle[vehicleid][Components][13],GetVehiclePaintJob(vehicleid),Vehicle[vehicleid][VID]
);
return 1;
}
stock LoadCarComponents(vehicleid)
{
for(new i; i < 14;i++){
if(Vehicle[vehicleid][Components][i] >= 0){
AddVehicleComponent(vehicleid,Vehicle[vehicleid][Components][i]);
}
}
return 1;
}
forward bool:IsTypePlane(vehicletype);
stock bool:IsTypePlane(vehicletype)
{
switch(vehicletype)
{
case 460,476,511,512,513,519,520,553,577,592,593:
{
return true;
}
}
return false;
}
forward bool:IsTypeHeli(vehicletype);
stock bool:IsTypeHeli(vehicletype)
{
switch(vehicletype)
{
case 417,425,447,469,487,488,497,548,563:
{
return true;
}
}
return false;
}
forward bool:IsTypeTruck(vehicletype);
stock bool:IsTypeTruck(vehicletype)
{
switch(vehicletype)
{
case 403,514,515:
{
return true;
}
}
return false;
}
forward bool:IsTypeBoat(vehicletype);
stock bool:IsTypeBoat(vehicletype)
{
switch(vehicletype)
{
case 430,446,452,453,454,472,473,484,493:
{
return true;
}
}
return false;
}
stock CreateNormalVehicle(vehicletype,Float:x,Float:y,Float:z,Float:rotation,color1,color2,respawn_delay)
{
new vehicleid = CreateVehicle(vehicletype,x,y,z,rotation,color1,color2,respawn_delay);
Vehicle[vehicleid][V_Size] = ReturnVehicleSize(vehicletype);
Vehicle[vehicleid][OwnerType]=0;
Vehicle[vehicleid][LabelID] = Text3D:(-1);
Vehicle[vehicleid][ModelID]=vehicletype;
Vehicle[vehicleid][Color1]=color1;
Vehicle[vehicleid][Color2]=color2;
Vehicle[vehicleid][PaintJobID]=0;
format(Vehicle[vehicleid][Owner],32,"SERVER");
Vehicle[vehicleid][Spawn][0]=x;
Vehicle[vehicleid][Spawn][1]=y;
Vehicle[vehicleid][Spawn][2]=z;
Vehicle[vehicleid][Angle]=rotation;
Vehicle[vehicleid][Fuel]=100.0;
Vehicle[vehicleid][Price]=0;
Vehicle[vehicleid][InteriorID]=0;
Vehicle[vehicleid][VirtualWorld]=0;
Vehicle[vehicleid][IsTrailer] = IsTypeTrailer(vehicletype);
Vehicle[vehicleid][IsPlane] = IsTypePlane(vehicletype);
Vehicle[vehicleid][IsHeli] = IsTypeHeli(vehicletype);
Vehicle[vehicleid][IsTruck] = IsTypeTruck(vehicletype);
Vehicle[vehicleid][IsBoat] = IsTypeBoat(vehicletype);
return vehicleid;
}
public OnVehicleSpawn(vehicleid)
{
LoadCarComponents(vehicleid);
return 1;
}
forward CreateNewMYSQLVehicle(vehicleid,vehicletype,Float:x,Float:y,Float:z,Float:rotation,color1,color2,_OwnerType,_PaintJobID,_Owner[],Float:_fuel,_Price,_InteriorID,_VirtualWorld);
public CreateNewMYSQLVehicle(vehicleid,vehicletype,Float:x,Float:y,Float:z,Float:rotation,color1,color2,_OwnerType,_PaintJobID,_Owner[],Float:_fuel,_Price,_InteriorID,_VirtualWorld)
{
Vehicle[vehicleid][VID] = mysql_insert_id();
Vehicle[vehicleid][OwnerType]=_OwnerType;
//if(Vehicle[vehicleid][OwnerType] != 0)
//{
// Vehicle[vehicleid][LabelID] = Create3DTextLabel(sprintf("%s\nOwner: %s",aVehicleNames[vehicletype-400],_Owner), 0x008080FF, 0.0, 0.0, 0.0, 35.0, 0, 0);
// Attach3DTextLabelToVehicle(Vehicle[vehicleid][LabelID],vehicleid,0.0,0.0,0.0);
//}
//else
//{
//SetPVarInt(vehicleid,"3DLABEL",_:Create3DTextLabel("Blablabla", 0x008080FF, 0.0, 0.0, 0.0, 35.0, 0, 0));
//Delete3DTextLabel(Text3D:GetPVarInt(vehicleid,"3DLABEL"));
Vehicle[vehicleid][LabelID] = Text3D:(-1);
//}
Vehicle[vehicleid][ModelID]=vehicletype;
Vehicle[vehicleid][Color1]=color1;
Vehicle[vehicleid][Color2]=color2;
Vehicle[vehicleid][PaintJobID]=_PaintJobID;
Vehicle[vehicleid][Owner]=GlobalString32;
Vehicle[vehicleid][Spawn][0]=x;
Vehicle[vehicleid][Spawn][1]=y;
Vehicle[vehicleid][Spawn][2]=z;
Vehicle[vehicleid][Angle]=rotation;
Vehicle[vehicleid][Fuel]=_fuel;
Vehicle[vehicleid][Price]=_Price;
Vehicle[vehicleid][InteriorID]=_InteriorID;
Vehicle[vehicleid][VirtualWorld]=_VirtualWorld;
Vehicle[vehicleid][IsTrailer] = IsTypeTrailer(vehicletype);
Vehicle[vehicleid][IsPlane] = IsTypePlane(vehicletype);
Vehicle[vehicleid][IsHeli] = IsTypeHeli(vehicletype);
Vehicle[vehicleid][IsTruck] = IsTypeTruck(vehicletype);
Vehicle[vehicleid][IsBoat] = IsTypeBoat(vehicletype);
return 1;
}
forward bool:IsTypeTrailer(vehicletype);
stock bool:IsTypeTrailer(vehicletype)
{
switch(vehicletype)
{
case 435,450,584,591:
{
return true;
}
}
return false;
}
stock GetTrailerType(vehicletype)
{
switch(vehicletype)
{
case 435:return 0;//food trailer
case 450:return 1;//Trailer with coal,grind,sand
case 584:return 2;//petrol trailer
case 591:return 3;//Anything trailer
}
return -1;
}
mysql_query("CREATE TABLE IF NOT EXISTS `vehicles` (`v_id` int(11) NOT NULL auto_increment,PRIMARY KEY (`v_id`))");
mysql_query("ALTER TABLE `vehicles` ADD `owner_type` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `model_id` int(11) NOT NULL");
mysql_query("ALTER TABLE `vehicles` ADD `tmp_vehice_id` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `color_1` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `color_2` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `paintjob` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `owner` VARCHAR(32) NOT NULL default 'SERVER'");
mysql_query("ALTER TABLE `vehicles` ADD `spawnx` FLOAT(35,25) NOT NULL");
mysql_query("ALTER TABLE `vehicles` ADD `spawny` FLOAT(35,25) NOT NULL");
mysql_query("ALTER TABLE `vehicles` ADD `spawnz` FLOAT(35,25) NOT NULL");
mysql_query("ALTER TABLE `vehicles` ADD `angle` FLOAT(35,25) NOT NULL");
mysql_query("ALTER TABLE `vehicles` ADD `fuel` FLOAT(35,25) NOT NULL default 100.00");
mysql_query("ALTER TABLE `vehicles` ADD `price` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `interior` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `world` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `spoiler` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `hood` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `roof` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `sideskirt` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `lamps` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `nitro` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `exhaust` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `wheels` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `stereo` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `hydraulics` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `frontbumper` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `rearbumper` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `ventright` int(11) NOT NULL default 0");
mysql_query("ALTER TABLE `vehicles` ADD `ventleft` int(11) NOT NULL default 0");
mysql_query(sprintf("SELECT * FROM `vehicles` LIMIT %d",MAX_VEHICLES-1 ),LOAD_VEHICLES );
stock mysql_query(query[],resultid = (-1),extraid = (-1),connectionHandle = 1)
{
return mysql_function_query(connectionHandle,query,false,"OnQueryFinish", "siii",query,resultid,extraid,connectionHandle);
}