Jump to content
Sign in to follow this  
donalexander

How do I make a barrel into a weapon crate

Recommended Posts

Can someone please help me to make a barrel contain an ACE2 jerrycan so I can add it to my mission, I would like to be able to walk up to and and press GEAR to get a jerrycan out of a barrel to refuel vehicles in my mission.

Share this post


Link to post
Share on other sites

Use ACE? :)

Actually, if you have ACE just make a script that checks if they have a launcher already, then gives them a jerrycan. Seems the jerrycan just "works" once you have it.

Edited by kylania

Share this post


Link to post
Share on other sites

Well, making a invisable weapon holder in order to make a real gear menu might be a little to complicated i'll go with addaction and adding the jerrycan to the player.

put that in the init of the barrel

this setVariable ["ammount",2]; //change the ammount to the number of jerrycans you want
nul = this addAction ["Take Jerrycan", "jerrycan.sqf",[],0,false];

now make a jerrycan.sqf file and put this in.

private ["_caller","_type","_barrel","_ammount","_backpack"];
_barrel = _this select 0;
_caller  = _this select 1;

_ammount = _barrel getVariable "ammount"; //How many jerrucans are there
if (_ammount>0) then
 {
   _backpack = [_caller] call ACE_fnc_FindRuck;
   if (_caller hasWeapon _backpack ) then {_caller removeWeapon _backpack }; //Get rid of                               backpack if he has one
   sleep 0.3; 
   _caller addWeapon "ACE_JerryCan_Dummy_15"; //Add the Jerrycan
   _ammount = _ammount - 1;
   this setVariable ["ammount",_ammount ];
 } else 
   {
    hint "There are no more jerrycans in the barrel";
   }; 

You can limit the amount of jerrycan you want to give to the players by using a global variable and some if inside.

Edited by shay_gman

Share this post


Link to post
Share on other sites

Thank you gman it worked perfectly I just had to change the barrel init to nul = this addAction ["Take Jerrycan", "jerrycan.sqf",[],0,false]; it didnt work the other way.

---------- Post added at 10:03 PM ---------- Previous post was at 09:18 PM ----------

Just wondering how to put in a global variable? or how can I make it so there is just one or two jerrycans in there?

Share this post


Link to post
Share on other sites

private ["_caller","_type","_barrel","_dummyTarget","_backpack", "_limit", "_avail"];
_barrel = _this select 0;
_caller  = _this select 1;

_limit = 2; //Max number of jerrycans available
_avail = _barrel getVariable ["TAG_jerrycans_available", _limit]; //Retrieve the current number of jerrycans available, if none were taken the variable does not exist, default to the limit
if (_avail > 0) then //Some are available
{
  _backpack = [_caller] call ACE_fnc_FindRuck;
  if (_caller hasWeapon _backpack) then
  {
      hint "You must drop your backpack first!";
  }
  else
  {
     _barrel setVariable ["TAG_jerrycans_available", _avail - 1, true]; //Save the number of jerrycans available now
     _caller addWeapon "ACE_JerryCan_Dummy_15"; //Add the Jerrycan
  };
}
else
{
  hint "No more jerrycans available.";
};

The code should be 100% MP safe thanks to the broadcasted setVariable. I also removed the automatic backpack removal. I think it's much better to let the player do it himself so he doesn't wonder where it's gone.

Edited by Deadfast

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  

×