Jump to content
Sign in to follow this  
Bulldog Six

pilots addaction question

Recommended Posts

hey fellas!

I have some helicopters in my mission which have a red combat light in them which is on by default. But I would like to give the pilot the option to turn it on and off. Can someone please help me with it?

this is the code for my UH60 lights:

light1 = "#lightpoint" createVehicleLocal [0,0,0];
light1 setLightBrightness 0.02;
light1 setLightAmbient [0.02,0,0];
light1 setLightColor [1,0,0];
light1 lightAttachObject [this,[-0.8,2.7,-0.5]];
light2 = "#lightpoint" createVehicleLocal [0,0,0];
light2 setLightBrightness 0.02;
light2 setLightAmbient [0.02,0,0];
light2 setLightColor [1,0,0];
light2 lightAttachObject [this,[0.8,2.7,-0.5]];

also how do I include slightly different codes for other helo types so one script works for different helos?

I guess I need to use the addaction command and create lightOn and lightOff scripts which differentiate between different helo types and uses the proper code for them - but that's where I need your help. I need it for 3 helo types: the Blackhawk ("UH60M_EP1"), the Chinook ("CH_47F_EP1") and the Huey ("UH1H_TK_EP1"). Just use the same code for all helo types and I'll alter it for them accordingly.

Please help me out fellas! How do I do this?

Share this post


Link to post
Share on other sites

hello? do you need additional information?

it shouldn't be that complicated. basically, structurewise it should look kinda like this (I think):

if DRIVER is PILOT and if combat lights are "OFF" then ADD_ACTION "turn on combat lights" (turn on combat lights -> if VEHICLE is UH1H use LIGHT SETTINGS 1; if vehicle CH47 use LIGHT SETTINGS 2; if VEHICLE is HUEY use LIGHT SETTINGS 3)

if COMBAT LIGHTS are "ON" then PILOT ADD_ACTION "turn off combat lights" and REMOVE ACTION "turn on combat lights"

if PILOT selects action "turn off combat lights" then REMOVE COMBAT LIGHT OBJECTS from LIGHT SETTINGS 1, 2 or 3 //depending on in which helo he's sitting

preferrably all light settings should be accessible in the same file, but if it's easier to give each helo it's own light settings script then that's ok too.

help me please! where's the code pro's?

Edited by Bulldog Six

Share this post


Link to post
Share on other sites

It my be harder than you think, also will it be for MP use.

Giving the option isn't hard but keeping track of the lights maybe.

If you turn the light on in one vehicle then get out and into another you need two sets of lights now and so on.

Share this post


Link to post
Share on other sites
It my be harder than you think, also will it be for MP use.

Giving the option isn't hard but keeping track of the lights maybe.

If you turn the light on in one vehicle then get out and into another you need two sets of lights now and so on.

I agree, it's not that easy. but maybe easier than you might think.

yes, for MP use!

