Vehicle Armour Intention

Started by GangstaRas, May 27, 2015, 03:48 AM

Previous topic - Next topic

DizzasTeR

#15
So I did a couple of tests and surprisingly what I found is that the

GetVehicleCount();

is returning 0, that means a loop won't even start because the value of that is 0, and when I set it to any other number bigger than 0, for instance i got 5 vehicles, So I used this code

function VehicleImmunity()
{
    print( GetVehicleCount() );
    local veh;
    print("from function");
    for( local i = 0; i < 5; i++ )
    {
        print("forloopstep");
        local veh = FindVehicle( i );
        if( veh )
        {
            print("if statement");
            veh.Health = 99999;
            print("worked");
        }
    }
    print("end of the road");
}

and it worked totally fine, So basically you need to get correctly the total amount of vehicles you have, I don't know if that function is bugged or whatsoever but it is returning 0;

GangstaRas

A good find but now I found something myself. Is there a bug on FindVehicle as well? I remember experimenting with getting a vehicle's name and I must of did print(vehicle) and it gave me this 0x0000blahblah value. I bring that up because if the FindVehicle is suppose to be working would it have some 0x000blahblah value defined to veh rather than being empty?

function VehicleImmunity()
{
    print( GetVehicleCount() );
    local veh;
    print("from function");
    for( local i = 0; i < 106; i++ )
    {
        print("forloopstep");
        local veh = FindVehicle( i );
print ( veh );
        if( veh )
        {
            print("if statement");
            veh.Health = 99999;
            print("worked");
        }
    }
    print("end of the road");
}



DizzasTeR

That's not a bug, there is a function to get the namr of the vehicle, I guess it was GetVehicleNameFromModel, maybe that, can't check wiki right now i'm on phonr.

So basically you can just do:

local veh = FindVehicle( i );

if( veh )
{
        name = GetVehiclrNameFromModel( veh.Model );
print( name );
}

Have a try ;)

Thijn

printing FindVehicle should indeed print a pointer instead of null values, which means FindVehicle can't find your vehicle ;)
Might sound obvious, but do you actually have any vehicles?
If so, where and how do you add them? If it's in the config file, do you have the xmlconfloader plugin loaded?

GangstaRas

Quote from: Doom_Killer on Jun 17, 2015, 05:04 PMThat's not a bug, there is a function to get the namr of the vehicle, I guess it was GetVehicleNameFromModel, maybe that, can't check wiki right now i'm on phonr.

So basically you can just do:

local veh = FindVehicle( i );

if( veh )
{
        name = GetVehiclrNameFromModel( veh.Model );
print( name );
}

Have a try ;)

Thanks for the lookout Doom but I had that prob sorted a long time ago :), I just brought up that part.

And yh Thijn I have the vehicles, they're in the config file and xmlconfloader has been loaded. I have other vehicle commands that work perfectly fine so I'm not sure whats the deal here

Thijn

Try calling your custom function on, for example, onPlayerJoin. Maybe the vehicles aren't properly loaded when your script loads, for some unknown reason.

GangstaRas

Well I'll be...it works :D the 99999 value didn't register though, had to use something more realistic like 3000 but it works, if statement finally worked and all cars health are changed but as it is right now in its placement won't it run every time someone joins?

aXXo

#22
An explanation would be, that vehicles from the Config file are loaded after the onScriptLoad() executes. That explains GetVehicleCount being 0 and FindVehicle(1) returning NULL.

Anyway, config file was a practice in 0.3z and it is too old school for 0.4. The plugin which allows it to be read will probably not be updated in future. Quite a lot of 0.4 server settings are already not available in the config and you need to call them in your scripts anyway.

Get rid of the config.

GangstaRas

Quote from: aXXo on Jun 17, 2015, 07:03 PMAn explanation would be, that vehicles from the Config file are loaded after the onScriptLoad() executes. That explains GetVehicleCount being 0 and FindVehicle(1) returning NULL.

Anyway, config file was a practice in 0.3z and it is too old school for 0.4. The plugin which allows it to be read will probably not be updated in future. Quite a lot of 0.4 server settings are already not available in the config and you need to call them in your scripts anyway.

Get rid of the config.

Damn :/. Well I guess it's cars.nut time. Thank you all guys, its been quite a hell this one.