Jump to content

Sign in to follow this  
demon cleaner

[ACE] Chemlights attached to shoulder of AI

Recommended Posts

I'm having a bit of trouble attaching an IR chemlight to an AI. What I'm actually doing is calling a script from the units vehicle init. The script contains the following (as suggested in this old thread: http://forums.bistudio.com/showthread.php?92452-ACE-Chem-lights-attached-to-shoulder-of-AI):

_chemLight = "ACE_Knicklicht_IR_Used" createVehicle [0,0,0];
_chemLight attachTo [_unit,[0,-0.06,0.05],"LeftShoulder"];

This did not work ... and yes "_unit" is defined.

Looking into the scripts of "ace_sys_knicklicht" I've changed the vehicle init to:

_chemLight = "ACE_Knicklicht_IR_Used" createVehicle [0,0,0];
_chemLight attachTo [_unit,[0,-0.06,0],"Granat"];

This also did not work ...

Lastly I've tried using the "ACE_Knicklicht_Proxy" object instead but this also did not make it work. Thing is neither of the above seems to even attach the object ...

I'm getting the feeling that I need to run the "_chemLight" object through "ua_knicklicht_anbringen.sqf" and "ua_knicklicht_leuchten.sqf" somehow but I'm not quite sure how. It may also be that certain variables need to be set on the "_unit" object for this to work.

Does anyone know how to get this to work ?

Share this post


Link to post
Share on other sites

Hi,

I've had a similar problem recently and found a solution in this thread: http://forums.bistudio.com/showthread.php?139569-Chemlight-on-Soldiers&highlight=attach+chemlight

In particular, refer to Kylania's code for attaching chemlight to ai and replace the word "aiUnit" with the name you have assigned to the ai in the editor. If you want to attach it to the player just use the name "player" instead of "aiUnit". I have tested it and it works.

While Im at it: should you want to place an IR strobe on a unit then place this code in the unit's init line in the Editor: ["ace_sys_irstrobe_aradd", [this]] call CBA_fnc_globalEvent;

For some reason the strobe will be much brighter on AI than on the player.

Share this post


Link to post
Share on other sites

Hi GvsE!

Thanks for taking the time to answer this one.

You (and Kylania) are correct. My error was to attach the wrong object. The key here seems to be to attach one of the "ACE_Knicklicht_Object_(X)" objects which are found under "CfgVehicles->ACE_Knicklicht_Object_(X)" as opposed to the "ACE_Knicklicht_(X)" and "ACE_Knicklicht_(X)_used" objects which can be found under "CfgMagazines->ACE_Knicklicht_X".

Example for the IR chemlights:

"CfgVehicles->ACE_Knicklicht_Object_IR" and "CfgVehicles->ACE_Knicklicht_Object_IR_I"

The "ACE_Knicklicht_Object_IR_I" appears to function as a light emitter. Looking at the scripts in "ace_sys_knicklicht" the file "ua_knicklicht_leuchten.sqf" seems to replace the "ACE_Knicklicht_Object_X" object with "ACE_Knicklicht_Object_X_I" which probably means "illuminated".

In any case I've settled with the following vehicle init for now:

_chemlight = "ACE_Knicklicht_Object_IR" createVehicle [0,0,0];
_chemlight attachTo [_unit,[0,-0.073,0.056],"LeftShoulder"];

This is working as expected.

Thanks again for taking the time to answer.

SOLVED!

Share this post


Link to post
Share on other sites

If you could answer one question for me, i'd be much obliged. I understand that you work with scripts, not with init fields of units in the editor. I don't do much via scripts and so init fields of units in editor get cluttered after a while. Now, how do you define which units will get chemlights and which won't? I guess there must be some code that complements the "_unit" parameter? And does this code go into init.sqf of a mission?

Share this post


Link to post
Share on other sites

Hi!

Yes you could do that in the init.sqf. It's not the most effective place to do such low level stuff as vehicle inits but for the sake of an example let's do it this way:

Let's suppose you've placed 3 units on the map which you want to attach chemlights to. You've named your units s1, s2 and s3. Filling the "name" field of a unit (or any "vehicle" for that matter) makes it identifiable by the game engine. The game engine will refer to it as an object named s1 for example.

Now let's assume your init.sqf contains the following:

private ["_unitsArray","_chemlight"];

_unitsArray = [s1,s2,s3];

{
 _chemlight = "ACE_Knicklicht_Object_IR" createVehicle [0,0,0];
 _chemlight attachTo [_x,[0,-0.073,0.056],"LeftShoulder"];
} forEach _unitsArray;

What this does is firstly we set the scope of two local variables named "_unitsArray" and "_chemlight". The next thing is filling these variables with values. In our case the names of the units that were created in the editor as that's what we want to access. The curly brace enclosed part is where things happen. As you can see I've replaced the "_unit" variable from the previous example (above post) with "_x". The way this works is that the "forEach" command tells the game engine to execute the commands inside the curly braces for the amount times it finds a value (or more precisely an index) in "_unitsArray" replacing the "_x" with the value of "_unitsArray" during each pass.

So if this script is run the commands inside the curly braces will be run exactly 3 times as our variable named "_unitsArray" holds 3 values [s1,s2,s3]. Each pass a chemlight is created at map position [0,0,0] and then attached to the object named "_x". "_x" is replaced with one of the three values of "_unitsArray" in order. So on the first pass "_x" equals "s1". On the second pass "_x" equals "s2" and so forth. This results in the commands being executed "for each" of the units and each time a new chemlight is created then attached to the unit that's being processed at that time.

I hope this is what you were looking for.

Edited by Demon Cleaner

Share this post


Link to post
Share on other sites

Thank you kindly for the comprehensive answer! This is very helpful and precise, and I couldn't have asked for a better explanation. :)

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  

×