Jump to content
Sign in to follow this  
Monkwarrior

smokeshells and MP

Recommended Posts

Gents,

Our tanks have the ability to produce smokeshells.

The gunner has an action in his menu to "pop smoke".

The code which is run is an sqf-file and it looks like this:

/* 	pop_smoke.sqf
Script to produce a smokewall fired by a tank
The smokewall will be in front of the turret where the turret is aiming at

Called by: PzKpfwV.hpp and other tankscripts with popsmoke ability
Version: 1.0
Date: 04/10/2009
Parameters:
	0) the tankobject
	1) name of the main gun on the turret
	2) reloadtime in seconds
*/

_armored = _this select 0;
// The name of the main weapon 
_nameofmainweapon = _this select 1;
// The reloadtime
_reloadtimesmoke = _this select 2;

_reloading = _armored getVariable "I44_reloadsmoke";
if (_reloading > 0) exitwith
{
hint "Smoke dischargers are being reloaded";
};
_armored setVariable ["I44_reloadsmoke", 1];


//Get tank postion and direction of the turret
objX = getpos _armored select 0;
objY = getpos _armored select 1;
_dir = _armored weaponDirection format ["%1", _nameofmainweapon];
objdir = (_dir select 0) atan2 (_dir select 1);

for [{_i = 0}, {_i <= 5}, {_i = _i + 1}] do
{
_shell = "Smokeshell" createVehicle [0,0,200+random100];
_shell setPos [objX,objY,3]; 
_vectdir = _dir;
_velocityFactor = 15; 
_velocity = [((_vectDir select 0)*_velocityFactor),((_vectDir select 1)*_velocityFactor),((_vectDir select 2)*_velocityFactor)]; 
_shell setVelocity _velocity;

};

So basicly we are using a createvehicle and setPos to create and move a smokeshell.

The problem

In our dedicated server ONLY the player launching the smokeshell sees the smokeshell. So the script is not run on the other clients.

What are we missing here ?

How can we make sure this smoke is to be seen by all other clients and the server ?

Thanks gents, Monk.

Share this post


Link to post
Share on other sites

You'll most likely can use the setVehicleInit command followed by a processInitCommands.

By way of example, here's a snippet from a script of mine:

_MPInit=Format ["[This,%1,%2,%3,%4,%5] ExecVM ""JTD_FireAndSmoke\Scripts\SmokeMain.sqf""",_SmokeStyle,_PrimaryLifetime,_SecondaryLifetime,_thisTime,_VehicleScale];
_Vehicle SetVehicleInit _MPInit;
ProcessInitCommands;

So you can see how to pass a series of parameters to the vehicle (in your case smokeshell) and have all machines execute it.

Share this post


Link to post
Share on other sites

Thanks DMarwick.

After extensive testing we have come to the conclusion that using setvehicleinit and Processinitcommands does not work in MP for us.

In fact none of the other players could even see any smoke at all.

Part of the code we used looked like this:

for [{_i = 0}, {_i <= 5}, {_i = _i + 1}] do

{

_shell = "Smokeshell" createVehicle [0,0,200+random100];

_shell setPos [objX,objY,3];

_vectdir = _dir;

_velocityFactor = 15;

_velocity = [((_vectDir select 0)*_velocityFactor),((_vectDir select 1)*_velocityFactor),((_vectDir select 2)*_velocityFactor)];

_shell SetVehicleInit format ["This, setvelocity %1;",_velocity];

processInitCommands;

sleep 4;

};

In fact the setvelocity command also doesn't work in MP either.

The only thing that works right now in MP is a createvehicle statement.

So as a workaround we create our smokeshells on the spot where we want them to end. A sub-optimal workaround because tankcrews can create a smokescreen behind houses etc :(

Any more suggestions are welcome of course.

After all there is still something we are missing because the guyz from ACE are able to do this :)

Thanks, Monk.

Edited by Monkwarrior

Share this post


Link to post
Share on other sites

execVM/call this on the init-event of the vehicle:



if(isnil "UniqueGlobalVariable") then {



[indent]UniqueGlobalVariable = true;
VariableForBroadcast = [];
"VariableForBroadcast" addPublicVariableEventHandler {
[indent]if (time - ((_this select 1) select 3) < 10) then {
[indent](_this select 1) execVM "pop_smoke.sqf";   // adjust script-path here[/indent]


};[/indent]

};[/indent]
};


lets say this is the code that is executed when the gunner hits the action

[TANKOBJECT,MAINGUN,RELOADTIME] execVM "pop_smoke.sqf";

extend it to:

[TANKOBJECT,MAINGUN,RELOADTIME] execVM "pop_smoke.sqf";
VariableForBroadcast = [TANKOBJECT,MAINGUN,RELOADTIME,time];
publicVariable "VariableForBroadcast";

and in the script pop_smoke.sqf use 'createVehicleLocal' instead of 'createvehicle'.

======================================

Note: the check with the time (when the variable is published and when its received is required, to avoid smokeshells being fired off, on the last vehicle that has done it, for jip-players right after they join. Thats because of the vehicles in the mission being init-ed before the published variables are being syncronised for jip-players

======================================

Another mp issue that is being resolved that way (which you are probably not aware of right now) is the reload status.

'setVariable' has local effect only, meaning that the vehicle is marked as reloading the smokeshells only for the player that has shot them (in your script). That can be exploited.

Edited by dengibtsschon
typo, and notes

Share this post


Link to post
Share on other sites
Thanks DMarwick.

After extensive testing we have come to the conclusion that using setvehicleinit and Processinitcommands does not work in MP for us.

In fact none of the other players could even see any smoke at all.

Part of the code we used looked like this:

In fact the setvelocity command also doesn't work in MP either.

The only thing that works right now in MP is a createvehicle statement.

So as a workaround we create our smokeshells on the spot where we want them to end. A sub-optimal workaround because tankcrews can create a smokescreen behind houses etc :(

Any more suggestions are welcome of course.

After all there is still something we are missing because the guyz from ACE are able to do this :)

Thanks, Monk.

Ah well if you were hoping to sycnchronise moving elements via that method then you're on a hiding to nowhere :) the createVehicle statement is indeed probably what you're looking for. In fact I don't know how the engine itself looks after this, perhaps it's as simple as each machine performing it's own physics calculations and then syncing the results with the "firing" PC.

Perhaps you might consider looking at a similar solution: test the position of the smokeshell at regular intervals on the firing PC, say each 0.5 seconds, and as soon as there's no more movement you sync up all the other PCs and place a createVehicle smokeshell at that position.

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  

×