Jump to content
Sign in to follow this  
zipman

help - load/unload ammo crates into MHQ/vehicles

Recommended Posts

i turn to this wonderful forum as i know im going beyond myself on this, would like to try and load/unload ammo crates into MHQ/vehicles.

i have no clue where to start but it would be great to have it in the mission im trying to build,

if anyone has a way to do this please help, a simple mission with the scripts would be wonderful,

thanks for any help once again

Share this post


Link to post
Share on other sites

It's probably just done by setting a variable attached to the vehicle of it's got something in or not. When you deploy you create whatever box you want, when you load it you delete whatever one was previously deployed.

Look into createVehicle/deleteVehicle for creating and destroying the crate. The US Basic Weapons box has a classname of USBasicWeaponsBox, you'd probably want to empty this and fill it with whatever weapons/ammo you wanted. Look into clearMagazineCargo and clearWeaponCargo along with addWeaponCargo and addMagazineCargo

Then check out setVariable for keeping track of if it's loaded or not.

Share this post


Link to post
Share on other sites

thanks for the reply im even more lost now then when i started.hehe

ok this is the thing, have a MHQ thats a mobile spawn, in it i would like to have it load a ammo crate (US Basic Weapons box would be fine), then drive off get anywhere on the map and drop/spawn/unload the ammo crate,

i have now searched all over and cant seem to find anythink, i have seen it in a few MP maps but wouldnt know where to start to look how its done. im a real noobie when it comes to anythink arma/arma2 and scripts

Share this post


Link to post
Share on other sites

What you're asking for isn't a few lines of code nor will it be easy, it's a system. To use it you'll want to know what you're doing.

You could try something like "TransBox" from Mad Max. It's for OFP, but might work for ArmA2. Problem is, it might conflict with your MHQ stuff. Depends on how you're doing the MHQ thing really. Posting that would help.

I've already explained basically what you'll need to do, and given you links to the commands that will do them. If you're a newbie to scripting and want to learn, this is a pretty good exercise to start with. :) Give it a try and post what you get.

Edit: Something you asked in another thread gave me an idea, and you could actually use attachTo for this and skip a lot of the variable nonsense. hmm. Using a USBasicWeapons box you'd use this to mount it: this attachTo [MHQ1,[.5,-1.5,.9]];

Edited by kylania
attachTo is wonderful

Share this post


Link to post
Share on other sites

kylania if its not to much trouble could you do a sample of them as you seem to know what your taking about, i would learn faster if i was looking at a sample would be layed out for the ammo or & the attachTo thing,

really thanks for your time

Share this post


Link to post
Share on other sites

I got the ammo box working using attachTo. It's pretty neat. :) Working in the MHQ respawn stuff I think you're using too.

Share this post


Link to post
Share on other sites

TL;DR = It works. Within 15m with engine off. Action is on the MHQ. Test mission included.

You can download the test mission, MHQ Proof of Concept to follow along with the umm.. following.

Well, the main challenge in this was dealing with vehicle respawn. I'm actually not sure it's working properly in multiplayer to be honest. The vehicle respawn method I used was "Simple Vehicle Respawn Script v1.3" by Tophe. It didn't really work with the ammo box though, and I'm too tired to try to fix it, so instead I made the ammo box a one time thing. If you lose it, too bad you're gonna have to use the ammo at base.

For the MHQ itself, I decided to stick with the 'respawn at base, teleport to the MHQ' concept, but very simple. No dialogs, no error checking, just.. poof!

I also use ArmATec's AmmoRefiller script on the ammobox to keep it full all the time it's alive.

I decided to limit the loading of the box to only work with the MHQs engine turned off and the box within 15 meters of the MHQ. Unloading is similar, having to have the engine turned off. While this does allow some speedy coasting load/unload times, it seemed reasonable.

So, first up, the ammobox! It's called mhq1_ammobox since I was too lazy to make a full init file with options and stuff. So call it that. It's init string is the following, which simply sets up the autorefill script for it. Otherwise, nothing special about it.

_null = [this] execVM "AmmoRefill.sqf";

Second you have your MHQ. It must be called mhq1, again since I'm lazy. It also must be the LAV25_HQ vehicle, or else you'll need to change some code to make it match the proper typeOf after respawn. It's init string is a bit more complicated, since we're both adding the option to load the ammobox and setting up vehicle respawn on it.

_null = mhq1 addaction ["Load ammobox", "attach_ammobox.sqf"]; veh = [this, 15, 100000000, 5, TRUE] execVM "vehicle.sqf";

The 100,000,000 setting in the respawn line is to keep it from exploding when you get out. Several times it would think you'd abandoned it and explode. At first it was funny, not so much after a few hours of testing.

I put a few extra vehicles with respawns in the test mission as well. There's also a Flag pole with the following init:

_null = this addaction ["Teleport", "teleport.sqf"];

Basically, run up to it, click Teleport and you appear behind the MHQ.

