Jump to content
Jaden Vance

Replacing an object with another object!

Recommended Posts

Hello, I am looking to create this:

I have a helipad with four helipad portable red lights. I will place an "addaction" to a nearby object to change these four lights to portable green lights, to signal pilots that this spot is free to land. And then, turn them again to red lights when a helicopter is parked there.

 

The question is, how to replace these four lights? What command to use?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

Hi!

First thing: in this video, he show a kind of "amateur" way to do it. It will get the job done, but it will definitely not be worthy whether you use it in multiplayer.
 I will search for a basic script I used a few years ago to do some similar stuff, but I am sure guys here will bring some MUCH better and cleaner codes for you 😁 .

In this video, he shows how to "open" some objects, like laptops and crates, by replacing the closed version of the object by its open version while using addAction.
So you could do the same with your red/green lights. 😉
 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

You can switch green or red, hiding red or green like that:

- place your helipad, name it : hpad1  (or else, but that's for the following script)

- place all red portable lights you want (within 20 m from hpad1 center here, but feel free to change that)

 

Now, in init field of the helipad, write:


 

this spawn {
  private _redLights = (_this nearObjects ["PortableHelipadLight_01_red_F",20]);
  private _greenLights = [];
  {
    _x params ["_rLite","_pos","_dir"];
    _pos = getPosASL _rLite;
    _dir = getDir _rLite;
    _gLite = createVehicle ["PortableHelipadLight_01_green_F",[0,0,0],[],0,"can_collide"];
    _gLite setdir _dir;
    if isServer then {_gLite hideObjectGlobal TRUE};
    sleep 0.2;
    _gLite setPosASL _pos;
    _greenLights pushback _glite;
  } forEach _redLights;

MGI_hideObj = compileFinal "
  params ['_activelights','_switchLights','_aLite','_sLite'];
  {
    _aLite = _x;
    _aLite hideObjectGlobal TRUE;
    _sLite = _switchLights #_foreachindex;
    _sLite hideObjectGlobal FALSE;
  } forEach _activeLights;
";
player addAction ["green lights",
  {
    params ["_tgt","_caller","_id","_lights"];
    _lights params ["_redlights","_greenLights"];
    if ((_caller actionParams _id)#0 isEqualTo "green lights") then {
      [_redlights,_greenLights] remoteExec ["MGI_hideObj",2];
      _caller setUserActionText [_id,"red lights"];
    } else {
      [_greenlights,_redLights] remoteExec ["MGI_hideObj",2];
      _caller setUserActionText [_id,"green lights"];
    }
  },
[_redlights,_greenLights],1.5,TRUE,FALSE,"","isNull objectParent _this && _this distance2D hpad1 <20",20];
};

 

This code should work in SP or MP. I didn't dig it if one player set lights to green and another one set them to red. Probably no error but you have to make the action twice. No time for fixing that (broadcast state of menu)

Have fun!

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Pierremgi, you are very good with this stuff. Thanks a lot, fits perfect for what I have in mind!

Works excellent! ❤️

 

JCataclisma, your idea is also amazing. I will keep that technique in mind for future ideas! ❤️

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

×