Author Topic: One timer: Check Vehicles' HP and Players' Z position  (Read 2317 times)

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
One timer: Check Vehicles' HP and Players' Z position
« on: October 05, 2013, 12:57:48 am »
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:

Code: [Select]
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
Code: [Select]
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:
Code: [Select]
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:

Code: [Select]
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

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #1 on: October 05, 2013, 12:21:49 pm »
Try this:
Code: [Select]
function onVehicleHealthChange( veh, oldhp, newhp )
{
     if ( newhp <= 850.0 )
     {
            Your code here.
     }
     
     return 1;
}
« Last Edit: October 05, 2013, 12:44:52 pm by Thijn »

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #2 on: October 05, 2013, 02:16:13 pm »
I tried with this event but it didn't worked.. that's why I made my own checker.
But I gave another try and now it works properly :/

Thank you, Thijn :)

But now I have another problem, the player is not ejected. (I think it will work if I will use a timer to eject him, but I want to avoid timers)
« Last Edit: October 05, 2013, 02:24:45 pm by [RBS]Moby »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #3 on: October 05, 2013, 03:34:21 pm »
I haven't tested it. But try doing player.Vehicle = null;

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #4 on: October 05, 2013, 03:52:22 pm »
I haven't tested it. But try doing player.Vehicle = null;

not work

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #5 on: October 05, 2013, 11:59:53 pm »
I think the function you need is:
Code: [Select]
player.RemoveFromVehicle()

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #6 on: October 07, 2013, 03:26:14 pm »
I think the function you need is:
Code: [Select]
player.RemoveFromVehicle()

Great, thank you.
In VC:MP is no function like this one. (and I thought that it was not made for squirrel for both games...)

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #7 on: October 07, 2013, 09:06:57 pm »
I think the function you need is:
Code: [Select]
player.RemoveFromVehicle()

Great, thank you.
In VC:MP is no function like this one. (and I thought that it was not made for squirrel for both games...)
Welcome to Liberty Unleashed, where there are actual useful scripting functions.

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #8 on: October 09, 2013, 06:31:53 pm »
Welcome to Liberty Unleashed, where there are actual useful scripting functions.

I know that Libery Unleashed has more and useful scripting functions than Vice City Multiplayer, but let me explain you why I didn't gave a search for this function "player.RemoveFromVehicle()" in the wiki:

In VC:MP, Pawn has "RemovePlayerFromVehicle(playerid)" function and I used it, but when I moved to Squirrel platform, there was (and it is still not) no function to remove the player from a vehicle, so I thought the respective function from pawn was just a reposition of the player, nothing more. (so not actually a game function for me)
So I started to use "player.Pos = player.Pos;", so that's why I didn't gave a search for "player.RemoveFromVehicle()" in the wiki.

By the way, the function "player.Pos" is bugged in LU because it is setting and the position of the  player's vehicle.

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: One timer: Check Vehicles' HP and Players' Z position
« Reply #9 on: October 10, 2013, 04:03:41 pm »
That's not bugged. That's how it should be.

 

© Liberty Unleashed Team.