Jump to content
Sign in to follow this  
nullsystems

Light createvehicle - local?

Recommended Posts

Hello,

I have a custom addon which has an addAction attached to a vehicle. When activated this creates a light and attaches it to the vehicle.

Now, this almost works 100% apart from:

The light created only shows on the computer which activated the lights.

Which means its obviously local.

How can I get around this?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

light = "#lightpoint" createVehicleLocal getpos _vehicle;

publicVariable "light"

light lightAttachObject [_v, [0,0,+0.4]]

light setLightBrightness 0.04;

light setLightAmbient[1, 1.0, 1.0];

light setLightColor[1.0, 1.0, 1.0];

I even tried publicVariable, nothing.

Could it be because the vehicle is being created by a locally run script?

Share this post


Link to post
Share on other sites

I think you will need to run the script on every client for everyone to see the light not just use publicVariable to declare the light.

Maybe the best way to implement that is to modify the addAction to change the value of a public variable (e.g. vehicleLight = true) and broadcast it via the publicVariable command.

Also add a trigger (which by default will be on every client) to your mission that has a condition of vehicleLight.  When true, it will activate the script (on all clients) that creates and attaches the light to the vehicle.

If you want to do this via a script instead of a trigger you will need to use a script running on every client using the waitUntil command.

I am assuming even though the vehicle is local to the driver it would still work but would obviously needs to be tested.

Good luck!

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

light = "#lightpoint" createVehicleLocal getpos _vehicle;

Have you tried using createVehicle instead of createVehicleLocal, as createVehicleLocal is explicitly intended to be created locally only?

Share this post


Link to post
Share on other sites

I cant believe I didnt see that, man im such an idiot at times. I should really do scriting when im awake huh lol

Thanks man, I bet thats it.

PS: while we are at it, is setRain local? As I tried it last night running from a script in the init.sqs but changes where only made locally, different people had different weather.

Share this post


Link to post
Share on other sites
Hello,

I have a custom addon which has an addAction attached to a vehicle. When activated this creates a light and attaches it to the vehicle.

Now, this almost works 100% apart from:

The light created only shows on the computer which activated the lights.

Which means its obviously local.

How can I get around this?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

light = "#lightpoint" createVehicleLocal getpos _vehicle;

publicVariable "light"

light lightAttachObject [_v, [0,0,+0.4]]

light setLightBrightness 0.04;

light setLightAmbient[1, 1.0, 1.0];

light setLightColor[1.0, 1.0, 1.0];

I even tried publicVariable, nothing.

Could it be because the vehicle is being created by a locally run script?

All is that you need to do is remove the local.. tounge2.gif you tried that yet biggrin_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

light = "#lightpoint" createVehicle getpos _vehicle;

publicVariable "light"

light lightAttachObject [_v, [0,0,+0.4]]

light setLightBrightness 0.04;

light setLightAmbient[1, 1.0, 1.0];

light setLightColor[1.0, 1.0, 1.0];

Share this post


Link to post
Share on other sites

yeah, as hitman said lol. I tried it as he wrote it.

Its my own fault for scripting when I just woke up, moron. Wasted your time lol

Share this post


Link to post
Share on other sites
I cant believe I didnt see that, man im such an idiot at times. I should really do scriting when im awake huh lol

Thanks man, I bet thats it.

PS: while we are at it, is setRain local? As I tried it last night running from a script in the init.sqs but changes where only made locally, different people had different weather.

You would have to run a global script for the set rain smile_o.gif

Share this post


Link to post
Share on other sites

Yes, it is global and its being run from init.sqs. There are no local settings or if statements.

ill keep testing when i wake up.

Share this post


Link to post
Share on other sites
Quote[/b] ]

All is that you need to do is remove the local.. you tried that yet

ello,

Yep, just tried that. Still only happens locally. How odd.

Share this post


Link to post
Share on other sites

Use processInitCommands to create the lights (or do anything thats called localy) on all clients.

This example takes JIP into account and assumes your adding and removing the lights to turn them on and off. If the lights are just added once and never removed then you can get rid of all the stuff relating to time.

Lights on:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object SetVehicleInit Format ["[This,%1,True] ExecVM ""AddLights.sqf"",Time];

Lights off:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object SetVehicleInit Format ["[This,%1,False] ExecVM ""RemoveLights.sqf"",Time];

Then in AddLights.sqf and RemoveLights.sqf add this at the top, before your other code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object=_This Select 0;

_TimeCalled=_This Select 1;

_AddLights=_This Select 2;

//See if it's a JIP Client

_IsJIP=IsNull Player;

//See if there were multiple calls to this script

_LastTime=_Object GetVariable "LightSwitch";

//If it's a JIP client only execute the last call

If (TypeName "_LastTime"=="SCALAR") Then

       {

       If (_LastTime<_TimeCalled) Then

               {

               _Object SetVariable ["LightSwitch",_TimeCalled];

               };

       }

       Else

       {

       //This is the first time it's been called so inti the variable

       _Object SetVariable ["LightSwitch",_TimeCalled];

       };

//Wait for all the previous calls

Sleep 0.001;

//See if the objects been deleted or killed

If ((IsNull _Object) Or !(Alive _Object)) Then ExitWith {};

//See if this the last call to the script

If ((_Object GetVariable "LightSwitch")<_TimeCalled) ExitWith {};

//If it's a JIP client and the lights are being removed then just exit

If (_IsJIP and !_AddLights) ExitWith {};

//The rest of your code goes here

This should cover the worst of it. You will have to figure out how best to use, it for your own requirements.

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  

×