Jump to content
Sign in to follow this  
norrin

Example scripts that use the attachTo command

Recommended Posts

Simple beginners question, I'm using Norrins attach mount_vcl_init.sqf scripts etc successfully to load and unload ammo crates.

But, how do I configure these scripts/vehicle init line so vehicle is preloaded with ammo crate at mission start (AAV's conducting amphibious assualt)???

OK solution provied by ZSU Victim, as below:

"create a new file in the mountonvcl subdirectory called automount_vcl.sqf:"

// automount_vcl.sqf

// © SEP 2009 - Victim (scgadsl@gmail.com)

// based on original work © JUNE 2009 - norrin (norrin@iinet.net.au)

_vcl = _this select 0;

_typeOfVcl = _this select 1;

_mountVcl = objNull;

_mountVcl = nearestObjects [_vcl, [_typeOfVcl], 20] select 0;

_mountVcl attachTo [_vcl,[0.3,-1.5,0.3]];

sleep 0.1;

_vcl setVariable ["NORRN_mountOn_vcl_pos0", [true, _mountVcl], true];

if (true) exitWith {};

"Then edit the mount_vcl_init.sqf and add the following lines in BOLD RED"

// mount_vcl_init.sqf

// © JUNE 2009 - norrin (norrin@iinet.net.au)

/*

Name playable units and vehicle in the editor

Put this in the init line of the vehicle in the editor: nul = [this] execVM "mountOnVcl\mount_vcl_init.sqf";

*/

_vcl = _this select 0;

_typeOfVcl = _this select 1;

_automount = _this select 2;

_c = 1;

_load = _vcl addAction ["Load bike on truck", "mountOnVcl\mount_vcl.sqf", _typeOfVcl, 0, false, true];

_unload = _vcl addAction ["Unload vehicle", "mountOnVcl\dismount_vcl.sqf","", 0, false, true];

_toAttach = objNull;

_vcl removeAction _load;

_vcl removeAction _unload;

if (isServer) then

{

_vcl setVariable ["NORRN_mountOn_vcl_pos0", [false, objNull], true];

sleep 2;

if (_automount) then

{

//hint "Attempting to Automount...";

nul = [_vcl,_typeofVcl] ExecVM "mountOnVcl\automount_vcl.sqf";

};

};

while {alive _vcl} do

"Finally change your vehicle init line from this:

nul = [this,"bicycle"] execVM "mountOnVcl\mount_vcl_init.sqf";

to this:

nul = [this,"bicycle",true] execVM "mountOnVcl\mount_vcl_init.sqf";

if you don't want it to automount then use this:

nul = [this,"bicycle",false] execVM "mountOnVcl\mount_vcl_init.sqf"; "

Share this post


Link to post
Share on other sites
I was put this scripts in Xneo's "The longest day" mission. But I can't play with it, when I go to platform it show two boats on there, and I can't see anything in actionmanu.

I put "nul=[] execVM "Mission\BoatLaunch\LHD_Init.sqf";" in the missions init.sqf is it correct? Can you tell how to solution this problem?

It's an issue with the script not being dedicated server friendly. If anyone could make the adjustments so that this works in MP I for one would be grateful! :239::notworthy:

Share this post


Link to post
Share on other sites
OK solution provied by ZSU Victim, as below:

"create a new file in the mountonvcl subdirectory called automount_vcl.sqf:"

"Then edit the mount_vcl_init.sqf and add the following lines in BOLD RED"

"Finally change your vehicle init line from this:

nul = [this,"bicycle"] execVM "mountOnVcl\mount_vcl_init.sqf";

to this:

nul = [this,"bicycle",true] execVM "mountOnVcl\mount_vcl_init.sqf";

if you don't want it to automount then use this:

nul = [this,"bicycle",false] execVM "mountOnVcl\mount_vcl_init.sqf"; "

Im sorry but this is probably gonna be a dumb question, i am very new to scripting and i am having a tough time reading and learning it. This will allow you to pick up a ammo crate and drop it off? Will it work for a uh-y1 or is it only for a plane. Is there one for a uh-y1 and if there is, is there a way to drop the crate from really high so it can parachute down, or is that how it already works?

Share this post


Link to post
Share on other sites

But the script will let me pick up an ammo crate from a heli, and take it over to my friends that are encircled by enemies and low on ammo and drop it off to them fully filled?

Share this post


Link to post
Share on other sites
"create a new file in the mountonvcl subdirectory called automount_vcl.sqf:"

Man i just must be stupid...where do i find the mountonvd at... or do i even need it. and how does this script know what vehicle is needed to attach the ammo crates? Sorry you can obviously tell i am new at this because i am just so lost.

Share this post


Link to post
Share on other sites

We have a little induction mission we run for new players to our group weekly, so I thought I'd give the regular induction trainer staff a bit of a shock.... (yes this in on topic...) ;D

Share this post


Link to post
Share on other sites

Ok I must admit I love Norrins little attachto scripts. I have altered and played around with the bike on the pickup one to acomplish all sorts of things like carrying ammo crates, mortars, adding searchlights to the back of trucks the list goes on!

Here is one thing that I am sure some people will love. I have always wanted to be able to tow the M119 around before a truck. Now this doesn't do anything fancy it just attaches the gun to the back of the truck, so the wheels don't rotate and the base plate is still present, though partially hidden most of the time. At least it gives me the ability to add this to the missions if I need to relocate etc.

towgun.jpg

// mount_vcl.sqf
// © JUNE 2009 - norrin (norrin@iinet.net.au)

_vcl 			= _this select 0;
_caller			= _this select 1;
_typeOfVcl		= _this select 3;
_dir			= getdir _vcl;
_mountVcl 		= objNull; 
_blogs			= 0; 
_c			= 0;
_dir1 			= 0;


if (count nearestObjects [player, [_typeOfVcl], 20] > 0) then
{
_mountVcl = nearestObjects [player, [_typeOfVcl], 20] select 0;
}; 

if (vehicle _caller != _caller) then {_caller action ["GetOut", vehicle _caller]; sleep 1};

if (!((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0)) then
{	

_dir1 = getdir _vcl;
_vcl setdir 0;
_mountVcl attachTo [_vcl,[0,-6.4,-1.2]]; 
_mountVcl setDir 180;
_mountVcl setVectorup [0,-0.15,1];
_vcl setdir _dir1;


sleep 0.1;
_vcl setVariable ["NORRN_mountOn_vcl_pos1", [true, _mountVcl], true];
};

if (true) exitWith {};

So all I have done is added bits to the mount_vcl.sqf script. Then in the init line of the truck assigned the type of object to be attached to M119

nul = [this,"M119"] execVM "mountOnVcl\mount_vcl_init.sqf";

The rest of the scripts are as per Norrins Put bike in Pickup scripts.

As always love your work Norrin!

This has not been tested in MP, just been playing around, and their is probably a better way of doing it, but it may just give a little enjoyment to others like it has to me.

Share this post


Link to post
Share on other sites

Is there a way to make the hinge work? Or at least limit turning radius of the vehicle to simulate the extra weight and friction when turning sharply. Using the tow tractor on the C130 lets you do donuts and knock everything in your path over.

Share this post


Link to post
Share on other sites
Is there a way to make the hinge work? Or at least limit turning radius of the vehicle to simulate the extra weight and friction when turning sharply. Using the tow tractor on the C130 lets you do donuts and knock everything in your path over.

Not without a lot of work. Regarding the turning circle it is not as noticable, the example you give is the worst case scenerio using the vehicle with the smallest turning circle attached to the longest model towed. Though trying to turn the C130 without it is even more fun!

I will take the limitations for the benefits.

Share this post


Link to post
Share on other sites

Damn guys help. I do what it said but i can't get any of them to work. Maybe i am doing something wrong. Any advice?

---------- Post added at 10:47 PM ---------- Previous post was at 10:31 PM ----------

oh nevermind

Share this post


Link to post
Share on other sites

blakeace: your script works nice, but on dedicated the gun is turned in the opposite way when you load it. See:

vitalfist1.jpg

In SP and hosted game it works nicely.

Share this post


Link to post
Share on other sites
blakeace: your script works nice, but on dedicated the gun is turned in the opposite way when you load it. See:

vitalfist1.jpg

In SP and hosted game it works nicely.

Not sure about this one mate, have to admit I am far from a dedicated server expert. I can only confirm it is doing the same thing on our server. Sometimes it would set the correct angle in relation to the truck, but would always fail to angle correctly to set the connection point correctly.

Wish I could be of more help, but this will have to wait for someone who is more familiar with dedicated servers.

Share this post


Link to post
Share on other sites

Blakeace: tnx for reply.

Something stays local instead of being a public variable... guys any clues?

Share this post


Link to post
Share on other sites

Instead of:

gun setdir 123;

Do:

gun setvehicleinit "this setdir 123";

processinitcommands;

Edit: Yes, I know wiki says the setdir should sync, but doesn't work for me either.

Share this post


Link to post
Share on other sites
Instead of:

gun setdir 123;

Do:

gun setvehicleinit "this setdir 123";

processinitcommands;

Edit: Yes, I know wiki says the setdir should sync, but doesn't work for me either.

Thanks shk, that was the right path to fix this. I have got it to work on our dedicated server, though sometimes the whole rig points north when loading.

But the Gun always loads right and unloads flat. Might look funny on steep inclines didn't test to be honest.

I usually slightly raise the gun barrel before loading to make it look better.

// mount_vcl_init.sqf
// © JUNE 2009 - norrin (norrin@iinet.net.au)
/*
Name playable units and vehicle in the editor
Put this in the init line of the vehicle in the editor: nul = [this] execVM "mountOnVcl\mount_vcl_init.sqf";
*/

_vcl 		= _this select 0;
_typeOfVcl	= _this select 1;
_c 			= 0;
_load = _vcl addAction ["Load bike on truck", "TankTow\mount_vcl.sqf", _typeOfVcl, 0, false, true];
_unload = _vcl addAction ["Unload vehicle", "TankTow\dismount_vcl.sqf","", 0, false, true];
_toAttach 	= objNull;
_vcl removeAction _load;
_vcl removeAction _unload;

if (isServer) then
{
_vcl setVariable ["NORRN_mountOn_vcl_pos1", [false, _toAttach], true];
sleep 2;
};
while {alive _vcl} do
{ 
if (!((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0) && _c == 0 && count (nearestObjects [_vcl, ["man"], 10]) > 0 && count (nearestObjects [_vcl, [_typeOfVcl], 10]) > 0) then
{	
	_load = _vcl addAction ["Attach Gun", "TankTow\mount_vcl.sqf", _typeOfVcl, 0, false, true];
	_vcl removeAction _unload;
	_c = 1;
};

if (((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0) && _c == 1) then
{	
	_unload = _vcl addAction ["Release Gun", "TankTow\dismount_vcl.sqf","", 0, false, true];
	_vcl removeAction _load;
	_c = 0;
};
if (count (nearestObjects [_vcl, ["man"], 10]) == 0 || count (nearestObjects [_vcl, [_typeOfVcl], 10]) == 0) then
{
	_vcl removeAction _load;
	_vcl removeAction _unload;
	if (!((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0)) then {_c = 0};
	if ((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0) then {_c = 1};
};	
//hint format ["%1", (_vcl getVariable "NORRN_mountOn_vcl_pos1")];
sleep 0.5;
/*
if(speed _vcl >= 20 and _c == 1 ) then 
{
	_vel = velocity _vcl;_dir = direction _vcl;
	_speed =5.3; comment "Added speed";
	_vcl setVelocity [(sin _dir*_speed),(cos _dir*_speed),(_vel select 2)];
};
*/


};
if (!alive _vcl) exitWith {};

// mount_vcl.sqf
// © JUNE 2009 - norrin (norrin@iinet.net.au)

_vcl 			= _this select 0;
_caller			= _this select 1;
_typeOfVcl		= _this select 3;
_dir			= getdir _vcl;
_mountVcl 		= objNull; 
_blogs			= 0; 
_c			= 0;
globaldir1 			= 0;


if (count nearestObjects [player, [_typeOfVcl], 20] > 0) then
{
_mountVcl = nearestObjects [player, [_typeOfVcl], 20] select 0;
}; 

if (vehicle _caller != _caller) then {_caller action ["GetOut", vehicle _caller]; sleep 1};

if (!((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0)) then
{	

globaldir1 = getdir _vcl;
_vcl setvehicleinit "this setdir 0;";
processinitcommands;
_mountVcl attachTo [_vcl,[0,-6.4,-1.2]]; 
_mountVcl setvehicleinit "this setDir 180; this setVectorup [0,-0.15,1];";
processinitcommands;
_vcl setvehicleinit "this setdir globaldir1;";
processinitcommands;
sleep 0.1;	
_vcl setVariable ["NORRN_mountOn_vcl_pos1", [true, _mountVcl], true];
};

if (true) exitWith {};

// dismount_vcl.sqf
// © JUNE 2009 - norrin (norrin@iinet.net.au)

_vcl 			= _this select 0;
_caller			= _this select 1;
_mountVcl		= (_vcl getVariable "NORRN_mountOn_vcl_pos1") select 1;
_vclDir			= getDir _vcl;


if (vehicle player == player) then 
{	
detach _mountVcl;
_mountVcl setvehicleinit "this setDir 180; this setVectorup [0,0,0];";
processinitcommands;
_vcl setVariable ["NORRN_mountOn_vcl_pos1", [false, objNull], true];
};

if (true) exitWith {};

Share this post


Link to post
Share on other sites

Hey as a rabid revive user i love the work you do norrin. took a look at your move to door heli script last night and its fantastic! As there are a few Gereration Kill fans in ZSU the clan i belong to. i decided to see what would happen if i put your attachto on a hummer or a CRRCs. had an intresting eftect. it works except for druing speed, i guess this is something to do with valocity in your script. as im a noob when it comes to scripting and volcity im not gonna touch that with 50 foot barge pole!:eek: would love if someone could take a look and tell me what they think.Atttach to hummer

Share this post


Link to post
Share on other sites
Ok I must admit I love Norrins little attachto scripts. I have altered and played around with the bike on the pickup one to acomplish all sorts of things like carrying ammo crates, mortars, adding searchlights to the back of trucks the list goes on!

Here is one thing that I am sure some people will love. I have always wanted to be able to tow the M119 around before a truck. Now this doesn't do anything fancy it just attaches the gun to the back of the truck, so the wheels don't rotate and the base plate is still present, though partially hidden most of the time. At least it gives me the ability to add this to the missions if I need to relocate etc.

towgun.jpg

// mount_vcl.sqf
// © JUNE 2009 - norrin (norrin@iinet.net.au)

_vcl 			= _this select 0;
_caller			= _this select 1;
_typeOfVcl		= _this select 3;
_dir			= getdir _vcl;
_mountVcl 		= objNull; 
_blogs			= 0; 
_c			= 0;
_dir1 			= 0;


if (count nearestObjects [player, [_typeOfVcl], 20] > 0) then
{
_mountVcl = nearestObjects [player, [_typeOfVcl], 20] select 0;
}; 

if (vehicle _caller != _caller) then {_caller action ["GetOut", vehicle _caller]; sleep 1};

if (!((_vcl getVariable "NORRN_mountOn_vcl_pos1") select 0)) then
{	

_dir1 = getdir _vcl;
_vcl setdir 0;
_mountVcl attachTo [_vcl,[0,-6.4,-1.2]]; 
_mountVcl setDir 180;
_mountVcl setVectorup [0,-0.15,1];
_vcl setdir _dir1;


sleep 0.1;
_vcl setVariable ["NORRN_mountOn_vcl_pos1", [true, _mountVcl], true];
};

if (true) exitWith {};

So all I have done is added bits to the mount_vcl.sqf script. Then in the init line of the truck assigned the type of object to be attached to M119

nul = [this,"M119"] execVM "mountOnVcl\mount_vcl_init.sqf";

The rest of the scripts are as per Norrins Put bike in Pickup scripts.

As always love your work Norrin!

This has not been tested in MP, just been playing around, and their is probably a better way of doing it, but it may just give a little enjoyment to others like it has to me.

About norrins script. How to change what can be added?

Share this post


Link to post
Share on other sites

Love this script - I've been playing around with the pick-up truck and the bike for quite a while now

mountedBike.jpg

(I've been using trucks'n mortars instead though ;))

Then I've tried to make some additional script in order to carry 3 tubes pr. truck instead of just one. I do get 3 "Load Mortar" options, but once I've loaded one Mortar I suddenly get 3 "Unload Mortar" options... ?!?

How can I load several items in one vehicle and how do I unload them next to eachother instead of at the same spot...? :)

Share this post


Link to post
Share on other sites
About norrins script. How to change what can be added?

nul = [this,"M119"] execVM "mountOnVcl\mount_vcl_init.sqf";

By the variables passed.

In this case the script command is place in the vehicles init line. So "this" is refering to that particular vehicle, the second parameter is what the script looks for to carry.

Note different objects have different positional requirements meaning you would have to adjust the attachto offset in the mount script.

Then I've tried to make some additional script in order to carry 3 tubes pr. truck instead of just one. I do get 3 "Load Mortar" options, but once I've loaded one Mortar I suddenly get 3 "Unload Mortar" options... ?!?

How can I load several items in one vehicle and how do I unload them next to eachother instead of at the same spot...? :)

I looked at this a while ago, but can't find the scripts atm. If I remeber Norrin uses a variable to save the current state of the script.

	_vcl setVariable ["NORRN_mountOn_vcl_pos0", [false, _toAttach], true];

I believe this was it. My "bandaid solution was to create a second script, where I changed NORRN_mountOn_vcl_pos0 to NORRN_mountOn_vcl_pos1 in the second script. Not very elegant but created two positions on a truck.

Though I am going by memory here so could be off the mark!

Edited by blakeace

Share this post


Link to post
Share on other sites

Please I need help. Where do I place the script for the C-130 do I place it along with the mission sqm. in C:\Users\Owner\Documents\ArmA 2 Other Profiles\shadowhunter388\missions\? When I go to load it it says. Cannot find script eject sqs.. I cant fiqure out how to get it to work. Please if you can reply and help me. thanks ;)

---------- Post added at 08:35 AM ---------- Previous post was at 08:06 AM ----------

Yeah I need help are you supposed to put the mission.sqm and the script sqf in C:\Users\Owner\Documents\ArmA 2 Other Profiles\shadowhunter388\missions? if so when I load the misson it says script scripts/eject1.sqf is not found.

Share this post


Link to post
Share on other sites
Please I need help. Where do I place the script for the C-130 do I place it along with the mission sqm. in C:\Users\Owner\Documents\ArmA 2 Other Profiles\shadowhunter388\missions\? When I go to load it it says. Cannot find script eject sqs.. I cant fiqure out how to get it to work. Please if you can reply and help me. thanks ;)

---------- Post added at 08:35 AM ---------- Previous post was at 08:06 AM ----------

Yeah I need help are you supposed to put the mission.sqm and the script sqf in C:\Users\Owner\Documents\ArmA 2 Other Profiles\shadowhunter388\missions? if so when I load the misson it says script scripts/eject1.sqf is not found.

If you are refering to Norrins script from http://forums.bistudio.com/showthread.php?t=73630&page=2 then the scripts are to be located in a sub directory of the mission directory.

Directory Name = mountOnC130

nul = [this,"car"] execVM "mountOnC130\mount_vcl_init.sqf";

As you can see from the call to the script above.

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  

×