Jump to content
Sign in to follow this  
katipo66

attach back to object addaction

Recommended Posts

I have this applied to a weapon which attaches to quad no problem, coordinates are all wrong but easily sorted (so i think :D)

sniperg attachTo [quad1,[0,1,1]]; 

In my init.sqf i have

quad1 addAction ["<t color='#ffffff' size='1'>Attach to Quad</t>", { execVM "attachgun.sqf"}];

which shows up as it should..

And where im obviously not getting it is in my attachgun.sqf i simply have:

sniperg attachTo [quad1,[0,1,1]];

Ive tried a lot of different variations from examples online but its not working.

What i want to achieve is to be able to remove and attach the weapon anytime.

I remember someone had made a nice mission on Tora Bora with the same quad setup im trying to achieve, but memory is very hazy its one in the morning and missus pissed off at key board tapping away, damn this game!

Share this post


Link to post
Share on other sites

¨1: create a variable, for example in init.sqf

gunIsNowAttached = false;

2: add two addActions with each a condition.

quad1 addAction ["<t color='#ffffff' size='1'>Attach to Quad</t>", { execVM "attachgun.sqf"}, [], 1, false, false, "", !gunIsNowAttached];
quad1 addAction ["<t color='#ffffff' size='1'>Detach from Quad</t>", { execVM "attachgun.sqf"}, [], 1, false, false, "", gunIsNowAttached];

in "attachgun.sqf" do this or similar.

if (gunIsNowAttached) then {
detach sniperg;
gunIsNowAttached = false;
} else {
sniperg attachTo [quad1,[0,1,1]];
gunIsNowAttached = true;
};

Share this post


Link to post
Share on other sites

Damn! Lol... i thought I was dreaming, It's good to see you back man!!

Thanks for the pro tip :)

Edit* its not quite working, i added quotes around the conditions (e.g. "!gunIsNowAttached") which makes them appear in the action menu but the attachto does not do anything, there are no script errors and i placed a hint at the end of attachgun.sqf that appears when selecting 'Attach to Quad'... the addaction works as it should its just not attaching the weapon.

I think the clue may be in the link provided so im gonna try and figure this one out, please dont mind if i come back begging.

Also i found the Tora bora mission i mentioned if anyone else was interested The Battle of Tora Bora (Deep Recon) - actually i realized it doesnt have the ability to attach rifle back to quad after all.

Edited by Katipo66

Share this post


Link to post
Share on other sites

thank you :)

You are right, should be qoutes around the condition.

the other error you get is because of {} brackets around the script, that means you can do correct code directly in the action.

ex code:

quad1 addAction ["<t color='#ffffff' size='1'>Attach to Quad</t>", [color="#FF0000"]{ sniperg attachTo [quad1,[0,1,1]]; gunIsNowAttached = true; }[/color], [], 1, false, false, "", "!gunIsNowAttached"];
quad1 addAction ["<t color='#ffffff' size='1'>Detach from Quad</t>", [color="#FF0000"]{ detach sniperg; gunIsNowAttached = false; }[/color], [], 1, false, false, "", "gunIsNowAttached"];

or

quad1 addAction ["<t color='#ffffff' size='1'>Detach from Quad</t>", [color="#FF0000"]{ _this = [] execVM "attachgun.sqf" }[/color], [], 1, false, false, "", "gunIsNowAttached"];

ex script:

quad1 addAction ["<t color='#ffffff' size='1'>Attach to Quad</t>", [color="#FF0000"]"attachgun.sqf"[/color], [], 1, false, false, "", "!gunIsNowAttached"];
quad1 addAction ["<t color='#ffffff' size='1'>Detach from Quad</t>", [color="#FF0000"]"attachgun.sqf"[/color], [], 1, false, false, "", "gunIsNowAttached"];

Also a suggestion to setPos the weapon next to quad on detach, because it will hang in the air after detach.

Edited by Demonized
fixed missing "" in conditions

Share this post


Link to post
Share on other sites

Awesome, thanks mate I'll apply this first opportunity and get back to confirm.

Edit* Just a note that it works as it should of course apart from "sniperg attachTo [quad1,[0,1,1]];" does not work, but no biggie as i simply have it in the weapons init and everything works as it should.. the ability to enter code directly is nice and clean and i will attempt to build on this.. also ive taken your advice in your sig, ive half assed attempted various times to learn but easily gave up, but the code doesnt look as scary as it used to :) thanks again.

Edited by Katipo66

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  

×