Saving vehicle damage
#1

Hi

I have this function that is supposed to save vehicle damage to the vehicle enum. This is in turn saved to the DB. Its running once every 30 seconds and the database call is every 3 minutes and when the player leaves.

When I spawn the vehicle is perfect.

Any ideas.

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]);

       
        }
   
    }
   
    return 1;

}
Reply
#2

You are not applying the vehicle damage anywhere?
https://sampwiki.blast.hk/wiki/UpdateVehicleDamageStatus
Reply
#3

This function that is run by a timer it updates the enum which is written to the database every 3 minutes and when the player leaves.

It's not even storing it to the database.

When the player rejoins and his vehicles is loaded is when I am applying the damage again.
Reply
#4

Your loop needs changing for a start. Vehicle IDs start at 1 and the highest ID is MAX_VEHICLES:

pawn Код:
for(i = 1; i <= MAX_VEHICLES; i++)
Regarding your actual problem - what is it?
Reply
#5

Quote:
Originally Posted by liam1412
Посмотреть сообщение
This function that is run by a timer it updates the enum which is written to the database every 3 minutes and when the player leaves.

It's not even storing it to the database.

When the player rejoins and his vehicles is loaded is when I am applying the damage again.
I'm guessing you're not showing us the whole code.
Show us the part in which you're saving the information onto files/uploading it to the database, and the part in which you're applying the saved damage (UpdateVehicleDamageStatus)
Reply
#6

Why don't you use OnVehicleDamageStatusUpdate anyway?
Reply
#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
#8

after further investigation IsValidVehicle(i) is returning false for all 2000 even though my vehicle is spawned
Reply
#9

I was wrong. Its getting to the enum but not the DB!
Reply
#10

Ok here is another thing liam, your cars will bug out if you save the HP below 250.0 the point where they are set on fire and explode in this case save their spawn position and health at 1000.0 or your going to have problems.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)