SA-MP Forums Archive
Updating vehicle damage - when? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Updating vehicle damage - when? (/showthread.php?tid=429878)



Updating vehicle damage - when? - liam1412 - 11.04.2013

So I am saving all vehicle damage to the enum which in turn goes to the database. At what point should I update the enum??


Re: Updating vehicle damage - when? - Faisal_khan - 11.04.2013

Run a loop under OnPlayerUpdate to check the vehicles. Maybe this will work out. Not sure.


Re: Updating vehicle damage - when? - liam1412 - 11.04.2013

I was thinking about doing a processVehicleDamage() function on a timer every 30 seconds. Would that be heavy on resources.


Re: Updating vehicle damage - when? - LetsOWN[PL] - 11.04.2013

Hi.
... I don't want to give bad advise or something, but I would do it when player leaves vehicle (using OnPlayerExitVehicle public).
Seems most optimal.

Greetz,
LetsOWN



Re: Updating vehicle damage - when? - park4bmx - 11.04.2013

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
Run a loop under OnPlayerUpdate to check the vehicles. Maybe this will work out. Not sure.
simply the worst way you can think of !
Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Hi.
... I don't want to give bad advise or something, but I would do it when player leaves vehicle (using OnPlayerExitVehicle public).
Seems most optimal.

Greetz,
LetsOWN
What if the player never leaves the car ?
e.g explodes.

A good way is going to be to use the vehicles damage status update callback
OnVehicleDamageStatusUpdate
NOTE: if you want to go fully pro on this u can make it check how fast its updating the status so there is no overwriting.


Re: Updating vehicle damage - when? - Faisal_khan - 11.04.2013

Quote:
Originally Posted by liam1412
Посмотреть сообщение
I was thinking about doing a processVehicleDamage() function on a timer every 30 seconds. Would that be heavy on resources.
Yeah that won't cause a problem. That was what I thought earlier before posting here.
Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Hi.
... I don't want to give bad advise or something, but I would do it when player leaves vehicle (using OnPlayerExitVehicle public).
Seems most optimal.

Greetz,
LetsOWN
No I won't do that.

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
simply the worst way you can think of !


What if the player never leaves the car ?
e.g explodes.

A good way is going to be to use the vehicles damage status update callback
OnVehicleDamageStatusUpdate
Damn this was added in 0.3a and how could I never come across this!


Re: Updating vehicle damage - when? - liam1412 - 11.04.2013

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
simply the worst way you can think of !


What if the player never leaves the car ?
e.g explodes.

A good way is going to be to use the vehicles damage status update callback
OnVehicleDamageStatusUpdate
NOTE: if you want to go fully pro on this u can make it check how fast its updating the status so there is no overwriting.
I could see this getting nasty. IE if someone goes on a rampage smashing into vehicles etc, that's a lot of writes. I'm not sure how I would check the speed it was updating to prevent this.


Re: Updating vehicle damage - when? - park4bmx - 11.04.2013

after each update store the current time by how much it passed
pawn Код:
//global variables!
new Hour, Minute, Second;

//the callback
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new nHour, nMinute, nSecond;
    gettime(nHour, nMinute, nSecond);
    if(nHour => Hour  && nMinute => Minute && nSecond > Second+2)//the simplest check, ofc it can be more advanced(the +2 add another 2sec)
    {
        gettime(Hour, Minute, Second);//update the last time it updated
        //run your save
    }
    return 1;
}
im not sure about the check as the gettime is using Unix time