Liberty Unleashed
Scripting => Script Help => Topic started by: sseebbyy on October 04, 2013, 11:57:48 pm
-
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
-
Try this:
function onVehicleHealthChange( veh, oldhp, newhp )
{
if ( newhp <= 850.0 )
{
Your code here.
}
return 1;
}
-
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)
-
I haven't tested it. But try doing player.Vehicle = null;
-
I haven't tested it. But try doing player.Vehicle = null;
not work
-
I think the function you need is:
player.RemoveFromVehicle()
-
I think the function you need is:
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...)
-
I think the function you need is:
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.
-
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.
-
That's not bugged. That's how it should be.