Jump to content
mcnools

Simple way to add item to all playable units?

Recommended Posts

Well, I just completed the 10th mission in a campaign I'm making for a group and I realized I forgot to add Ace Earplugs to the default loadout.

Is there any way to just put a script in the init.sqf or similar (easy to copy into all the missions) that adds an item (in this case ACE_EarPlugs) to every playable unit on mission start?

This would probably be quicker than going through all missions and every single unit (some already have some specific things in their init so I can't override all of them). So I thought I'd just ask before heading into this grueling task.

 

Share this post


Link to post
Share on other sites

In both initPlayerLocal.sqf and onPlayerRespawn.sqf (if applicable):
 

waitUntil {!isNull player};
params ["_unit"];

_unit addItemToUniform "ACE_EarPlugs";

 

*edit* - Have you given up on terrain creation? Your A2 terrains are still among the very best. Thanks for your significant contributions the community!

  • Like 2

Share this post


Link to post
Share on other sites

Also, if you are using a set of standardized loadouts, I find it best to handle them via sqf. That way, you can simply edit the script and copy/past the edits (or entire files - I just use a "loadouts" folder) to your other missions.

 

Build them in the Arsenal, export, clean up the formatting, then call them from each unit's init (and via respawn EH if needed).

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Harzach said:

In both initPlayerLocal.sqf and onPlayerRespawn.sqf (if applicable):
 


waitUntil {!isNull player};
params ["_unit"];

_unit addItemToUniform "ACE_EarPlugs";

 

*edit* - Have you given up on terrain creation? Your A2 terrains are still among the very best. Thanks for your significant contributions the community!

 

Thank you very much! Will try that first thing tomorrow. 🙂

And thanks for your compliment! I have indeed given up on terrain creation simply due to how much time it takes. I've been happy to see others getting my maps working properly in ArmA 3 though, and it always makes me glad to see people still remember them, so thank you! 

  • Like 2

Share this post


Link to post
Share on other sites

Sorry for the late reply but I didn't have time to test the script on our server until now. Unfortunately I cannot get it to work. Do I have to specify the unit ID's in the "_unit"-param? and if so, how do I separate the ID's when I put in multiple ones?

(sorry if I'm missing something obvious, while I've been making missions since OFP I still can't really grasp scripting very well, haha).

Share this post


Link to post
Share on other sites

Nope, the line

params ["_unit"];

is the same as 

private ["_unit"];
_unit = _this select 0;

and in these specific event scripts, "_this select 0" is the local player. Therefore, as each player joins or respawns, these scripts will run on them locally.

 

Are the earplugs just not appearing, or are you getting errors?

Share this post


Link to post
Share on other sites

The earplugs aren't appearing but I'm not getting any errors. I put the code into "initPlayerLocal.sqf".

 

If I understand correctly you don't have to execute the initplayerlocal.sqf script manually right? it should just kick in when you start?

Share this post


Link to post
Share on other sites

Correct. 

 

Maybe there is a conflict? Post the contents of those event scripts.

Share this post


Link to post
Share on other sites

Possibly, I don't have anything else in the initplayerlocal.sqf though.. Only thing I have is some post processing settings in the init.sqf. However, I am running with ACE so maybe that conflicts somehow. Not that it should I guess, only thing I can think about that is related there is that we use the setting for respawning with the same gear you died with.

edit: tried it on a completely clean mission too but no luck unfortunately. Adding "this additem "ACE_EarPlugs" to a units init seems to give him the earplugs so at least it's the right classname, haha (always good to rule that out).

Share this post


Link to post
Share on other sites

Well, without ACE it wouldn't work at all 🙂

 

It might be the ACE gear respawn setting, though not sure why that would cause an issue on first spawn - unless you are using respawn on start, maybe?

 

Make a clean repro mission with just ACE/CBA loaded and share it here.

Share this post


Link to post
Share on other sites

Ah, the ol' copy/paste bug. This time it was in the script file name.

 

fGHW6dt.png

 

If you are copy/pasting anything from this forum, you might want to paste it into a code block here first, to see if you have any bad characters. The red dot denotes a bad character.

 

Just re-type the full file name, including extension, and you should be all set.

Share this post


Link to post
Share on other sites

Haha, damn. Never knew that was a thing. Your'e right, works fine now. That might explain why some other scripts from the forums I've tried never worked... Guess you learn something new every day, haha. Thank you very much for your help man! Saved me a lot of trouble.

Share this post


Link to post
Share on other sites

Yeah, sometimes I forget and spend far too long trying to figure out why something isn't working. It can help to use an editor with syntax formatting/highlighting. Notepad++ with something like this, for example:

These copy/paste errors will sometimes make themselves apparent if they break the highlighting. 

 

There are also more complete, "professional" solutions like Poseidon, if you want.

 

  • Like 2

Share this post


Link to post
Share on other sites

I'll take a look at that, looks very useful! thanks again!

Share this post


Link to post
Share on other sites
4 hours ago, Harzach said:

There are also more complete, "professional" solutions like Poseidon, if you want.

 

 

Too bad that Poseidon is no more updated with new commands. But a very good tool, indeed. I do like the "press F1" opening the BIKI page for the command at cursor.

  • Like 1

Share this post


Link to post
Share on other sites
26 minutes ago, pierremgi said:

 

Too bad that Poseidon is no more updated with new commands. But a very good tool, indeed. I do like the "press F1" opening the BIKI page for the command at cursor.

 

Ahh, that's too bad. Great tools seem to fall by the wayside - I recall Squint being very useful back in A2. I'm sure it's a PITA keeping these things up-to-date. Janez is doing a great job of maintaining that N++ highlighter.

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

×