Saving vehicle damage
#7

ok here is the full code

Here is the

pawn Код:
enum vehicleStats {
    vInternalId,
    vModelId,
    vColor1,
    vColor2,
    Float:vSpawnX,
    Float:vSpawnY,
    Float:vSpawnZ,
    Float:vSpawnA,
    vOwnerId,
    Float:vHealth,
    vFuelLevel,
    vPanelDamage,
    vDoorsDamage,
    vLightsDamage,
    vTyreDamage,
    vMod1,
    vMod2,
    vMod3,
    vMod4,
    vMod5,
    vMod6,
    vMod7,
    vMod8,
    vMod9,
    vMod10,
    vMod11,
    vMod12,
    vMod13,
    vMod14,
    vMod15,
    vMod16,
    vMod17,
    vPaintJob,
    vPlayerId
}
this is the vehicle part of the update code that runs every 3 mins. There is a very similar function that also updates all players vehicles when he leaves the server

pawn Код:
for(v=0; v < MAX_VEHICLES; v++)
    {
   
        if(IsValidVehicle(v))
        {
   
            format(vehicleQuery,sizeof(vehicleQuery),
            "UPDATE `playervehicles` SET vColor1='%i', vColor2='%i', vSpawnX='%f', vSpawnY='%f', vSpawnZ='%f', vSpawnA='%f', vOwnerId='%i', vHealth='%f', vFuelLevel='%i', vPanelDamage='%i',vDoorsDamage='%i', vLightsDamage='%i', vTyreDamage='%i', vMod1='%i',vMod2='%i',vMod3='%i',vMod4='%i',vMod5='%i',vMod6='%i',vMod7='%i',vMod8='%i',vMod9='%i',vMod10='%i',vMod11='%i',vMod12='%i',vMod13='%i',vMod14='%i',vMod15='%i',vMod16='%i',vMod17='%i',vPaintJob='$i' WHERE vInternalId='%i'",
            playerVehicles[v][vColor1],
            playerVehicles[v][vColor2],
            playerVehicles[v][vSpawnX],
            playerVehicles[v][vSpawnY],
            playerVehicles[v][vSpawnZ],
            playerVehicles[v][vSpawnA],
            playerVehicles[v][vOwnerId],
            playerVehicles[v][vHealth],
            playerVehicles[v][vFuelLevel],
            playerVehicles[v][vPanelDamage],
            playerVehicles[v][vDoorsDamage],
            playerVehicles[v][vLightsDamage],
            playerVehicles[v][vTyreDamage],
            playerVehicles[v][vMod1],
            playerVehicles[v][vMod2],
            playerVehicles[v][vMod3],
            playerVehicles[v][vMod4],
            playerVehicles[v][vMod5],
            playerVehicles[v][vMod6],
            playerVehicles[v][vMod7],
            playerVehicles[v][vMod8],
            playerVehicles[v][vMod9],
            playerVehicles[v][vMod10],
            playerVehicles[v][vMod11],
            playerVehicles[v][vMod12],
            playerVehicles[v][vMod13],
            playerVehicles[v][vMod14],
            playerVehicles[v][vMod15],
            playerVehicles[v][vMod16],
            playerVehicles[v][vMod17],
            playerVehicles[v][vPaintJob],
            playerVehicles[v][vInternalId]
            );
            mysql_function_query(connection, vehicleQuery, false, "", "");
       
        }

    }

