Home   Help Search Login Register  

Author Topic: Ammo box generates mags when one is present?  (Read 4982 times)

0 Members and 1 Guest are viewing this topic.

Offline danturn

  • Members
  • *
Ammo box generates mags when one is present?
« on: 27 May 2009, 10:45:41 »
Basically, what I want is to essentially make a factory out of an ammo box. When an Item such as a magazine is present in the ammo box it will generate more of these magazines at a rate of say, one every 2 minutes. I understand the ammo box will need a name say "factory_1" and a script to run. So in it's init field would it be
Code: [Select]
this exec "factory.sqf" so that the script will run consatantly?

then

Code: [Select]
if "magname" true then addmagazinecargo ["magname",1]....
and im kinda lost there on how to set it to a time limit, that's if that bit of code is right anyway.

Any ideas?
Cheers.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Ammo box generates mags when one is present?
« Reply #1 on: 27 May 2009, 12:16:15 »
Hi,

Can't be done, sadly. There is no way to check the magazine/weapon content of a container (such as a vehicle or an ammo box). :( Hopefully something that is rectified in ArmA II!

Anyway, you could make it work through some more magic scripting that still adds the ammo to an ammo box, but this all depends on what you want it for - e.g., how universal, complicated, MP-compliant etc. do you want it to be?

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re: Ammo box generates mags when one is present?
« Reply #2 on: 27 May 2009, 15:05:21 »
Wolfrug is probably right, it can't be done ... that way!

The way to do this would be to create a new action for the ammo box using addAction. The action removes something from the players inventory then adds it to the ammo box. You then make it add the same type of item every x seconds to the box. This won't allow you to check the amount of items remaining though.
Get those missions out there you morons!

