Jump to content
Sign in to follow this  
Dr3adn0ught35

Obtaining Object/Vehicle Position (Mainly Height)

Recommended Posts

I have recently just started to dive deeper into scripting and I wanted to start small.

As of now I am working on script to increase a vehicle's fuel consumption. I wanted to add in the script where if the vehicle went up a hill, It will use more fuel. to do this I am using a nested If statement to check if the vehicle's height increases over the span of a second.

My problem is, I do not know how to Obtain the vehicle's height. I have been digging into arma's files to try and find out how aircraft's HUD calculate its own height. Yet I cannot find arma 2's core class files (.cfg, Default, etc)

If anyone can provide the command to find a vehicle's present height, or the location of arma 2's core class files, It would be much appreciated

Share this post


Link to post
Share on other sites

Hi mate... welcome to the forum.

You would use getposATL... the ATL stands for Above Terrain Level.

_pos = getposATL _vehicle;    //returns a coordinate array [x,y,z];

_xcoord = _pos select 0;        //x coordinate
_ycoord = _pos select 1;        //y coordinate
_zcoord = _pos select 2;        //z coordinate ATL or height ATL

Share this post


Link to post
Share on other sites

I have inserted the code into the script and tinkered with it a bit, however it still isn't working. I have narrowed it down to the problem lying in...

if (_zcoord > _old) then

I am sure it has to do with the if statement since I have never been able to see a example of a IF statement with the condition comparing one array to another.

this is what I got (modified from the version I found on BI). The values are high so that I can test the script within a few seconds of starting the game.

init:

nul=[victor,0.5] execvm "Fuel_Consumption.sqf"; // victor being the name of the vehicle and 0.5 is the new rate of fuel used

_unit = _this select 0;
_rate = _this select 1;
_old = 0;

while {(alive _unit) and (fuel _unit > 0)} do
{ 
_pos = getposATL _unit;    //returns a coordinate array [x,y,z];
_xcoord = _pos select 0;        //x coordinate
_ycoord = _pos select 1;        //y coordinate
_zcoord = _pos select 2;        //z coordinate ATL or height ATL
if (isengineon _unit) then {
	if (_zcoord > _old) then 
               {
		_rate = _rate * 2.25;
		_unit setFuel ( Fuel _unit -_rate);
	} else 
               {
		_unit setFuel ( Fuel _unit -_rate);
               };			
};
_old = _zcoord;
sleep 1;
};

Share this post


Link to post
Share on other sites

In order to debug.... do you have -showcripterrors in your games shortcut?

Also look at using hint or hintsilent to see your variable values.... or diag_log to log those values to the .rpt file?

Using one or all of those little tools will help you find the errors. Get accustomed to using them from now.

Share this post


Link to post
Share on other sites

Presently I do have my game setup with -showscripterrors and I have also tried hint, but the script runs with no errors, it just considers the if statement to be false and moves on. as for the hint it doesn't do anything either

Share this post


Link to post
Share on other sites

This should work....shortened it a bit. Took out lines you don't need like getting the x and y coords. That was just to show you how to get all the individual coordinates from a position array. I'm pretty sure you'll follow it based on the stuff above.

_unit = _this select 0;
_rate = _this select 1;
_oldz = (getposATL _unit) select 2;

while {(alive _unit) and (fuel _unit > 0)} do { 
_zcoord = (getposATL _unit) select 2;        //z coordinate ATL or height ATL
if (isengineon _unit) then {
    if (_zcoord > _oldz) then {
        _rate = _rate * 2.25;
        _unit setFuel ( Fuel _unit -_rate);
        [color="#FF0000"] _oldz = _zcoord;[/color]
    } else {
        _unit setFuel ( Fuel _unit -_rate);
           };			
};
sleep 1;
};

Share this post


Link to post
Share on other sites

Try using getposASL.

getposATL will measure the vehicles distance above the ground it is sitting on. It will only alter a very small amount with terrain and vehicle position/angle variations.

getposASL measures the vehicle relative to the sea level position which stays constant while you either get further away or closer to it.

sh = this spawn
{
while {alive _this} do
{
	hint str((getposASL _this) select 2);
	sleep 0.1; 

};



};

Place the snippet of code in a vehicles init field to see how the z component of the position changes. Change the ASL to ATL in the code to see how that one doesn't really alter.

Hope this helps

Blake.

Share this post


Link to post
Share on other sites

Perfect! It works like a charm. thank you blake and twirly for helping sort this out now all I have to do is put this in my next mission

// nul=[nameofvehicle,rateofleak] execvm "Fuel_Consumption.sqf"; (I recommend 0.00025 for fateofleak for roughly 40 minutes of fuel)

_unit = _this select 0;
_old = 0;

while {(alive _unit) and (fuel _unit > 0)} do
{ 
_rate = _this select 1;
_pos = (getposASL _unit) select 2;    
if (isengineon _unit) then {
	if (_pos > _old) then {
		_rate = _rate * 15;
		_unit setFuel ( Fuel _unit -_rate);
	} else {
		_unit setFuel ( Fuel _unit -_rate);};			
};
_old = _pos;
sleep 1;
};

Share this post


Link to post
Share on other sites

In this post, f2ksel shows how to get the pitch of a vehicle. He's using a bis fnc so you'd need the functions module on the map.

http://forums.bistudio.com/showthread.php?130585-create-a-custom-script-trigger&p=2100096&viewfull=1#post2100096

If the vehicle is pitching up and has speed, then you can assume it's going up hill and increase it's fuel consumption.

Share this post


Link to post
Share on other sites

I stand corrected for the rateofleak I think 0.00027778 would suffice for 45 minutes with the engine at idle and the increase rate would be 1.25 for now

Edited by Dr3adn0ught35

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×