Jump to content
scifer

How to find a vehicle's mass / weight

Recommended Posts

If I would try to learn a script language of a game and its difficulties then I would try to respect the work of the devs and the work of the wiki authors and the experience of the helping people as well.

I would not say all the time that I would do everything better. Cause I would know that there may reasons for all of the things which I may not understand fully...

  • Like 3

Share this post


Link to post
Share on other sites

It works! 😀

// MCA_fn_getVehicleMass.sqf.

// This function tries to get the mass of a vehicle.
// This is a hack, it may not work every time.

params ["_caller", "_vehClassName"];

if (!(isClass (configFile >> "CfgVehicles" >> _vehClassName))) exitWith { 0.0 };

private ["_callerPos", "_vehPos", "_veh", "_mass"];
_callerPos = position _caller;
_vehPos = [_callerPos select 0, _callerPos select 1, (_callerPos select 2) + 5000 + (random 2000)];
_veh = createVehicle [_vehClassName, _vehPos, [], 0, "FLY"];
_mass = getMass _veh;
deleteVehicle _veh;

_mass

 

Share this post


Link to post
Share on other sites

I understand that this game is difficult to develop and this game is unique. I very much appreciate the job of the developers.

But there is a moment. The "Operation Flashpoint: Cold War Crisis" was released in EU on June 22, 2001.

Now it is April, 2022. In the year 2022 I see the same bugs that were peresent in the good old Op. Flashpoint.

I like this game because of its freedom to create, its editor and its community.

I wish B.I.S. good luck in creating a new engine and releasing the fourth Arma.

I wish to see working towing with low gear mode for vehicles.

 

Share this post


Link to post
Share on other sites
12 hours ago, Waldemar 337 said:

It works! 😀


// MCA_fn_getVehicleMass.sqf.

// This function tries to get the mass of a vehicle.
// This is a hack, it may not work every time.

params ["_caller", "_vehClassName"];

if (!(isClass (configFile >> "CfgVehicles" >> _vehClassName))) exitWith { 0.0 };

private ["_callerPos", "_vehPos", "_veh", "_mass"];
_callerPos = position _caller;
_vehPos = [_callerPos select 0, _callerPos select 1, (_callerPos select 2) + 5000 + (random 2000)];
_veh = createVehicle [_vehClassName, _vehPos, [], 0, "FLY"];
_mass = getMass _veh;
deleteVehicle _veh;

_mass

 

If you don't mind me asking, why do you add a random value to the z coordinate of the vehicle's position? Does it provide any kind of benefit to your task?

 

I don't really know exactly how getMass works and so I cannot understand why a vehicle has to be flying high in order to get its mass but I trust that you have tested the function and works "properly".

Share this post


Link to post
Share on other sites

Short version of the answer is following.

In this "hack" script the vehicle is created in the sky above the player to minimize the possible collision with environment.

 

What does that mean ?

If several players start using this function, they will be creating a lot of mess and the possibility of collision will increase.

If the vehicle was created in the same place, it would limit the usage of the script to one function at the same time.

So, here I tried to minimize the possibility of collision using two methods.

  • First one -- player creates a temporary "hack" vehicle above him, X and Y coordinates of the created vehicle are the same as the player's X & Y. This minimizes possibility of collision between different players. Note that objects larger than a player increase the possibility of collision greatly because objects having the same altitude may collide.
  • Second one -- a random number is used in the Z coordinate (height) to minimize possibility of collision for the same player if he calls this function several times simultaneously. As we know Arma's engine uses some kind of scheduler which is non-managed, i.e. player can not control the scheduler and execution of the code. So, this is just a safety measure for parallel code execution.

Of course, if the vehicle is very big, much bigger than a player, and a neighbour player creates his flying vehicle at the same time, there will be a great possibility of collision. So, this workaround will not work every time. And again, this does not work all the time, as the random number generator may generate two equal numbers and all this "hack" will not work.

 

The good solution would be to create a special controller which would allow only one created vehicle instance at the time, but it is too complicated for this situation. Such functions as 'getMass' for vehicle classes should be provided by game developers, because they have access to the game engine. The source code of the game is not accessible by the community, so we do not have to do their job.

 

Share this post


Link to post
Share on other sites
18 minutes ago, Waldemar 337 said:

The best solution would be

... to avoid such "hacks" if possible somehow.

 

upto now you did not show any line of code which would need such ugly "hack" to complete its "mission".

 

Share this post


Link to post
Share on other sites
10 minutes ago, sarogahtyp said:

... to avoid such "hacks" if possible somehow.

Yes, I wrote the same.

Such functions should be provided by the game developers.

Quote

The source code of the game is not accessible by the community, so we do not have to do their job.

But we do not have access to the game engine.

If you know how to get the theoretical vehicle's mass by its class name, please let the community know it.

I did what I could instead of complaining. I provided my piece of shitty code.

I would do it better if I could change the game engine, but I have no access to it, and will never have it.

 

10 minutes ago, sarogahtyp said:

upto know you did not show any line of code which would need such ugly "hack" to complete its "mission".

You are very curious. I am writing a simple add-on for the game which will be some kind of a vehicle viewer.