Offline danturn

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #3 on: 27 May 2009, 17:33:06 »
ahh, :(. Is it possible to just do a script where something is added to the crate every (x) minutes then regardless of it's presence in the crate?

I no that I can create triggers and actions to add weapon or magazine cargo to a crate, just not sure how I add the time function into it.

Last time I had a man walking between two points which would take him a certain amount of time, but obviously if he dies, then it's no longer generating any income so to speak.

cheers

Offline Rommel92

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #4 on: 27 May 2009, 23:43:35 »
ahh, :(. Is it possible to just do a script where something is added to the crate every (x) minutes then regardless of it's presence in the crate?

Code: (in a trigger) [Select]
nil = [] spawn {waituntil{<YOUR_MAG> addmagazinecargo <BOX_NAME> ; sleep <DELAY>; <END_CONDITION>}}
« Last Edit: 28 May 2009, 06:12:14 by h- »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Ammo box generates mags when one is present?
« Reply #5 on: 28 May 2009, 03:37:27 »
Hint: never assign a value to nil!
try { return true; } finally { return false; }

Offline Denisko-Redisko

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #6 on: 28 May 2009, 07:36:57 »
There is the workaround obtain content of a ammobox  (in general, any object with the TransportMagazines and TransportWeapons subclasses). But it only works in campaign mode. Basically you can use it in single missions just packed them in a campaign, but you can not use it for multiplayer. Here is a snippet of code which implements this feature:
Code: [Select]
//
// Recomment that (two lines) for use in your project
// #define funcPrefix YOUR_PROJECT_FUNC_PREFIX
#define funcPrefix func
#define func(name) funcPrefix##name
#define arg(X)            (_this select (X))

func(UploadCargoToPool) = {
    deleteStatus "UploadCargoToPool::temp";
    _this saveStatus "UploadCargoToPool::temp";
    if( _this isKindOf "WeaponHolder" )then{
        _this = typeOf _this createVehicleLocal [0,0,100];
        _this loadStatus "UploadCargoToPool::temp";
        pickWeaponPool _this;
        deleteVehicle _this;
    }else{
        pickWeaponPool _this;
        _this loadStatus "UploadCargoToPool::temp";
    };
    deleteStatus "UploadCargoToPool::temp"
};

func(QueryCargoPool) = {
    private ["_cfg", "_count", "_item", "_list", "_query", "_tmp"];
    _cfg = configFile >> arg(1);
    _query = arg(2);
    arg(0) call func(UploadCargoToPool);
    _list = [];
    for "_i" from 0 to count _cfg - 1 do {
        _item = _cfg select _i;
        if( isClass _item )then{
            _count = configName _item call _query;
            if( _count != 0 )then{
                _list set [count _list, [configName _item, _count]]
            }
        }
    };
    _list
};

func(GetWeaponCargo) = {
    clearWeaponPool;
    [_this, "CfgWeapons", { queryWeaponPool _this }] call func(QueryCargoPool)
};

func(GetMagazineCargo) = {
    clearMagazinePool;
    [_this, "CfgMagazines", { queryMagazinePool _this }] call func(QueryCargoPool)
};

func(QueryWeaponCargo) = {
    clearWeaponPool;
    arg(0) call func(UploadCargoToPool);
    queryWeaponPool arg(1)
};

func(QueryMagazineCargo) = {
    clearMagazinePool;
    arg(0) call func(UploadCargoToPool);
    queryMagazinePool arg(1)
};
In the attache - an example of the campaign to test these functions.
« Last Edit: 28 May 2009, 10:44:25 by Denisko-Redisko »
sorry for my english

Offline Rommel92

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #7 on: 28 May 2009, 08:58:23 »
Hint: never assign a value to nil!

yeah my bad, I've written this a few times, but I only do this when testing in the editor. Bad practice I know.  :confused:

Offline Denisko-Redisko

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #8 on: 28 May 2009, 11:05:44 »
Yes, the initialization field in editor, don't like when the expression returns anything. I'm using in these cases the following trick:
call { this spawn { anycode } }
;)
sorry for my english

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Ammo box generates mags when one is present?
« Reply #9 on: 28 May 2009, 11:12:54 »
The real problem is that he's assigning a script handle to nil that way. The next time he tries to set a variable to nil it will be assigned the damn handle... ;)
try { return true; } finally { return false; }

Offline danturn

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #10 on: 28 May 2009, 11:44:45 »
Code: [Select]
nil = [] spawn {waituntil{<YOUR_MAG> addmagazinecargo <BOX_NAME> ; sleep <DELAY>; <END_CONDITION>}}
Soo, If your not supposed to use nil, then what do I use instead  ???. I am assuming I am supposed to write my time value in Delay?

Any chance of a bit of explaining on what each part of the trigger does? thanks

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Ammo box generates mags when one is present?
« Reply #11 on: 28 May 2009, 12:32:31 »
Either use Denisko's suggestion or a global variable that does not interfere with any command ("dummy" is a good one).
try { return true; } finally { return false; }

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Ammo box generates mags when one is present?
« Reply #12 on: 29 May 2009, 00:01:44 »
If it is single-player, then you might as well just generate one every 10 minutes. But then, I don't see that as terribly useful unless you have respawning in MP. The issue with doing this in MP is that you make one per player, not one per box (without a lot of messing about).

I think I implemented this once by placing the weapon/magazines on top of the box (create a weaponHolder then add the weapon to it). That way, I could test whether there was a weaponHolder at a precise position to see if the original items had been picked up. Someone can come along and just pick up and then drop the weapon, to allow it to respawn, but that is going to be an issue in any case (and not one I'd worry too much about).

But regardless, hoping that Arma2 will save us from this frustration ;)
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Rommel92

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #13 on: 29 May 2009, 08:37:10 »
Incase your still confused, that means:
Code: [Select]
dummyHandle = [] spawn {waituntil{<YOUR_MAG> addmagazinecargo <BOX_NAME> ; sleep <DELAY>; <END_CONDITION>}}

Example:
Code: [Select]
dummyHandle = [] spawn {waituntil{"Strela" addmagazinecargo AMMOBOX1 ; sleep 1; not (alive AMMOBOX1)}}

Offline danturn

  • Members
  • *
Re: Ammo box generates mags when one is present?
« Reply #14 on: 29 May 2009, 19:18:25 »
Thanks rommel, so, in affect, will that just generate the sterla mag every 1 minute regardless of it's presence in the ammo box?

I feel really thick at the moment haha.

thanks