Help pls make veh system with orm
#1

PHP код:
forward SafeCreateVehicle(owner[], modelFloat:xFloat:yFloat:zFloat:acolor1 color2);
public 
SafeCreateVehicle(owner[], modelFloat:xFloat:yFloat:zFloat:acolor1 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(ormidVehicle[vehnumber][vID], "ID");
    
orm_addvar_string(ormidVehicle[vehnumber][vPlate], MAX_VEHICLE_PLATE"Plate");
    
orm_addvar_int(ormidVehicle[vehnumber][vOwner], "Owner");
    
orm_addvar_int(ormidVehicle[vehnumber][vModelID], "ModelID");
    
orm_addvar_int(ormidVehicle[vehnumber][vColor1], "Color1");
    
orm_addvar_int(ormidVehicle[vehnumber][vColor2], "Color2");
    
orm_addvar_float(ormidVehicle[vehnumber][vSp][0], "PosX");
    
orm_addvar_float(ormidVehicle[vehnumber][vSp][1], "PosY");
    
orm_addvar_float(ormidVehicle[vehnumber][vSp][2], "PosZ");
     
orm_addvar_float(ormidVehicle[vehnumber][vSp][3], "PosA");
     
orm_setkey(ormid"Plate");
    
orm_select(ormid);
    switch(
orm_errno(ormid))
    {
        case 
ERROR_OK:
        {
            
format(stringsizeof(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:eE_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(stringsizeof(string), "Vehicle license %s registered to database ID %d used %d dataslot by vehicle id%d"Vehicle[vehnumber][vPlate], Vehicle[vehnumber][vID], vehnumberVehicle[vehnumber][VID]);
            
ABroadCast(COLOR_ADMCMD1,string,4);
        }
    }
}
forward SafeDestroyVehicle(vehicleid);
public 
SafeDestroyVehicle(vehicleid)
{
    new 
vehnumber GetVehicleSlot(vehicleid);
    for(new 
E_VEHICLE:eE_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=0MAX_VEHICLESi++)
    {
        if(
Vehicle[i][VID] == vehicleid) { slot i; break; }
    }
    return 
slot;
}
forward GetFreeSlotVehicle();
public 
GetFreeSlotVehicle()
{
    new 
slot;
    for(new 
i=0MAX_VEHICLESi++)
    {
        if(
Vehicle[i][VID] == 0) { slot i; break; }
    }
    return 
slot;

when i create alway say already registered
Reply
#2

got it no need any help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)