Jump to content
Sign in to follow this  
PixeL_GaMMa

vehicle randomization data

Recommended Posts

Hi there, is it possible to grab the current vehicle seed of a randomized vehicle and load up that vehicle again?

e.g. If i create a pickup truck and it randomizes it without 1 of the doors, is it possible to grab the state of that vehicle and re-load it at a later time? I already have persistence for vehicles, but it only stores damage level and class of the vehicle, but I would also like to store the current state/randomized version of that vehicle.

-Colin

Share this post


Link to post
Share on other sites
26 minutes ago, PixeL_GaMMa said:

Hi there, is it possible to grab the current vehicle seed of a randomized vehicle and load up that vehicle again?

e.g. If i create a pickup truck and it randomizes it without 1 of the doors, is it possible to grab the state of that vehicle and re-load it at a later time? I already have persistence for vehicles, but it only stores damage level and class of the vehicle, but I would also like to store the current state/randomized version of that vehicle.

-Colin

 

That's not as easy as saving damage from hitpoints and fuel etc.

You'd need to iterate all animation names of the vehicle and save it, something like this might work:

animationnames cursorObject apply {cursorobject animationPhase _x};
//returns for offroad:
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.999995,0.999995,0,1,0,0,0,0,0,0,0,0,0.176895,0.174369,0.407346,0.404851,1,1,1,1,0,0,0,0,0,0.000280603,0,1,0,0,0,0,0,1,0,0,0,1,1,0,1,1,0,1,1,1,1,0,1.146,0,0,1.146,1.146,1.146,1.146,1.146,1.146,1.146,1.146,1.146]

The downside is, hiding a door or bumper also reduces a vehicles mass, like this:
 

configfile >> "CfgVehicles" >> "C_Offroad_01_F" >> "AnimationSources" >> "HideBumper1" >> "mass"//-50

So you'd need to take care of that as well.

Maybe there's a built in function who handles this properly.

 

Would be neat to have a single function that returns the current vehicle state, like setUnitLoadout/getUnitLoadout.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

Yep, ideally it would be a single seed for a vehicle, how i do it in some of my procedural projects is have a seed that can be re-used.

When the vehicle is generated, it is generated using a specific random seed/number, then if that seed is used again it would be generated in the exact same way, in which case it would be as simple as saving a single number and re-using it when calling createVehicle, that would have been perfect.

Your code actually may be ideal, I can also just store a total of the mass rather than iterate the missing pieces. I assume the centre of mass also changes depending on this? Thanks for your help :)

 

p.s. I already wrote a setCargoLoadout and getCargoLoadout which is ideal for vehicles and cargo boxes, I will release it once I make some improvements probably. :)

  • Like 1

Share this post


Link to post
Share on other sites

About mass, there's currently no way that I know of to get a default mass for the vehicle out of the config, only for spawned objects, and this mass again depends on which parts have been hidden or not.

 

Cheers

Share this post


Link to post
Share on other sites

Yep, but when the vehicle is saved (persistently) I can just do a getMass _veh; save this and when the vehicle is loaded, apply the animation data and then setMass ... etc

Edit: Implemented and tested, along with getObjectTextures, it all works perfectly, thanks again for help, I will post the functions soon :)

Share this post


Link to post
Share on other sites

I don't know about the missing doors but vehicle texture is pretty easy to set. Here's code from one of my missions:

 

// --- Save vehicle texture ---
// _type = vehicle type here!

_textureList = (getArray (configFile/"CfgVehicles"/_type/"texturelist")) select {typeName _x isEqualTo "STRING"};

_textureIndex = -1;
if(count _textureList > 0) then
{
_textureIndex = floor random (count _textureList); // Select one of the texture possibilities
};
// --- Load vehicle texture ---
if(_textureIndex >= 0) then // Has any extra textures?
{
_textureList = (getArray (configFile/"CfgVehicles"/_type/"texturelist")) select {typeName _x isEqualTo "STRING"}; // same as above
_text = _textureList select _textureIndex;

_textures = (getArray (configFile/"CfgVehicles"/_type/"texturesources"/_text/"textures"));

if(count _textures > 0) then // for some reason this can be empty
{
_texture = _textures select 0;
_veh setObjectTextureGlobal [0, _texture ];
};

};

You just need to pass there the vehicle type ("_type", "_veh" (and maybe some other variable)) and the texture is saved in "_textureIndex" variable

Share this post


Link to post
Share on other sites

OK just put these together, not tested since my game mode doesn't use them directly like this, but they should work

Source

//
// PX_fnc_getVehicleState :: Get vehicles current state - Note: this does not save inventory
// Author: Colin J.D. Stewart
// Usage: _stateblock = _vehicle call PX_fnc_getVehicleState;
//
PX_fnc_getVehicleState = {
    [
        typeOf _this,
        getPosATL _this,
        getDir _this,
        fuel _this,
        getMass _this,
        damage _this,
        getObjectTextures _this,
        animationnames _this apply {_this animationPhase _x}            // thanks Grumpy Old Man here for help
    ];
};

