Trying to create a vehicle system
#1

Hi guys, how are you?
I'm trying to create a vehicle system for my RP Gamemode.
I've made something like that, but I'm not sure if that's how you make a vehicle system.

OnGameModeInit:
pawn Код:
for (new i = 0; i < MAX_VEHICLES; i++) {
        if (GetVehicleModel(i)) {
            format(szQuery, sizeof(szQuery), "SELECT `vid` FROM `vehicles` WHERE `vid` = '%d'", i);
            mysql_function_query(dbHandle, szQuery, true, "CheckExistVehicle", "d", i);
        }
    }
CheckExistVehicle:
pawn Код:
public CheckExistVehicle(vehicleid) {
    new rows, fields;
    cache_get_data(rows, fields);
    if (rows) {
        format(szQuery, sizeof(szQuery), "SELECT `model`,`posX`,`posY`,`posZ`,`angle`,`color1`,`color2`,`fuel`,`rental`,`owned`,`owner`,`factionowned`,`factionid` FROM `vehicles` WHERE `vid` = '%d'", vehicleid);
        mysql_function_query(dbHandle, szQuery, true, "GetVehicleInfo", "d", vehicleid);
    }
    else {
        vInfo[vehicleid][vModel] = GetVehicleModel(vehicleid);
        GetVehiclePos(vehicleid, vInfo[vehicleid][vPos][0], vInfo[vehicleid][vPos][1], vInfo[vehicleid][vPos][2]);
        GetVehicleZAngle(vehicleid, vInfo[vehicleid][vAngle]);
        if (GetVehicleModel(vehicleid) == 596 || GetVehicleModel(vehicleid) == 427) { // Police Car (LSPD) | FBI Truck
            vInfo[vehicleid][vColor1] = 0;
            vInfo[vehicleid][vColor2] = 1;
        }
        else if (GetVehicleModel(vehicleid) == 490) { // FBI Rancher
            vInfo[vehicleid][vColor1] = 0;
            vInfo[vehicleid][vColor2] = 0;
        }
        else if (GetVehicleModel(vehicleid) == 420 || GetVehicleModel(vehicleid) == 438) { // Taxies
            vInfo[vehicleid][vColor1] = 6;
            vInfo[vehicleid][vColor2] = 6;
        }
        else {
            GetVehicleColor(vehicleid, vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2]);
        }
        vInfo[vehicleid][vEngine] = false;
        vInfo[vehicleid][vLocked] = true;
        vInfo[vehicleid][vFuel] = 100;
        vInfo[vehicleid][vRental] = 0;
        vInfo[vehicleid][vRented] = false;
        format(vInfo[vehicleid][vRentOwner], 24, "%s", "None");
        vInfo[vehicleid][vOwned] = 0;
        format(vInfo[vehicleid][vOwner], 24, "%s", "None");
        vInfo[vehicleid][vFactionOwned] = 0;
        vInfo[vehicleid][vFactionID] = -1;
       
        format(szQuery, sizeof(szQuery), "INSERT INTO `vehicles` VALUES(NULL, '%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d')", vehicleid, vInfo[vehicleid][vModel], vInfo[vehicleid][vPos][0], vInfo[vehicleid][vPos][1], vInfo[vehicleid][vPos][2], vInfo[vehicleid][vAngle], vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2], vInfo[vehicleid][vFuel], vInfo[vehicleid][vRental], vInfo[vehicleid][vOwned], vInfo[vehicleid][vOwner], 0, -1);
        mysql_function_query(dbHandle, szQuery, false, "", "");
       
        ChangeVehicleColor(vehicleid, vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2]);
    }
    return 1;
}
GetVehicleInfo:
pawn Код:
public GetVehicleInfo(vehicleid) {
    new rows, fields, temp[30];
    cache_get_data(rows, fields);
   
    cache_get_field_content(0, "model", temp);      vInfo[vehicleid][vModel] = strval(temp);
    cache_get_field_content(0, "posX", temp);       vInfo[vehicleid][vPos][0] = floatstr(temp);
    cache_get_field_content(0, "posY", temp);       vInfo[vehicleid][vPos][1] = floatstr(temp);
    cache_get_field_content(0, "posZ", temp);       vInfo[vehicleid][vPos][2] = floatstr(temp);
    cache_get_field_content(0, "angle", temp);      vInfo[vehicleid][vAngle]  = floatstr(temp);
    cache_get_field_content(0, "color1", temp);     vInfo[vehicleid][vColor1] = strval(temp);
    cache_get_field_content(0, "color2", temp);     vInfo[vehicleid][vColor2] = strval(temp);
    cache_get_field_content(0, "fuel", temp);       vInfo[vehicleid][vFuel] = strval(temp);
    cache_get_field_content(0, "rental", temp);     vInfo[vehicleid][vRental] = strval(temp);
    cache_get_field_content(0, "owned", temp);      vInfo[vehicleid][vOwned] = strval(temp);
    cache_get_field_content(0, "owner",             vInfo[vehicleid][vOwner]);
       
    ChangeVehicleColor(vehicleid, vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2]);
    return 1;
}
Is it how it should be done? Are there any improvements I can make?
Thanks
Reply


Messages In This Thread
Trying to create a vehicle system - by oKzrh - 02.08.2012, 11:23
Re: Trying to create a vehicle system - by Misiur - 02.08.2012, 11:54
Re: Trying to create a vehicle system - by oKzrh - 02.08.2012, 11:59
Re: Trying to create a vehicle system - by Misiur - 02.08.2012, 13:12
Re: Trying to create a vehicle system - by oKzrh - 02.08.2012, 13:23

Forum Jump:


Users browsing this thread: 2 Guest(s)