Jump to content
Sign in to follow this  
undercoverbrother

"put this code in the init.sqf", means create a new file init.sqf? or put in init?

Recommended Posts

G'day guys,

I see in a lot of threads where people have posted code, that they frequently mention things like, put this code, in the helicopter's init.sqf or in the soldiers init.sqf. Could someone please tell me (and I'm sorry if it's just bloody obvious) what this exactly means? Does it mean create a new folder in your ArmA2 missions folder, called init.sqf and execute it in a somethings init or in a trigger? - or - does it mean just chuck the code into the whatever's init line?

Also is there a difference between doing it one way or the other.

Thanks,

Share this post


Link to post
Share on other sites

When someone specificly says "put it in init.sqf" you go into the missions folder

In:

MyDocs/ArmA 2 Other Profiles/*your profile*/Missions/*yourmission*/

( If this changed for OA, I'm sorry, I don't own OA at the moment. But I guess its basicly the same just with OA somewhere?)

Then create a file called init.sqf and place the code in there. (obviously, if one already exists there from prior use, Use that one)

Then you should have 2 files in that folder, init.sqf and mission.sqm

Place code given into init.sqf file.

  • Like 1

Share this post


Link to post
Share on other sites

There is no such thing as object's init.sqf.

You can either have an object's init (short for initialization) or init.sqf/init.sqf.

In the first case it means you should open the editing window for the unit in question in the editor and paste the code into the Initialization box.

As for the second case, you have to create a text file in the mission's root directory called init.sqf and paste the code there.

Share this post


Link to post
Share on other sites

Thanks for clarifying that up for me fellas, its just that I was unsure because, I've seen people saying stuff like put this (whatever code) in the helo's init.sqf and I was confused.

Share this post


Link to post
Share on other sites

i want to put this into unit initialization via script how?

so i just need to copy the script into each unit init, how?

sorry im newbie in scripting, usually do it inside the editor, please help me.

this allowfleeing courage;

this enablefatigue false;

this addEventHandler ["HandleDamage",

{

_object = _this select 0;

_damage = _this select 2;

if((damage _object) + _damage > 0.9) then {0.9} else {_damage};

}];

Share this post


Link to post
Share on other sites

One way is to place the code in a script and compile the script as a function.

InitUnit.sqf:

_this allowfleeing courage; //public variable courage must be defined somewhere or there will be an error
_this enablefatigue false;

_this addEventHandler
["HandleDamage",
{
_object = _this select 0;
_damage = _this select 2;
if((damage _object) + _damage > 0.9) then {0.9} else {_damage};
}
];

compiled in init.sqf:

InitUnit = Compile PreprocessFile ("InitUnit.sqf");

Now it is a function called "InitUnit". When units get created in mission, you have each unit or vehicle crewmember call the function as part of its init.

Example When a unit is created:

_soldier = _team CreateUnit [_unit,_position,[],0.6,"FORM"];
[_soldier] Call InitUnit;

Example when a vehicle is created:


_vehicle = _team CreateUnit [_unit,_position,[],0.6,"FORM"];
_crewmen = crew _vehicle;
{[_x] Call InitUnit} forEach _crewmen;

Compiling it in init.sqf you still have to put the code in the editor object initialization fields, since the mission's init.sqf runs after the editor objects initialize.
The function would be used for objects created during the mission.

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  

×