This is the mysql write that updates when player leaves
pawn Код:
public updateSpecificPlayerAndVehicles(playerid)
{

    new playerQuery[1024];
    new vehicleQuery[1024];
    new v;

    format(playerQuery, sizeof(playerQuery),
    "UPDATE `playeraccounts` SET playerCash='%i', playerBank='%i', playerSpawnX='%f', playerSpawnY='%f', playerSpawnZ='%f', playerSpawnAngle='%f', playerWeaponSlot1='%i', playerWeaponAmmo1='%i', playerWeaponSlot2='%i', playerWeaponAmmo2='%i', playerWeaponSlot3='%i', playerWeaponAmmo3='%i',playerHasDrivingLicence='%i', playerHasBoatLicence='%i',playerHasPilotLicence='%i', playerHasFishingLicence='%i',playerAdminLevel='%i',playerFactionID='%i',playerFactionLevel='%i' WHERE userID='%i' LIMIT 1",
    playerVariables[playerid][pMoney],
    playerVariables[playerid][pBank],
    playerVariables[playerid][pSpawnX],
    playerVariables[playerid][pSpawnY],
    playerVariables[playerid][pSpawnZ],
    playerVariables[playerid][pSpawnA],
    playerVariables[playerid][pWs1],
    playerVariables[playerid][pWa1],
    playerVariables[playerid][pWs2],
    playerVariables[playerid][pWa2],
    playerVariables[playerid][pWs3],
    playerVariables[playerid][pWa3],
    playerVariables[playerid][pHasDrivingLicence],
    playerVariables[playerid][pHasBoatLicence],
    playerVariables[playerid][pHasPilotLicence],
    playerVariables[playerid][pHasFishingLicence],
    playerVariables[playerid][pAdminLevel],
    playerVariables[playerid][pFactionId],
    playerVariables[playerid][pFactionLevel],
    playerVariables[playerid][pInternalId]
    );
    mysql_function_query(connection, playerQuery, false, "", "");


    for(v=0; v < MAX_VEHICLES; v++)
    {

        if(playerVehicles[v][vPlayerId] == playerid)
        {

            format(vehicleQuery,sizeof(vehicleQuery),
            "UPDATE `playervehicles` SET vColor1='%i', vColor2='%i', vSpawnX='%f', vSpawnY='%f', vSpawnZ='%f', vSpawnA='%f', vOwnerId='%i', vHealth='%f', vFuelLevel='%i', vPanelDamage='%i',vDoorsDamage='%i', vLightsDamage='%i', vTyreDamage='%i', vMod1='%i',vMod2='%i',vMod3='%i',vMod4='%i',vMod5='%i',vMod6='%i',vMod7='%i',vMod8='%i',vMod9='%i',vMod10='%i',vMod11='%i',vMod12='%i',vMod13='%i',vMod14='%i',vMod15='%i',vMod16='%i',vMod17='%i',vPaintJob='$i' WHERE vInternalId='%i'",
            playerVehicles[v][vColor1],
            playerVehicles[v][vColor2],
            playerVehicles[v][vSpawnX],
            playerVehicles[v][vSpawnY],
            playerVehicles[v][vSpawnZ],
            playerVehicles[v][vSpawnA],
            playerVehicles[v][vOwnerId],
            playerVehicles[v][vHealth],
            playerVehicles[v][vFuelLevel],
            playerVehicles[v][vPanelDamage],
            playerVehicles[v][vDoorsDamage],
            playerVehicles[v][vLightsDamage],
            playerVehicles[v][vTyreDamage],
            playerVehicles[v][vMod1],
            playerVehicles[v][vMod2],
            playerVehicles[v][vMod3],
            playerVehicles[v][vMod4],
            playerVehicles[v][vMod5],
            playerVehicles[v][vMod6],
            playerVehicles[v][vMod7],
            playerVehicles[v][vMod8],
            playerVehicles[v][vMod9],
            playerVehicles[v][vMod10],
            playerVehicles[v][vMod11],
            playerVehicles[v][vMod12],
            playerVehicles[v][vMod13],
            playerVehicles[v][vMod14],
            playerVehicles[v][vMod15],
            playerVehicles[v][vMod16],
            playerVehicles[v][vMod17],
            playerVehicles[v][vPaintJob],
            playerVehicles[v][vInternalId]
            );
            mysql_function_query(connection, vehicleQuery, false, "", "");

        }

    }

}
And this updates the enum every 30 seconds


pawn Код:
public doVehicleDamageUpdates()
{

    new i;
    new panelsd, doorsd, lightsd, tyresd;
   
    for(i = 0; i < MAX_VEHICLES; i++)
    {
   
        if(IsValidVehicle(i))
        {
       
            GetVehicleDamageStatus(i, panelsd, doorsd, lightsd, tyresd);
           
            playerVehicles[i][vPanelDamage] = panelsd;
            playerVehicles[i][vDoorsDamage] = doorsd;
            playerVehicles[i][vLightsDamage] = lightsd;
            playerVehicles[i][vTyreDamage] = tyresd;
           
            GetVehicleHealth(i,playerVehicles[i][vHealth]);

       
        } else {
       
            printf("Vehicle ID %i is not valid",i);
           
        }
   
    }
   
    return 1;

}

When the player spawns the vehicle is undamaged even though it was knackered when I quit the server. The vehicle spawn code is not shown as it is irrelevant the data is never getting to the database.

I don't use the callback because I figure it could get very intensive is somebody is on a rampage crashing vehicles all over the shop.
Reply


Messages In This Thread
Saving vehicle damage - by liam1412 - 12.04.2013, 12:03
Re: Saving vehicle damage - by [XST]O_x - 12.04.2013, 12:07
Re: Saving vehicle damage - by liam1412 - 12.04.2013, 12:11
Re: Saving vehicle damage - by MP2 - 12.04.2013, 12:13
Re: Saving vehicle damage - by [XST]O_x - 12.04.2013, 12:17
Re: Saving vehicle damage - by MP2 - 12.04.2013, 12:21
Re: Saving vehicle damage - by liam1412 - 12.04.2013, 12:29
Re: Saving vehicle damage - by liam1412 - 12.04.2013, 12:45
Re: Saving vehicle damage - by liam1412 - 12.04.2013, 13:23
Re: Saving vehicle damage - by Pottus - 12.04.2013, 13:35

Forum Jump:


Users browsing this thread: 1 Guest(s)