//
// PX_fnc_createVehicle :: Creates a vehicle from state array block via PX_fnc_getVehicleState
// Author: Colin J.D. Stewart
// Usage: _stateblock spawn PX_fnc_createVehicle;
//
PX_fnc_createVehicle = {
    private _veh = createVehicle [_this select 0, _this select 1, [], 0, "FORM"];
    _veh enableSimulationGlobal true;
    _veh setVariable ["BIS_enableRandomization", false];
                    
    _veh setDir _this select 2;
    _veh setFuel _this select 3;
    _veh setMass _this select 4;
    _veh setDamage _this select 5;
    
    private _textures = _this select 6;                    
    private _phaseData = _this select 7;
    
    { _veh setObjectTextureGlobal [_forEachIndex, _x]; } forEach _textures;
    { _veh animate [_x, (_phaseData select _forEachIndex)]; } forEach (animationNames _veh);

    _veh;
};

 

There are probably many improvements could be made here, but it's a start :)

 

Best Regards,

Colin

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, PixeL_GaMMa said:

There are probably many improvements could be made here, but it's a start :)

 

On a sidenote it wouldn't hurt to grab all variables stored on the vehicle and save them together with everything else, in case a mod/script needs it.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, Grumpy Old Man said:

 

On a sidenote it wouldn't hurt to grab all variables stored on the vehicle and save them together with everything else, in case a mod/script needs it.

 

Cheers


Excellent idea, we could also add per hit point damage

//
// PX_fnc_getVehicleState :: Get vehicles current state - Note: this does not save inventory
// Author: Colin J.D. Stewart
// Usage: _stateblock = _vehicle call PX_fnc_getVehicleState;
//
PX_fnc_getVehicleState = {
	[
		typeOf _this,
		getPosATL _this,
		getDir _this,
		fuel _this,
		getMass _this,
		(getAllHitPointsDamage _this) select 2,
		getObjectTextures _this,
		animationnames _this apply {_this animationPhase _x}			// thanks Grumpy Old Man here for help
	];
};

//
// PX_fnc_createVehicle :: Creates a vehicle from state array block via PX_fnc_getVehicleState
// Author: Colin J.D. Stewart
// Usage: _stateblock spawn PX_fnc_createVehicle;
//
PX_fnc_createVehicle = {
	private _veh = createVehicle [_this select 0, _this select 1, [], 0, "FORM"];
	_veh enableSimulationGlobal true;
	_veh setVariable ["BIS_enableRandomization", false];
					
	_veh setDir (_this select 2);
	_veh setFuel (_this select 3);
	_veh setMass (_this select 4);
	
	private _hitPoints = (_this select 5);
	{ _veh setHitPointDamage [_x, _hitPoints select _forEachIndex]; } forEach (getAllHitPointsDamage _veh) select 0;	
	
	private _textures = (_this select 6);					
	private _phaseData = (_this select 7);
	
	{ _veh setObjectTextureGlobal [_forEachIndex, _x]; } forEach _textures;
	{ _veh animate [_x, (_phaseData select _forEachIndex)]; } forEach (animationNames _veh);
	
	_veh;
};

 

Share this post


Link to post
Share on other sites

I've just updated my game mode to use the new functions, but it seems setHitPointDamage doesn't work globally, any idea what the problem could be?

Share this post


Link to post
Share on other sites
11 minutes ago, PixeL_GaMMa said:

I've just updated my game mode to use the new functions, but it seems setHitPointDamage doesn't work globally, any idea what the problem could be?

Did you execute it where the vehicle is local?

 

Cheers

Share this post


Link to post
Share on other sites

Yes, it is executed directly on server as it is created (see function above)

Share this post


Link to post
Share on other sites

Try it like this, locality can be weird:

_setHitPointDamages = {
	params ["_veh","_hitpoints"];
	{ _veh setHitPointDamage [_x, _hitPoints select _forEachIndex]; } forEach (getAllHitPointsDamage _veh) select 0;	

};

[_veh,_hitpoints] remoteExec ["_setHitpointDamages",_veh];

Made the hitpoint forEach its own function so remoteExec only runs once.

 

Cheers

Share this post


Link to post
Share on other sites

After a short break away from screen, another look and I see my mistake, I forgot to add additional select 0 to all hit points array.

 

{ _veh setHitPointDamage [_x, (_hitPoints select _forEachIndex)]; } forEach ((getAllHitPointsDamage _veh) select 0) select 0;    

In-fact a better way would be

{ _veh setHitIndex [_forEachIndex, _x, false]; } forEach (_this select 5);

 

Now it looks like damage is working, but a tire that is blown is back when re-loaded, I would have assumed the animation would correct this but it still does not work. :/ getting into the vehicle shows the wheels are damaged, but the physical model/animation for damage is not updated.

OK, a bit re-ordering, and it seems to be working:

 

//
// PX_fnc_createVehicle :: Creates a vehicle from state array block via PX_fnc_getVehicleState
// Author: Colin J.D. Stewart
// Usage: _stateblock spawn PX_fnc_createVehicle;
//
PX_fnc_createVehicle = {
    private _veh = createVehicle [_this select 0, _this select 1, [], 0, "FORM"];
    _veh enableSimulationGlobal true;
    _veh setVariable ["BIS_enableRandomization", false];
                    
    _veh setDir (_this select 2);
    _veh setFuel (_this select 3);
    _veh setMass (_this select 4);
    
    private _textures = (_this select 6);                    
    private _phaseData = (_this select 7);
    
    { _veh setObjectTextureGlobal [_forEachIndex, _x]; } forEach _textures;
    { _veh animate [_x, (_phaseData select _forEachIndex)]; } forEach (animationNames _veh);        
    { _veh setHitIndex [_forEachIndex, _x, false]; } forEach (_this select 5);    
    
    _veh;
};

 

  • 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
Sign in to follow this  

×