Jump to content
Sign in to follow this  
wilf55

MP - Filling Ammobox on demand

Recommended Posts

So I've searched the forums and Google, and I haven't come up with anything specific to the issue...

What I'm trying to do is edit a multiplayer mission that has a number of ammoboxes located around the map, I'm attempting to not have the ammoboxes refill themselves on a timer - and have the script constantly running on the server, rather I'd prefer to have the script only run when required. The ammoboxes are initially spawned with an action in their init field:

null0 = this execVM "Path\fob_ammobox_wilf.sqf";

This file contains the following:

clearweaponcargo _this;
clearmagazinecargo _this;
_this addWeaponCargo ["M16A2",5];
_this addWeaponCargo ["SCAR_H_STD_EGLM_Spect",5];

...blah blah blah blah...

All works fine up until this point. This does the initial stocking of the ammobox just fine (as expected).

I put another item in the init line of the ammobox:

this addAction ["Restock", "Path\fob_ammobox_wilf.sqf"];

This doesn't work. I've done a bit of digging and am fairly sure it's related to the '_this' calling in the .sqf file. Using the execVM seems to parse the id of the ammobox over, but using the addaction stuff doesn't.

I'm aware that I can overcome this by having the script running all the time, and sleeping then refilling the box - I would really prefer not to do it like this if it is at all possible (which it seems like it should be).

Any help will be welcomed!

---------- Post added at 11:03 AM ---------- Previous post was at 10:50 AM ----------

Well... seems as though some more searching has solved the issue - but I'd still like to hear from anyone that has a more elegant solution.

The init like of the ammobox contains the normal fill request from a script, but the addaction calls a slightly different script.

null0 = this execVM "Path\fob_ammobox_wilf.sqf";
this addAction ["Restock", "Path\fob_ammobox_wilf2.sqf"];
this allowDamage false; 

The original script is as posted above, but the #2 script looks like this:

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

clearweaponcargo _ammob;
clearmagazinecargo _ammob;

_ammob addWeaponCargo ["M16A2",51];

Seems to work in my testing so far, but as I said - let me know if you have any other solutions.

Share this post


Link to post
Share on other sites

This is just a quick reply:

In the first instance your .sqf file is referencing the ammo box, in the second instance the .sqf is likely reference your player (or nothing) as that is the object the addAction is attached to.

What you want to do is add the ammobox object as a parameter to the addAction then it should work as is.

Share this post


Link to post
Share on other sites

Wilf, the method you have used correct. I shall give you my basic understanding:

When you add the following code to an init line:

this addAction ["Restock", "Path\fob_ammobox_wilf.sqf"];

The game sends two variables to the script contained in the array:

_this = [ object , player ]

You have to designate which items are which and assign a name to them:

_this select 0 = object      <- Object that the action is attached to.
_this select 1 = player      <- Player that activated the action

So essentially you just needed to specifically add the gear to the weaponcrate instead of the array containing the weapon crate and the player. Also, you may want to investigate the differences between the following commands:

addWeaponCargo

addWeaponCargoGlobal

addWeaponCargoLocal

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  

×