Jump to content
dealman

Creating Modules Only With CreateVehicleLocal?

Recommended Posts

I'm working on a mission where the players will spawn around a burning helicopter wreck, since it's just a regular wreck I want to add some effects(modules) to make it a bit prettier. I had it working with the editor no problem, but I want to make the mission a bit more dynamic, so people can easily add various things.

 

The problem I'm having is that I can't seem to use createVehicle to spawn the modules, but it works with createVehicleLocal. I'm not too familiar with how locality works in ArmA 3, I understand the whole ownership thing - but to execute things on the server, one client or all clients is a bit confusing. I'm fairly sure I'll need to use BIS_fnc_MP for this, but was hoping there'd be some approach I can do directly via initServer.sqf to keep it clean?

 

This is what I currently have, it's a bit messy and I haven't refactored it yet so there's probably a more efficient way of doing this.

Spoiler

// Settings
wreckModels = ["Land_UWreck_MV22_F"];
wreckEffects = [
	[["ModuleEffectsFire_F", [1.79785, -5.63281, -2.54846]], ["ModuleEffectsFire_F", [1.77148, 0.065918, -2.7937]], ["ModuleEffectsSmoke_F", [2.88574,-0.0478516,-3.69666]]]
];
wreckEffectsParams = [
	[[["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]]]
];
wreckPositions = [[10493.2, 7938.7, 0]];

// Logic Variables
heliWreck = objNull;
heliWreckEffects = [];

wreckSetup = [] spawn {
	// Spawn Wreck at a Random Spawn Location
	_spawnPos = wreckPositions call BIS_fnc_selectRandom;
	_wreckModel = wreckModels call BIS_fnc_selectRandom;
	_safePos = [_spawnPos, 0, 200, 0, 0, 0.15, 0] call BIS_fnc_findSafePos;
	heliWreck = _wreckModel createVehicle _safePos;
	heliWreck setDir (floor random 361);
	// Setup Effects if Applicable
	_wreckIndex = wreckModels find _wreckModel;
	{
		_effectClass = _x select 0;
		_effectPosRelative = _x select 1;
		_effectPosWorld = (heliWreck modelToWorld _effectPosRelative);
		_effectObject = _effectClass createVehicleLocal (heliWreck modelToWorld _effectPosRelative);
		// Set Effect Params if Applicable
		{
			{
				_effectObject setVariable [_x select 0, _x select 1];
			} forEach _x;
		} forEach (wreckEffectsParams select _wreckIndex);		
	} forEach (wreckEffects select _wreckIndex);
};

 

 

This works as intended in the editor and when I host my own server, but I'm fairly sure the modules would only be created for the host since I have to use createVehicleLocal.

 

So I have 2 questions:

1. Why is it that modules have to be created via createVehicleLocal and not createVehicle?

2. What would be the best approach to have these modules created for all clients?

Share this post


Link to post
Share on other sites
6 hours ago, dealman said:

I'm working on a mission where the players will spawn around a burning helicopter wreck, since it's just a regular wreck I want to add some effects(modules) to make it a bit prettier. I had it working with the editor no problem, but I want to make the mission a bit more dynamic, so people can easily add various things.

 

The problem I'm having is that I can't seem to use createVehicle to spawn the modules, but it works with createVehicleLocal. I'm not too familiar with how locality works in ArmA 3, I understand the whole ownership thing - but to execute things on the server, one client or all clients is a bit confusing. I'm fairly sure I'll need to use BIS_fnc_MP for this, but was hoping there'd be some approach I can do directly via initServer.sqf to keep it clean?

 

This is what I currently have, it's a bit messy and I haven't refactored it yet so there's probably a more efficient way of doing this.

  Hide contents


// Settings
wreckModels = ["Land_UWreck_MV22_F"];
wreckEffects = [
	[["ModuleEffectsFire_F", [1.79785, -5.63281, -2.54846]], ["ModuleEffectsFire_F", [1.77148, 0.065918, -2.7937]], ["ModuleEffectsSmoke_F", [2.88574,-0.0478516,-3.69666]]]
];
wreckEffectsParams = [
	[[["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]]]
];
wreckPositions = [[10493.2, 7938.7, 0]];

// Logic Variables
heliWreck = objNull;
heliWreckEffects = [];

wreckSetup = [] spawn {
	// Spawn Wreck at a Random Spawn Location
	_spawnPos = wreckPositions call BIS_fnc_selectRandom;
	_wreckModel = wreckModels call BIS_fnc_selectRandom;
	_safePos = [_spawnPos, 0, 200, 0, 0, 0.15, 0] call BIS_fnc_findSafePos;
	heliWreck = _wreckModel createVehicle _safePos;
	heliWreck setDir (floor random 361);
	// Setup Effects if Applicable
	_wreckIndex = wreckModels find _wreckModel;
	{
		_effectClass = _x select 0;
		_effectPosRelative = _x select 1;
		_effectPosWorld = (heliWreck modelToWorld _effectPosRelative);
		_effectObject = _effectClass createVehicleLocal (heliWreck modelToWorld _effectPosRelative);
		// Set Effect Params if Applicable
		{
			{
				_effectObject setVariable [_x select 0, _x select 1];
			} forEach _x;
		} forEach (wreckEffectsParams select _wreckIndex);		
	} forEach (wreckEffects select _wreckIndex);
};

 

 

This works as intended in the editor and when I host my own server, but I'm fairly sure the modules would only be created for the host since I have to use createVehicleLocal.

 

So I have 2 questions:

1. Why is it that modules have to be created via createVehicleLocal and not createVehicle?

2. What would be the best approach to have these modules created for all clients?

Try to use the alternative syntax for create vehicle, i had this issue with some scripts too, if that does not fix it lemme know
https://community.bistudio.com/wiki/createVehicle
 

Share this post


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

Try to use the alternative syntax for create vehicle, i had this issue with some scripts too, if that does not fix it lemme know
https://community.bistudio.com/wiki/createVehicle
 

 

Hey, thanks for the reply! I just tried using the alternative syntax and it does not work. Can't even spawn it at player pos using the debug console, I have to use createVehicleLocal for whatever reason. I guess this may be intended behavior, but I'm not entirely sure what the best approach would be to create this locally for every client.

Share this post


Link to post
Share on other sites
5 hours ago, dealman said:

was hoping there'd be some approach I can do directly via initServer.sqf to keep it clean?

Hi dealman, I am in favor of using the event scripts initServer.sqf and initPlayerLocal.sqf in keeping things clean

 

6 hours ago, dealman said:

1. Why is it that modules have to be created via createVehicleLocal and not createVehicle?

I believe this is related to the nature of particle effects in particular, rather than a general rule ?

 

6 hours ago, dealman said:

2. What would be the best approach to have these modules created for all clients?

I've been using init.sqf at startup to launch scripts intended to both the server and client, then remoteExec afterwards

Share this post


Link to post
Share on other sites
23 minutes ago, Nikander said:

Hi dealman, I am in favor of using the event scripts initServer.sqf and initPlayerLocal.sqf in keeping things clean

 

I believe this is related to the nature of particle effects in particular, rather than a general rule ?

 

I've been using init.sqf at startup to launch scripts intended to both the server and client, then remoteExec afterwards

 

Aye, that's the list I'm following to make sure the code I need is executed at the right time. While I wholly understand that particle effects are client-sided for obvious reasons, I was under the assumption the server could still create it "for" the client.

 

I did read about remoteExec earlier as I knew I'd have to use either that or BIS_fnc_MP, but what initially had me confused was the syntax of createVehicle/createVehicleLocal. Where you first specify the vehicle class, then the function and then the position and rest of the arguments.

But this shouldn't be a problem using the alternative syntax I imagine, that's what you get for staying up too long - you overlook things. :)

 

Edit:

So I gave this a shot which didn't work and resulted in an error inside xxx.

["ModuleEffectsFire_F", (getPosATL player)] remoteExec ["createVehicleLocal", 0];

And just to make sure I wasn't misusing it, I tried to create a building using the same syntax - which did work, the building showed up. But the fire module for whatever reason does not. For reference this is the error it output in the RPT file;
 

Spoiler

if (_damage > 0) then {_emitter setParticleFire [0.6*_damage, 0>
10:19:36   Error position: <_emitter setParticleFire [0.6*_damage, 0>
10:19:36   Error Undefined variable in expression: _emitter
10:19:36 File A3\modules_f\Effects\functions\fn_moduleEffectsFire.sqf, line 49
10:19:36 Error in expression <itter") select 0;
_pos = getPos _logic;
_emitter setPos _pos;


_colorRed = _log>
10:19:36   Error position: <_emitter setPos _pos;


_colorRed = _log>
10:19:36   Error Undefined variable in expression: _emitter
10:19:36 File A3\modules_f\Effects\functions\fn_moduleEffectsFire.sqf, line 18

 

 

What peculiar here is that using that very same function with the same parameters on the server works(of course it's created for the server, not the clients). This is the syntax I used then;
 

_effectObject = _effectClass createVehicleLocal (heliWreck modelToWorld _effectPosRelative);
// "ModuleEffectsFire_F" createVehicleLocal (position);

 

Share this post


Link to post
Share on other sites
31 minutes ago, dealman said:

 

Hey, thanks for the reply! I just tried using the alternative syntax and it does not work. Can't even spawn it at player pos using the debug console, I have to use createVehicleLocal for whatever reason. I guess this may be intended behavior, but I'm not entirely sure what the best approach would be to create this locally for every client.

Midn sharing the script with me, maybe i find what is the issue

Share this post


Link to post
Share on other sites
32 minutes ago, dealman said:

 

Hey, thanks for the reply! I just tried using the alternative syntax and it does not work. Can't even spawn it at player pos using the debug console, I have to use createVehicleLocal for whatever reason. I guess this may be intended behavior, but I'm not entirely sure what the best approach would be to create this locally for every client.

Mind sharing the script with me? maybe i find what is the issue :)

Share this post


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

Mind sharing the script with me? maybe i find what is the issue :)

 

Sure no problem, it's intended to be released on the Steam Workshop later on either way. Currently this is all I have;

initServer.sqf (Intended for Tanoa, you should only need 1 player unit for it to work)
 

Spoiler

// Settings
wreckModels = ["Land_UWreck_MV22_F"];
wreckEffects = [
	[["ModuleEffectsFire_F", [1.79785, -5.63281, -2.54846]], ["ModuleEffectsFire_F", [1.77148, 0.065918, -2.7937]], ["ModuleEffectsSmoke_F", [2.88574,-0.0478516,-3.69666]]]
];
wreckEffectsParams = [
	[[["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]], [["effectSize", 10.0], ["particleSize", 10.0]]]
];
wreckPositions = [[10493.2, 7938.7, 0]];

// Logic Variables
heliWreck = objNull;
heliWreckEffects = [];

wreckSetup = [] spawn {
	// Spawn Wreck at a Random Spawn Location
	_spawnPos = wreckPositions call BIS_fnc_selectRandom;
	_wreckModel = wreckModels call BIS_fnc_selectRandom;
	_safePos = [_spawnPos, 0, 200, 0, 0, 0.15, 0] call BIS_fnc_findSafePos;
	heliWreck = _wreckModel createVehicle _safePos;
	heliWreck setDir (floor random 361);
	// Setup Effects if Applicable
	_wreckIndex = wreckModels find _wreckModel;
	{
		_effectClass = _x select 0;
		_effectPosRelative = _x select 1;
		_effectPosWorld = (heliWreck modelToWorld _effectPosRelative);
		/* createVehicleLocal works as intended when playing in editor */
		_effectObject = _effectClass createVehicleLocal (heliWreck modelToWorld _effectPosRelative);
		
		/* createVehicle Alternative Syntax (Will not work because "Vehicles with brain cannot be created using 'createVehicle'!" */
		//_effectObject = createVehicle [_effectClass, (heliWreck modelToWorld _effectPosRelative), [], 0, "NONE"];
		
		/* createVehicleLocal executed via remoteExec on all clients, results in an error inside A3\modules_f\Effects\functions\fn_moduleEffectsFire.sqf */
		//[_effectClass, (heliWreck modelToWorld _effectPosRelative)] remoteExec ["createVehicleLocal", 0];
		
		// Set Effect Params if Applicable
		{
			{
				_effectObject setVariable [_x select 0, _x select 1];
			} forEach _x;
		} forEach (wreckEffectsParams select _wreckIndex);
	} forEach (wreckEffects select _wreckIndex);
};

waitUntil{scriptDone wreckSetup};

unitsSetup = [] spawn {
	{
		// Teleport the Player Nearby the Wreck
		_safePos = [getPos heliWreck, 10, 50, 3, 0, 0.5, 0] call BIS_fnc_findSafePos;
		_x setPos _safePos;
		_x setDir (floor random 361);
		// Remove the Player's Gear
		removeAllAssignedItems _x;
		removeBackpack _x;
		// Set Player as Unconscious (used for the 'intro')
		_x setUnconscious true;
	} forEach switchableUnits; /* TODO: Change to playableUnits for MP! */
};

 

 

So I was being a derp, it never did work in MP. It worked when I was testing in the editor, I guess I had them mixed up as I keep switching back and forth. Hard to test MP functionality without having a 2nd client. I'm guessing the way I tried to use remoteExec is incorrect after all. :(

Share this post


Link to post
Share on other sites

Alright buddy, try this out, i have not tested it but i had similar issues with spawning units and that's how i fixed them, if that does not fix it then I am sorry for not being able to help

_yourwreck = (heliWreck modelToWorld _effectPosRelative);
_effectObject = createVehicle [_effectClass, _yourwreck, [], 0, "NONE"];

Share this post


Link to post
Share on other sites
1 minute ago, BlacKnightBK said:

Alright buddy, try this out, i have not tested it but i had similar issues with spawning units and that's how i fixed them, if that does not fix it then I am sorry for not being able to help


_yourwreck = (heliWreck modelToWorld _effectPosRelative);
_effectObject = createVehicle [_effectClass, _yourwreck, [], 0, "NONE"];

 

I've already tried that, hence this commented code;

/* createVehicle Alternative Syntax (Will not work because "Vehicles with brain cannot be created using 'createVehicle'!" */
//_effectObject = createVehicle [_effectClass, (heliWreck modelToWorld _effectPosRelative), [], 0, "NONE"];

It seems you can't create that kind of module at all using createVehicle as it has a "brain".

Share this post


Link to post
Share on other sites
Just now, dealman said:

 

I've already tried that, hence this commented code;


/* createVehicle Alternative Syntax (Will not work because "Vehicles with brain cannot be created using 'createVehicle'!" */
//_effectObject = createVehicle [_effectClass, (heliWreck modelToWorld _effectPosRelative), [], 0, "NONE"];

It seems you can't create that kind of module at all using createVehicle as it has a "brain".

I am sorry i could not be of much help, i myself am new to the scripting world

Share this post


Link to post
Share on other sites
Just now, BlacKnightBK said:

I am sorry i could not be of much help, i myself am new to the scripting world

 

No problem buddy, I appreciate any and all help! :)

Share this post


Link to post
Share on other sites

Not a fan of double posting, but I believe I've managed to figured this out. There were 2 issues;

1. Apparently one should use createUnit to create the effect modules and not createVehicle(createVehicleLocal though works for whatever reason?).

2. It would seem I was doing this all too fast, at first using createUnit(reference) didn't work which had me confused - then I recall having similar issues in UnrealEngine 4 where some things would fail to execute on rare occasions, but slapping in a short delay would solve the problem. Lo and behold I slap in a uiSleep of 5 seconds and it now works.

 

I'd still love to hear an explanation as to why this is, so it's something I can avoid later on as I spent several hours on this. :down:

  • 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

×