I want to avoid the explosions in my server because them are removing my objects, so I am not using Rocket Launchers and bombs.
But there is another way: Vehicles Way. (one word: "BOOM!!!")
So I removed the posibility to have less than 850.0 hp on a vehicle, but there appear an error everytime a vehicle has under 850.0 hp:
AN ERROR HAS OCCURED [the index 'Health' does not exist]
For this "solution" I'm using a timer that calls "CheckVHP" at every 500ms.
By the way, that error doesn't affect the server, but it appears again and again and again.
Somehow I get use with this error.
This is the code:
first try
function CheckVHP( )
{
local veh, vhp, v;
local plr, i;
for(v = 0; v < GetVehicleCount(); v++) {
for(local plr, i = 0; i <= GetMaxPlayers(); i++) {
plr = FindPlayer(i);
if(plr) {
if(plr.Pos.z < 28.0 && plr.Spawned) {
plr.Health = 0.0;
}
}
}
veh = FindVehicle(v);
if(veh) {
vhp = veh.Health;
if(vhp <= 850.0) {
//print(veh);
for(i = 0; i <= GetMaxPlayers(); i++) {
plr = FindPlayer(i);
if(plr) {
if(plr.Vehicle == veh) {
plr.Pos = Vector(plr.Pos.x, plr.Pos.y, plr.Pos.z + 3);
}
}
}
vhp = 1000.0;
veh.Pos = Vector(0,0,0);
veh.Respawn();
}
}
}
}
second try:
function CheckVHP( )
{
local veh, vhp, v, plr, i;
for(v = 0; v < GetVehicleCount(); v++) {
for(i = 0; i <= GetMaxPlayers(); i++) {
veh = FindVehicle(v);
plr = FindPlayer(i);
if(veh || plr) {
if(veh && plr) {
vhp = veh.Health;
if(vhp <= 850.0) {
if(plr.Vehicle == veh) {
plr.Pos = Vector(plr.Pos.x, plr.Pos.y, plr.Pos.z+3);
vhp = 1000.0;
veh.Pos = Vector(0,0,0);
veh.Respawn();
} else {
vhp = 1000.0;
veh.Pos = Vector(0,0,0);
veh.Respawn();
}
}
} else {
if(veh) {
vhp = veh.Health;
if(vhp <= 850.0) {
vhp = 1000.0;
veh.Pos = Vector(0,0,0);
veh.Respawn();
}
} else if(plr) {
if(plr.Pos.z < 28.0 && plr.Spawned) {
plr.Health = 0.0;
}
}
}
}
}
}
}
In the second try, I wanted to make it a bit more organized, but it shows the same error, at the same line:
vhp = veh.Health;
But how I said, I get used with it.
By the way, I tried to eject the player from vehicle before its respawn because the ped is going with the car to coords 0, 0, 0, but I failed... it is not ejected... I remade (or tried to fix) the script many times, but I couldn't fix it.
I have there and a little script that kills every player that has the Z coord under 29. (don't ask why, I just need it for my server.
So... can someone tell me how to fix it ? And maybe there is a way that removes and that error about Health.
(Conclusion: I want this function to check vehicles' hp, eject players that are in a vehicle with hp under 850.0, and kill every ped that has Z coord under 29)
With respect,
Seby