There are two triggers, Radio Alpha to kill yourself and Radio Beta to kill the MHQ, for testing or lulz.

Now, the scripts! The first script is what attaches the box to the MHQ.

attach_ammobox.sqf:

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {
// Remove the current actions.
_removeActions = [mhq1] execVM "removeActions.sqf";
waitUntil {scriptDone _removeActions};
hint "Nothing to load!";
} else {
// Since the box is still in one piece, make sure it's within 15m of the MHQ and the MHQ isn't on.
if (mhq1 distance mhq1_ammobox < 16 and !isEngineOn mhq1) then 
{
	// Attach the box to the MHQ roof.
	mhq1_ammobox attachTo [mhq1,[.5,-1.5,.9]];

	// Clear the current actions.
	_removeActions = [mhq1] execVM "removeActions.sqf";
	waitUntil {scriptDone _removeActions};

	// Change the action on the MHQ to unload the box now.
	_null = mhq1 addaction ["Unload ammobox", "detach_ammobox.sqf"];

} else {
	// If the box isn't within 15m or the engine is running, tell them they have to try again.
	hint "You must be within 15m of the ammo box, with your engine off, to load it!";
};
};

Next is the code for detaching the ammobox and moving it 10m behind the MHQ.

detach_ammobox.sqf:

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {
// Remove the current actions.
_removeActions = [mhq1] execVM "removeActions.sqf";
waitUntil {scriptDone _removeActions};
hint "Nothing to load!";
} else {
// Since it's alive, make sure the engine is off on the MHQ.
if (!isEngineOn mhq1) then {

	// Detach it, and move it 10m behind the MHQ, on the ground.
	detach mhq1_ammobox;
	_worldPos = mhq1 modelToWorld [0,-10,0];
	mhq1_ammobox setPos [_worldPos select 0, _worldPos select 1, 0];

	// Remove the current actions.
	_removeActions = [mhq1] execVM "removeActions.sqf";
	waitUntil {scriptDone _removeActions};

	// Add the action to load it again.
	_null = mhq1 addaction ["Load ammobox", "attach_ammobox.sqf"];

} else {
	// If the engine was running, warn the user.
	hint "You can't unload while your engine is running!";
};
};

Third script is just a little function for clearing the actions. Since it's called so often I wrote it once and reference the function instead of writing the code each time.

removeActions.sqf:

// Grab the input.
_mhq = _this select 0;

// Remove all player added actions from the object.
_action = _mhq addAction["foo", "foo.sqf"];
while {_action >= 0} do	{
_mhq removeAction _action;
_action = _action - 1;
};

Here's the crazy basic teleport script.

teleport.sqf:

// Who activated the action?
_caller = _this select 1;

// Move them 5m behind the MHQ.
_worldPos = mhq1 modelToWorld [0,-5,0];
_caller setPos [_worldPos select 0, _worldPos select 1, 0];

And here's what I added to the Vehicle Respawn system to allow the MHQ to continue working after being destroyed (something I read most vehicle respawn scripts don't handle.)

Additions to vehicle.sqf:

		// Added by Venori.
	// This checks if it's the MHQ being respawned and if so, sets the vehicle name back to "MHQ1" so the scripts all keep working.
	if (_type == "LAV25_HQ") then {
		_VarName = "mhq1";
		_unit SetVehicleVarName _VarName;
		_unit Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];
		sleep 1;
		// If for some reason the ammo box is still alive, give the option to load it again.
		if (alive mhq1_ammobox) then {
			_null = mhq1 addaction ["Load ammobox", "attach_ammobox.sqf"];
		};
	};

The few remaining bugs are 1) the respawn script I choose doesn't appear to be MP friendly 2) it's possible to at times blow up the MHQ, but not the ammobox that was attached. In this case the ammobox floats in mid air till you drive back to it and reload it. 3) Not really a bug, but I'm slightly disappointed I couldn't get the box respawn working.

Share this post


Link to post
Share on other sites

