PHP код:
forward SafeCreateVehicle(owner[], model, Float:x, Float:y, Float:z, Float:a, color1 , color2);
public SafeCreateVehicle(owner[], model, Float:x, Float:y, Float:z, Float:a, color1 , color2)
{
new string[255];
new vehnumber = GetFreeSlotVehicle();
new plate[MAX_VEHICLE_PLATE+1];
new const charset[] = "ABCDEFGHIJKLMNOPQRSTUPWZYZ";
new const charset2[] = "123456789";
plate[0] = charset[random(26)];
plate[1] = charset[random(26)];
plate[2] = charset[random(26)];
plate[3] = charset[random(26)];
plate[4] = charset2[random(9)];
plate[5] = charset2[random(9)];
plate[6] = charset2[random(9)];
format(Vehicle[vehnumber][vPlate], 8, "%s", plate);
Vehicle[vehnumber][vModelID] = model;
Vehicle[vehnumber][vColor1] = color1;
Vehicle[vehnumber][vColor2] = color2;
Vehicle[vehnumber][vSp][0] = x;
Vehicle[vehnumber][vSp][1] = y;
Vehicle[vehnumber][vSp][2] = z;
Vehicle[vehnumber][vSp][3] = a;
new ORM:ormid = Vehicle[vehnumber][vORM_ID] = orm_create("vehicles");
orm_addvar_int(ormid, Vehicle[vehnumber][vID], "ID");
orm_addvar_string(ormid, Vehicle[vehnumber][vPlate], MAX_VEHICLE_PLATE, "Plate");
orm_addvar_int(ormid, Vehicle[vehnumber][vOwner], "Owner");
orm_addvar_int(ormid, Vehicle[vehnumber][vModelID], "ModelID");
orm_addvar_int(ormid, Vehicle[vehnumber][vColor1], "Color1");
orm_addvar_int(ormid, Vehicle[vehnumber][vColor2], "Color2");
orm_addvar_float(ormid, Vehicle[vehnumber][vSp][0], "PosX");
orm_addvar_float(ormid, Vehicle[vehnumber][vSp][1], "PosY");
orm_addvar_float(ormid, Vehicle[vehnumber][vSp][2], "PosZ");
orm_addvar_float(ormid, Vehicle[vehnumber][vSp][3], "PosA");
orm_setkey(ormid, "Plate");
orm_select(ormid);
switch(orm_errno(ormid))
{
case ERROR_OK:
{
format(string, sizeof(string), "Vehicle license %s is already registered object relation mapping and all data in vehicle data slot will be delete", Vehicle[vehnumber][vPlate]);
ABroadCast(COLOR_ADMCMD1,string,4);
for(new E_VEHICLE:e; e < E_VEHICLE; ++e)
{
Vehicle[vehnumber][e] = 0;
}
orm_destroy(ormid);
}
case ERROR_NO_DATA:
{
orm_setkey(ormid, "ID");
orm_insert(ormid);
Vehicle[vehnumber][VID] = CreateVehicle(Vehicle[vehnumber][vModelID], Vehicle[vehnumber][vSp][0], Vehicle[vehnumber][vSp][1], Vehicle[vehnumber][vSp][2], Vehicle[vehnumber][vSp][3], Vehicle[vehnumber][vColor1], Vehicle[vehnumber][vColor2], -1);
SetVehicleNumberPlate(Vehicle[vehnumber][VID], Vehicle[vehnumber][vPlate]);
format(string, sizeof(string), "Vehicle license %s registered to database ID %d used %d dataslot by vehicle id%d", Vehicle[vehnumber][vPlate], Vehicle[vehnumber][vID], vehnumber, Vehicle[vehnumber][VID]);
ABroadCast(COLOR_ADMCMD1,string,4);
}
}
}
forward SafeDestroyVehicle(vehicleid);
public SafeDestroyVehicle(vehicleid)
{
new vehnumber = GetVehicleSlot(vehicleid);
for(new E_VEHICLE:e; e < E_VEHICLE; ++e)
{
Vehicle[vehnumber][e] = 0;
}
orm_delete(Vehicle[vehnumber][vORM_ID]);
DestroyVehicle(vehicleid);
}
forward GetVehicleSlot(vehicleid);
public GetVehicleSlot(vehicleid)
{
new slot;
for(new i=0; i < MAX_VEHICLES; i++)
{
if(Vehicle[i][VID] == vehicleid) { slot = i; break; }
}
return slot;
}
forward GetFreeSlotVehicle();
public GetFreeSlotVehicle()
{
new slot;
for(new i=0; i < MAX_VEHICLES; i++)
{
if(Vehicle[i][VID] == 0) { slot = i; break; }
}
return slot;
}