Jump to content

Recommended Posts

I wish to light the inside of a building during a night mission. (on a dedicated server) I found a post that seems like a solution but the light only works when the script runs locally so I put a call to the script in the initPlayerLocal.sqf file but that didn't help.

 

In my initPlayerLocal method I have: 

[BaseLight_1, 0.5, 5.4] call LFT_LightSource;
[BaseLight_2, 0.5, 1.8] call LFT_LightSource; 

BaseLight_1 and BaseLight_2 are logic objects.

 

LFT_LightSource:

/*
 	NOTE: Runs locally.
*/
params["_light", "_intensity", "_height"];

_light setPosATL[(getPosATL _light select 0), (getPosATL _light select 1), _height];

BIS_lightEmitor01 = "#lightpoint" createVehicleLocal getPosATL _light;
BIS_lightEmitor01 setLightColor [1, 1, 1];
BIS_lightEmitor01 setLightBrightness _intensity;
BIS_lightEmitor01 setLightAmbient [1,1,1];
BIS_lightEmitor01 lightAttachObject [_light, [0, 0, 0.1]];

The code works perfectly when I run the mission from my PC.

Share this post


Link to post
Share on other sites

createVehicleLocal is local.  Use createVehicle instead. Your other commands are OK.

  • Like 3

Share this post


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

createVehicleLocal is local.  Use createVehicle instead. Your other commands are OK.

Yes, I realize that createVehicleLocal is local. But I believe that creating a lightpoint must be done at the local level which is why I put the call into the initPlayerLocal.sqf file which is run locally.

 

I'll try createVehicle but I don't have confidence that it will work.

 

Thanks for you reply.

 

Share this post


Link to post
Share on other sites

Yep, lightpoints and all commands are local.  No joy.

Share this post


Link to post
Share on other sites

I don't really understand what you're trying to do. Adding a light point is fine in local for each player. there is no reason for broadcasting this light (the reason why the commands are local).

If you create locally, but everywhere, there is no reason to fail! That's the point I don't understand with your issue.

 

On the other hand, if you switch on/off by an addAction (example) the code is local so you need to remoteExec.

If you remote exec a function (like below) this function must be known by all clients (so place it in init.sqf or create the function in cfgFunctions).

 

Use createVehicle and remoteExec the other commands. I'm using attachTo instead of lightAttachObject.

Try something like that:

 

//////////////  everywhere (init.sqf or else)   //////////////////
XX_fnc_setLight = compileFinal "
_this#0 setLightColor [1, 1, 1];
_this#0 setLightBrightness (_this#1);
_this#0 setLightAmbient [1,1,1];
";

////////////////////  your code   ///////////////


BIS_lightEmitor01 = "#lightpoint" createVehicle getPosATL _light;
BIS_lightEmitor01 attachTo [_light, [0, 0, 0.1]];
[[BIS_lightEmitor01,1],XX_fnc_setLight] remoteExec ["call"];

Not tested in MP so far. I don't have the context.
 

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, pierremgi said:

I don't really understand what you're trying to do. Adding a light point is fine in local for each player. there is no reason for broadcasting this light (the reason why the commands are local).

If you create locally, but everywhere, there is no reason to fail! That's the point I don't understand with your issue.

 

On the other hand, if you switch on/off by an addAction (example) the code is local so you need to remoteExec.

If you remote exec a function (like below) this function must be known by all clients (so place it in init.sqf or create the function in cfgFunctions).

 

Use createVehicle and remoteExec the other commands. I'm using attachTo instead of lightAttachObject.

Try something like that:

 


//////////////  everywhere (init.sqf or else)   //////////////////
XX_fnc_setLight = compileFinal "
_this#0 setLightColor [1, 1, 1];
_this#0 setLightBrightness (_this#1);
_this#0 setLightAmbient [1,1,1];
";

////////////////////  your code   ///////////////


BIS_lightEmitor01 = "#lightpoint" createVehicle getPosATL _light;
BIS_lightEmitor01 attachTo [_light, [0, 0, 0.1]];
[[BIS_lightEmitor01,1],XX_fnc_setLight] remoteExec ["call"];

Not tested in MP so far. I don't have the context.
 

I guess I don't understand what you mean when you say I don't need to broadcast the creation of a lightPoint. My code doesn't do that. The call to the LFT_LightSource function is placed in the initPlayerLocal.sqf file that gets run locally on every player's PC at the start of the mission so it should work but it doesn't. Very frustrating.

I'll see if I can get your remoteExec way of doing it to work. Thanks for the help. 

Share this post


Link to post
Share on other sites

Where are you defining your function? Certain files are processed in a different order depending on environment: 

 

https://community.bistudio.com/wiki/Initialization_Order

 

Maybe you are trying to call a function that doesn't yet exist, E.G. call in initPlayerLocal.sqf  to a function in init.sqf won't work on dedi but will in SP.

Share this post


Link to post
Share on other sites

In the initServer.sqf file I call a method that compiles several functions including the LFT_LightSource function.

In the initServer.sqf file:

_handle = [] execVM "scripts\common\compileMethods.sqf";
waitUntil {scriptDone _handle};

In the scripts\common\compileMethods.sqf file:

if(!isServer) exitWith {};

inView = compileFinal preprocessfilelinenumbers "LFT_Common\inView.sqf";
isPrimaryAmmoLow = compileFinal preprocessfilelinenumbers "LFT_Common\isPrimaryAmmoLow.sqf";
LFT_Attack_Ground_Troops = compileFinal preprocessfilelinenumbers "LFT_Common\LFT_Attack_Ground_Troops.sqf";
LFT_LightSource = compileFinal preprocessfilelinenumbers "LFT_Common\LFT_LightSource.sqf";

 

Share this post


Link to post
Share on other sites

Then these functions only exist on the server. Attempting to call them from initPlayerLocal, or from any client in general, will fail. As @pierremgi said, you should make sure they are created everywhere, such as in init.sqf. Considering initialization order, you should probably check for the function's existence before attempting to call it.

  • 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

×