WOW i was right you really know your stuff, i`ll have a go at this and let you know how it goes, this is really good thanks so so so so much, i hope to be able to work it all in to the mission im trying to make

thanks again i hope im smart enough to work all this out to it works after your hard work working it out, thanks again

---------- Post added at 07:52 PM ---------- Previous post was at 06:11 PM ----------

ok i did it (followed your words) added it to my mission tested it out in battle..lol and endedup losing where the box was once the mhq blowup also mhq didnt spawn back on base so i thought adding another marker to the ammo box on the map so it would help find it but to get it to respawn back on base once the mhq blows up would be wicked, and yes i also found it funny seeing the boxes floating in the air i felt like david copperfield,

thanks for all your help.

---------- Post added at 08:23 PM ---------- Previous post was at 07:52 PM ----------

to the mhq i added your code

_null = mhq1 addaction ["Load ammobox", "attach_ammobox.sqf"]; veh = [this, 15, 100000000, 5, TRUE] execVM "vehicle.sqf";

then found i needed to also add Vehicle Respawn Script by {nBs**-Myke-{CO**

[this, 10, 0, 235] exec "vehi_respawn.sqs";

to get it to spawn back to the base and how it spawns back on base where i needed,

have looked again into how to make the ammo box respawn tested a few things but like i said before i dont know enough about this Script stuff it just seems alittle beyond me,

thanks for all the time you put in to working this out,

Edited by zipman

Share this post


Link to post
Share on other sites

I used the same script a while back and I am still using it. Thanks Kylania. I have the MHQ and the ammobox respawning. I changed the script slightly so if the MHQ is destroyed while the ammobox is still loaded on top of the vehicle, that it will then set the damage of the ammobox to 1 (destroying it). Otherwise if the vehicle is destroyed and then it respawns back at the base, the ammo crates would remain hovering in the air where it last was when it was on top of the vehicle. I also removed all load/unload actions when the vehicle is destroyed and then add back the action to load when the vehicle respawns. I have a yellow marker attached to both the MHQ and the MHQ Ammo, so no matter where you leave the MHQ and Ammo, you can always find them on the map. I am undecided on the abandon time for both the vehicle and the ammo. I had it set so the vehicle and ammo would blow up and respawn back at base after 30 minutes if left abandon, but I think I might change the time to infinity. It's a great script.

---------- Post added at 10:42 PM ---------- Previous post was at 10:20 PM ----------

Oh, I'm also using it for Arrowhead, but I'm using the Stryker ICV (M2), which works out great because I have an option to teleport to the Stryker from the base flag and when you teleport to it - it moves you in cargo. It's a 12 man coop mission, so it can actually hold all 12 players, or at least 10 in cargo. The best part is that even if the vehicle is moving, you can still teleport into the back of it. I was thinking of making a deployable net tent for it, but I kind of like how it is exposed and the enemy try to blow it up. Players usually park it between some buildings or behind some big rocks or something to keep the enemy from finding it. I will post an example mission shortly.

Share this post


Link to post
Share on other sites

I sent an example mission to Kylania. If he likes the changes I made, then he can add the changes to his original MHQ ammo load/unload script and offer it for public use. I wouldn't feel right posting an example mission to the public using a script sample that I didn't create. I merely made a few small changes, that's all.

So far it is definitely my favorite script. After using it for a while in online multiplay, I've grown to like it way more than the Domi servers version of MHQ ammo loading/unloading and teleporting. This version is more straight forward with none of that extra BS stuff where you deploy tents and atv's/motorcycles and the lame timers that make you wait before you can load/unload again. No offense, Domi is cool and all, but for me it has been way overplayed and I got bored with it all within the first month after buying the game.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites
This version is more straight forward with none of that extra BS stuff where you deploy tents and atv's/motorcycles and the lame timers that make you wait before you can load/unload again. No offense, Domi is cool and all, but for me it has been way overplayed and I got bored with it all within the first month after buying the game.

* Deploy tents? You deploy MHQ for several reasons: Get the vehicle locked (broken but fixable), prevent lifting, and make stuff happen in a timely fashion so that clients are guaranteed a vehicle status update.

* Well I prefer bicycles only myself. Consider motorcycles and ATVs as an example on how you should think if you needed to add more.

* Lame timers are actually needed. Once you start seeing how other people play and misuse features of your own mission, you will agree.

* Domination ammo crates are local to the player. It allows giving only equipment you're supposed to have (don't expect people in general to play their slot, if you have ever played with 30 wannabe M107 snipers you know what I'm talking about). It prevents synchronization errors between clients and JIP clients about the crate contents and what you can get out of it (used to be a massive problem). And it prevents theft.

If you only play with your own squad, much of the above isn't needed. But once you open up for public, intended gameplay tends to go down the drain and you start realizing that "hey, maybe that wasn't such a bad idea after all" :)

Share this post


Link to post
Share on other sites

you can't load the ammobox anymore after the vehicle gets destroyed :(

is there an domination like script out there?

Share this post


Link to post
Share on other sites

I understand Carl, lol, but for me and my friends - domi is still overplayed, old and boring and the MHQ vehicle has too much bs wrapped into it - considering I don't make coop missions with more than 16 player slots. I just made another new mission using the load ammo crate script. I have no problems loading the crate onto the MHQ vehicle after the vehicle has been destroyed and respawns. Sometimes if another player loads the crate and then I go to unload it, the action will say load for me instead of unload, but then I just choose the load action and then unload action and it unloads it, but I do wish I could get that worked out - even though it's no big deal really.

Instead of just having the one crate at base that gets dragged all around everywhere, it would be cool if a new crate would instantly be created and already loaded onto the vehicle every time the vehicle respawns. I guess I could do it with a separate vehicle respawn script designed just for the MHQ vehicle. Hmm. The old crate that was left undamaged out in the battle could just remain in the battle indefinitely or delete on a timer.

Edited by A-SUICIDAL

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  

×