Jump to content
marki980908

Spawning an object with init via script

Recommended Posts

Hey I have a question, is it possible to spawn an object via script with init function already inside of it?
What I mean is this:

 

Spoiler

_object97 = createVehicle ["Land_TransferSwitch_01_F", [0, 0, 0], [], 0, "CAN_COLLIDE"];
_object97 setVectorDirAndUp [[-0.163148,-0.986602,0],[0,0,1]];
_object97 setPosASL [8960.75,12123,37.9628];

 

This will spawn me a electrical switch.
And this if placed inside the init:
 

Spoiler

DistanceToReach = 300; 
this addAction 
[   
    "Turn Off",   
    {   
        params ["_target", "_caller", "_actionId", "_arguments"];   
 { 
   private _ticket = format ["LSS%1", _forEachIndex]; 
  [_x, "OFF"] remoteExec ["switchLight", 0, _ticket];   
 } forEach nearestObjects [_caller, [], DistanceToReach]; 
  _target animateSource ["switchposition",1];   
  _target animateSource ["light",0];   
  _target setDamage 1;   
    },   
    [],   
    1.5,   
    true,   
    true,   
    "",   
    "alive _target",   
    3,   
    false,   
    "",   
    ""   
]; 
  
this addAction   
[   
    "Turn On",   
    {   
        params ["_target", "_caller", "_actionId", "_arguments"];   
 { 
    private _ticket = format ["LSS%1", _forEachIndex]; 
    [_x, "On"] remoteExec ["switchLight", 0, _ticket];   
 } forEach nearestObjects [_caller, [], DistanceToReach]; 
  _target animateSource ["switchposition",-1];   
  _target animateSource ["light",1];   
  _target setDamage 0;   
    },   
    [],   
    1.5,   
    true,   
    true,   
    "",   
    "!alive _target",   
    3,   
    false,   
    "",   
    ""   
];

 

Would make that switch work if placed in eden in objects init

What I would do I would just put it in init in eden and start the mission, but in this situation I need to do it in zeus. Is there a way to spawn in and apply init with a single code?

Share this post


Link to post
Share on other sites

could a script do it?? " SpawnElSwitch.sqf ". and call the script.

if (isServer) then {


_object97 = createVehicle ["Land_TransferSwitch_01_F", [0, 0, 0], [], 0, "CAN_COLLIDE"]; _object97 setVectorDirAndUp [[-0.163148,-0.986602,0],[0,0,1]]; _object97 setPosASL [8960.75,12123,37.9628];

DistanceToReach = 300;
_object97 addAction [ "Turn Off", { params ["_target", "_caller", "_actionId", "_arguments"]; { private _ticket = format ["LSS%1", _forEachIndex]; [_x, "OFF"] remoteExec ["switchLight", 0, _ticket]; } forEach nearestObjects [_caller, [], DistanceToReach]; _target animateSource ["switchposition",1]; _target animateSource ["light",0]; _target setDamage 1; }, [], 1.5, true, true, "", "alive _target", 3, false, "", "" ];

_object97 addAction [ "Turn On", { params ["_target", "_caller", "_actionId", "_arguments"]; { private _ticket = format ["LSS%1", _forEachIndex]; [_x, "On"] remoteExec ["switchLight", 0, _ticket]; } forEach nearestObjects [_caller, [], DistanceToReach]; _target animateSource ["switchposition",-1]; _target animateSource ["light",1]; _target setDamage 0; }, [], 1.5, true, true, "", "!alive _target", 3, false, "", "" ];
};

it's just a thought don't know if it will work 😉

  • Like 1

Share this post


Link to post
Share on other sites

The script should just work if you add the actions externally, instead of inside the init of an object. What ShArK_OG mentioned earlier, that is the way I would approach this too.

All you need to do is replace"this" in the addaction with "objectName" (such as _object97 mentioned above, or whatever other name you give the object).

Then you can just use the action ID handles to monitor the actions, if you need to remove them or anything.

 

Hope this helps. 🙂 

Tom

 

Edit:

Similar post here - asking the same question - maybe have a look if you want some more understanding: 

 

Edited by TomOZ
Added Link

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

×