currently I have the combat lights attached to the transport helos (Blackhawk, Chinook and OPFOR Huey's). So the combat lights are always on in them. I just want to add the ability to turn them off and on again.

you can take a look at it in my mission here (no further addon's required, just OA standalone):

http://www.gamefront.com/files/20997344/AQoP_v0729.zip

note: if you want to enter the pilot seat make sure to select a pilot in the unit selection screen or else it will kick you out of the chopper. I included the anti-collision lights for aircraft scripts by Combate Tático Brasil with which you can turn on and off the anti-collision lights as a pilot. but not the combat lights, that's where I need your help. the combat lights are directly attached to the choppers in the editor via init code - which I guess I would have to change to a script like the anti-collision lights but I lack the knowledge in coding to do it.

Edited by Bulldog Six

Share this post


Link to post
Share on other sites

Here's the code I got working for one vehicle. Copy the addaction into the vehicles init. name of the chopper is heli.

save as lights.sqf

//act1 = this addaction ["Int Light On","lights.sqf",2,1,false,true,"","player == driver heli"]

_veh = _this select 0;
_unit = _this select 1;
_handle = _this select 2;
_state = _this select 3;


_veh removeaction (_this select 2);

switch (_state) do {
     case 0: {
         _handle = _veh addaction ["Int Light On","lights.sqf",1,1,false,true,"","player == driver heli"];
};
case 1 : {
              _handle = _veh addaction ["Int Light Off","lights.sqf",0,1,false,true,"","player == driver heli"];
     };


};

if (_state == 0) exitWith { deletevehicle light1;deletevehicle light2;};

light1 = "#lightpoint" createVehicleLocal [0,0,0];
light1 setLightBrightness 0.02;
light1 setLightAmbient [0.02,0,0];
light1 setLightColor [1,0,0];
light1 lightAttachObject [_veh,[-0.8,2.7,-0.5]];
light2 = "#lightpoint" createVehicleLocal [0,0,0];
light2 setLightBrightness 0.02;
light2 setLightAmbient [0.02,0,0];
light2 setLightColor [1,0,0];
light2 lightAttachObject [_veh,[0.8,2.7,-0.5]];

Share this post


Link to post
Share on other sites

If it's for MP use (and if I understand correctly that means you want the lights switching on and off having global effects, so that other players can see the lights, too) the actions themselves are your least problem. I recently experienced lights being always local, no matter if you use createVehicle or createVehicleLocal.

Hence you can't just execute a client-side script to create/delete the lights. It would make light on the executing machine, but not on any others. So the first thing you'd need to think about is locality and the design to use.

I suggest a script that handles the light. Either create/delete lights or just switching their brightness.

The pilot's action calls another script which does nothing else but to broadcast the action call, so every client machine can handle the lights for their own (by executing the handler script). The natural way would suggest the use of publicvariable and a corresponding publicvariable-eventhandler. Another, easier way would be using setvehicleinit, but trust me, you don't want to do that.

Last but not least you should handle demolition of helicopters (then all clients need to destroy their local lights). And how to synchronize the light states with JIPs etc etc....

It is not as hard as it may sound now. But for MP, I'm afraid it ain't is not that easy either.

-------------------------------------------------------------

@F2k Sel: Just fyi, you can as well write the action as follows:

act1 = this addaction ["Int Light On","lights.sqf",2,1,false,true,"","player == driver [color="Red"]_target[/color]"]

then you don't need to give the heli a name.

Edited by Bon

Share this post


Link to post
Share on other sites

Bon has done an excellent job of the summarizing the MP/locality issues. Even though our projects are different in scope, I encountered these same issues with switching off street lamps in my electrical grid simulation scripts, which are also local-effects only. They way I handled locality and all the MP aspects is exactly this:

The pilot's action calls another script which does nothing else but to broadcast the action call, so every client machine can handle the lights for their own (by executing the handler script). The natural way would suggest the use of publicvariable and a corresponding publicvariable-eventhandler.

I am happy to go into detail with you to explain how I did it in a way that could be applied to your project.

Share this post


Link to post
Share on other sites

Thanks for pointing that out Bon, I've used _target before but admit I'd totally forgotten about it.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
If it's for MP use (and if I understand correctly that means you want the lights switching on and off having global effects, so that other players can see the lights, too) the actions themselves are your least problem. I recently experienced lights being always local, no matter if you use createVehicle or createVehicleLocal.

Hence you can't just execute a client-side script to create/delete the lights. It would make light on the executing machine, but not on any others. So the first thing you'd need to think about is locality and the design to use.

I suggest a script that handles the light. Either create/delete lights or just switching their brightness.

The pilot's action calls another script which does nothing else but to broadcast the action call, so every client machine can handle the lights for their own (by executing the handler script). The natural way would suggest the use of publicvariable and a corresponding publicvariable-eventhandler. Another, easier way would be using setvehicleinit, but trust me, you don't want to do that.

Last but not least you should handle demolition of helicopters (then all clients need to destroy their local lights). And how to synchronize the light states with JIPs etc etc....

It is not as hard as it may sound now. But for MP, I'm afraid it ain't is not that easy either.

...

Thanks for the input Bon! I didn't know you were still around. We talked about my mission with each other on teamspeak a while back, I don't know if you recall that - I was online as 'app0815' (Knoll was also around).

Hmmm, judging by your description it's certainly beyond my understanding in coding to realize by myself.

@Loyalguard: for sure! I would like to know how you did it. Might be helpful for my project. :)

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  

×