I will publish it on Steam very soon.

Share this post


Link to post
Share on other sites
3 hours ago, sarogahtyp said:

... to avoid such "hacks" if possible somehow.

 

upto now you did not show any line of code which would need such ugly "hack" to complete its "mission". 

 

But I provided an answer to your question before. It was in a previous message on the first page.

It reminds me a situation. A person on a street asks you what the time it is. And instead of telling the time, you are starting to find reasons why you should not bother telling the time.

Quote

- Why do you need this ?

- What do you need this for ?

- Are you sure that you need this ? Time does not exist. Why do you need it ?

LOL 😂

Let us be kind to other people. Please. Humanity is the key to all questions on this planet. Especially at this moment of time ...

Share this post


Link to post
Share on other sites

The reason for not telling you the time is that i dont know which timezone on which planet in which system you need. Also I dont know if i actually have the knowledge bout the time in that specific timezone.

 

For the scripts of the vehicle viewer you described above I have no bettet solution yet except that i would not do the "hack" when the viewer chooses a vehicle but on mission start for all vehicles and store it...

  • Like 1

Share this post


Link to post
Share on other sites

Also i would look for a formula which uses config entries like armor and hit point values and maybe some other values plus a factor to get similar values as getmass provides. That would avoid your "hack"

Share this post


Link to post
Share on other sites

Sounds interesting. Thank you.

 

I have a couple of questions.

 

1. How much memory will it take to store a big array of arrays ?

 

2. Does Arma engine offer a hash map or some similar type for storing big data ?

Searching the 1M-item-sized array using a simple forEach would take a lot of time.

 

Share this post


Link to post
Share on other sites

@Waldemar 337 thanks for the answer, but to be honest I should be more precise. Is there a good reason to make a vehicle up in the sky rather than creating it on terrain and then deleting it right after you acquire the information you need?

Share this post


Link to post
Share on other sites

ZaellixA,

the simple answer is following: land is smaller than air.

 

