19.01.2013, 01:31
Alright, so I'm attempting to make a Seatbelt/Helmet system work on my server. What it does is it damages the player if the vehicle they're driving or a passenger of gets damaged as well. It turned out fine, but whenever the vehicle respawns or despawns, the driver and passenger(s) die.
Further explanation:
Player-owned vehicles on my server are dynamic. They only spawn when the actual owner is online. Sometimes, the vehicle owner disconnects and the passenger(s) inside their vehicle dies, because the vehicle despawned. This also happens when the vehicle owner uses the /park command on their vehicle. The command will save the vehicle's location and respawn it right there. Upon respawning, the driver dies.
I think the cause of the problem is the fact that the vehicle disappears, leading the code to think that the vehicle was damaged down to 0 HP.
Here's the code I'm using:
Extra note:
The driver and passenger(s) don't lose HP if they have their seatbelt/helmet on so I tried despawning a vehicle while the driver and passenger(s) had their seatbelt on. They didn't die. I'm thinking of kicking the driver and passenger(s) out of the vehicle would be a good solution. You guys got any suggestions or better ideas?
Much appreciated.
Further explanation:
Player-owned vehicles on my server are dynamic. They only spawn when the actual owner is online. Sometimes, the vehicle owner disconnects and the passenger(s) inside their vehicle dies, because the vehicle despawned. This also happens when the vehicle owner uses the /park command on their vehicle. The command will save the vehicle's location and respawn it right there. Upon respawning, the driver dies.
I think the cause of the problem is the fact that the vehicle disappears, leading the code to think that the vehicle was damaged down to 0 HP.
Here's the code I'm using:
Код:
if(IsPlayerInAnyVehicle(playerid) == 1 && SeatbeltStatus[playerid] == 0) { new Float:TempCarHealth; GetVehicleHealth(GetPlayerVehicleID(playerid), TempCarHealth); new Float:Difference = floatsub(CarHealth[playerid], TempCarHealth); if((floatcmp(CarHealth[playerid], TempCarHealth) == 1) && (floatcmp(Difference,100.0) == 1)) { Difference = floatdiv(Difference, 10.0); new Float:OldHealth; GetPlayerHealth(playerid, OldHealth); SetPlayerHealth(playerid, floatsub(OldHealth, Difference)); } CarHealth[playerid] = TempCarHealth; } else { CarHealth[playerid] = 0.0; }
The driver and passenger(s) don't lose HP if they have their seatbelt/helmet on so I tried despawning a vehicle while the driver and passenger(s) had their seatbelt on. They didn't die. I'm thinking of kicking the driver and passenger(s) out of the vehicle would be a good solution. You guys got any suggestions or better ideas?
Much appreciated.
![Smiley](images/smilies/smile.png)