If we calculate the square of the available land and compare it with the volume of the air above the land, we can see that the probability of vehicle collision on land is much bigger than in the air. If we create temporary vehicles at the altitude of, for example, from 100 kilimeters up to 150 kms, the chances for them to collide will be very close to 0.001% or so. Here, by collisions I mean not only collisions between temporary objects, but also collisions with game objects (player's vehicles).

 

Moreover, I wanted to make a simple and at the same time safe method to get vehicle's parameters without storing big data in hidden objects like many scripts do, which I am not a fan of.

 

  • Like 1

Share this post


Link to post
Share on other sites

OK, so this is more of a "safeguard" than an actual necessity to get the mass of the vehicle right? I mean, that you could very well place a vehicle in the 3den editor and then use the same command on it to get the mass, then delete it... Do I understand it correctly or am I missing something??

Share this post


Link to post
Share on other sites

The current game engine does not allow to get the mass without creating a vehicle. Vehicle's class available to the comminity does not have a mass parameter. I found an only way to get the mass of a vehicle class by creating and deleting a vehicle. So, creation and deletion is the only way possible for me at this moment. If someone knows a better way, let us know.

 

I did not like the way that was suggested by sarogahtyp because that way creates other difficulties. Among those difficulties I could find following.

 

1. Requirement to make some measurements of all possible vehicle classes in the game.

 

1.1. This makes mission initialization fragile. If some add-on breaks the initialization process of these calculations, we will have to make them again and again.

 

1.2. Big data needs big space. Who and where will store all the encyclopedia of class parameters ? I thought that vehicle classes were created right for that very purpose. Game modders do not need to make the game engine themselves.

 

2. Requirement to search data in a big data storage. All this takes time.

 

Concerning the air vs land question. My choice was done only because of the probability of collisions. Volume of the air is much larger that the square of the land. I have told it before and I repeat it again.

 

Quote

you could very well place a vehicle in the 3den editor

If I placed the vehicle in the editor then how would people use this script and add-on in their scripts and games ?

 

I hope that I managed to answer your question.

  • Like 1

Share this post


Link to post
Share on other sites
On 4/18/2022 at 6:01 PM, sarogahtyp said:

The reason for not telling you the time is that i dont know which timezone on which planet in which system you need. Also I dont know if i actually have the knowledge bout the time in that specific timezone.

Do you always talk to people this way ?

You are very positive and friendly. Thank you all guys.

😍

Share this post


Link to post
Share on other sites
1 hour ago, Waldemar 337 said:

Do you always talk to people this way ?

Just depends!

 

Considering the effort required to determine the weight of a vehicle, I don't think it makes sense to display it. Or to put it in the words of my 15-year-old son: no player in arma is interested in the weight of a vehicle.

 

Share this post


Link to post
Share on other sites

Referring to this topic:

 

the most efficient way seems to use 

createSimpleObject (EDIT: createVehicleLocal because getMass does not work on simple objects).

with the local parameter set true and using a position underneath the ground.

Share this post


Link to post
Share on other sites
3 hours ago, Waldemar 337 said:

1. Requirement to make some measurements of all possible vehicle classes in the game.

Its not a problem to spawn/despawn 1000 vehicles local on server within some seconds before any player has joined.

 

3 hours ago, Waldemar 337 said:

 

1.1. This makes mission initialization fragile. If some add-on breaks the initialization process of these calculations, we will have to make them again and again.

What?

 

3 hours ago, Waldemar 337 said:

 

1.2. Big data needs big space. Who and where will store all the encyclopedia of class parameters ? I thought that vehicle classes were created right for that very purpose. Game modders do not need to make the game engine themselves.

 

2. Requirement to search data in a big data storage. All this takes time.

1000 times the classname as key and the mass as data stored in a hashmap. There is no problem with memory usage and not with the access time.

  • Like 2

Share this post


Link to post
Share on other sites

createSimpleObject does not work for getting the mass.

 

This script will create the hashmap for all vehicles. it can be tested on debug console and will hint the number of vehicles and the runtime used for the script:

private [ "_startTime", "_d", "_runtime", "_className" ];

sneakyPeakyGlobalMassHashmap = createHashMap;

isNil {
 _startTime = diag_tickTime;

 {
  _className = configName _x;
  _d = _className createVehicleLocal [ 0, 0, 0 ];
  sneakyPeakyGlobalMassHashmap set [ _className, ( getMass _d ) ];
  deleteVehicle _d;
 } forEach
 ( "_classname = configName _x; getNumber (_x >> 'scope') isEqualTo 2 && (_classname isKindOf 'Helicopter' ||
                    _classname isKindOf 'Plane' || _className isKindOf 'Car' || _className isKindOf 'Motorcycle' || _className isKindOf 'Tank' ||
                    _className isKindOf 'Ship_F') " configClasses (configFile >> "CfgVehicles") );

 _runtime = diag_tickTime - _startTime;
};

hint format [ "Count: %1 - Time: %2", (count sneakyPeakyGlobalMassHashmap), _runtime];

 

If u really want to get the mass within the mission then I recommend to use createVehicleLocal to "hide" the spawned vehicle from other connected players. You will also have no vehicle collisions this way.

  • Like 3

Share this post


Link to post
Share on other sites

If you know the mods that will be used during the mission beforehand, you can run @sarogahtyp 's script in editor, copy the contents of the generated hashmap to clipboard and paste it into the mission scripts. That way you don't have to spawn a bunch of vehicles during play and you will have the data available instantaneously.

  • Like 3

Share this post


Link to post
Share on other sites
59 minutes ago, _foley said:

If you know the mods that will be used during the mission beforehand, you can run @sarogahtyp 's script in editor, copy the contents of the generated hashmap to clipboard and paste it into the mission scripts. That way you don't have to spawn a bunch of vehicles during play and you will have the data available instantaneously.

 

@Waldemar 337 

I think @_foley's suggestion is a good idea. Normally I am more in favour of a dynamic solution, but if you have to spawn vehicles all the time, then I am also more in favour of hardcoding or a dynamic/hardcoding-hybrid:

 

In your vehicle viewer mod you could hard code the data for the most common vehicle mods like CUP and RHS and of course for the vanilla vehicles.

You could also use the ugly solution (using createVehicleLocal) for all vehicles that are not found in the hashmap.

This way you have a fast, always working solution which mostly will not spawn vehicles for just viewing them with your mod.

  • Like 1

Share this post


Link to post
Share on other sites
On 4/21/2022 at 4:36 PM, Waldemar 337 said:

The current game engine does not allow to get the mass without creating a vehicle. Vehicle's class available to the comminity does not have a mass parameter. I found an only way to get the mass of a vehicle class by creating and deleting a vehicle. So, creation and deletion is the only way possible for me at this moment. If someone knows a better way, let us know.

 

I did not like the way that was suggested by sarogahtyp because that way creates other difficulties. Among those difficulties I could find following.

 

1. Requirement to make some measurements of all possible vehicle classes in the game.

 

1.1. This makes mission initialization fragile. If some add-on breaks the initialization process of these calculations, we will have to make them again and again.

 

1.2. Big data needs big space. Who and where will store all the encyclopedia of class parameters ? I thought that vehicle classes were created right for that very purpose. Game modders do not need to make the game engine themselves.

 

2. Requirement to search data in a big data storage. All this takes time.

 

Concerning the air vs land question. My choice was done only because of the probability of collisions. Volume of the air is much larger that the square of the land. I have told it before and I repeat it again.

 

If I placed the vehicle in the editor then how would people use this script and add-on in their scripts and games ?

 

I hope that I managed to answer your question.

Yeah, I get your approach and the reasoning behind it, thanks.

 

To be honest, I haven't looked at the script you created so I can't really suggest anything, but maybe you could modify/extend it to scan for all 3den placed vehicles at the start of the mission and get the mass of those vehicles. There may be a chance that the players or mission creators won't use more than those vehicles. So, the need to run the script after the mission start will be reduced to the spawn of new types of vehicles.

 

You could make the script to use some kind of memoization in order to avoid being executed for the same type of vehicle more than once. I am just throwing suggestions here from an end-user's perspective and not implying that the script needs improvements. As I said, I haven't seen the script so I can't really have an opinion on the implementation.

  • Like 1

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

×