Home   Help Search Login Register  


Author Topic: RUG Inventory for Arma 2  (Read 4516 times)

0 Members and 1 Guest are viewing this topic.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
RUG Inventory for Arma 2
« on: 13 Dec 2010, 23:15:48 »
RUG Inventory v.0.7
now converted for Arma 2 from ArmA  :clap:

This script-suite allows you to add a vehicle-variable driven and very customizable RPG-like inventory system to your missions. Create your own items and inventories, and then freely move items from one inventory to the other - even allowing dropping it on the ground! Currently in BETA for testing. Not tested in MP, no support as of now.

Use: Try the test mission and read some of the comments on some of the scripts and functions to get a deeper understanding as to how things work. Currently does not contain all planned features, but that shouldn't limit the usability as of now. Important when porting to your own mission is to copy the custom dialog (RUG_Controls.h and RUG_Inventory.h) as well as the #includes in the description.ext to your own description.ext. Do not move any of the scripts that are inside the RUG_Inventory folder anywhere else, and keep the RUG_Inventory folder in the main folder of your mission (I.e. MissionName\RUG_Inventory).

How to create your own items : see the description in the test mission's comments (specifically Template_Items.sqf).

How to create your own inventories : see the description in the test mission's comments, the init.sqf, and RUG_Inventory.sqf

How to easily add, remove and transfer items: use RUG_EasyAdd, RUG_EasyRemove and RUG_EasyTransfer. See their script headings for usage!

Advanced use : Use your imagination, and check out the test mission for some ideas.

Future implementation:
- Possible smarter use of the "leave on ground" inventory, currently leaves a permanent inventory on the ground + weaponholder if any item is ever dropped on the ground.
- Integrated shopping system. [DONE]
- Better-looking dialog. [Partly done]
- Better support and implementation of the default "use" action. [DONE]
- More example missions to showcase the scripts.
- More functions for more in-depth item/inventory-manipulation. [DONE]
- MP-testing if possible
- SP-campaign compatibility testing.
- Proper commenting of scripts!! [Mostly done]

Known issues:
- Dropping items onto the ground will really drop them into the inventory of a weaponholder. This weaponholder will disappear if you use the "gear" action on it.
- Shortly after an entity dies, they will become non-entities for the Arma 2 engine, meaning their bodies can no longer be looted or interacted with. The only solution to this that I can imagine would be to make their "loot" actions actually refer to another unit somewhere else (e.g. a game logic). They can, however, be looted for a few moments after death.
- Not MP compatible AFAIK, but it's all based on vehicle variables and global vars, so there's nothing stopping you from making it as MP'riffic as you want.
- Barter system does not take into account capitalism, inflation or anything else. Value remains constant, whether buying or selling.
- Holstering allows for the infamous big weapon + launcher 'exploit' (e.g. machinegun and M136). Do not consider serious enough to fix.
- No support for OA backpacks at the moment. Confusion reigns when wearing both a launcher and a backpack.

Version history:

v.0.7 BETA
- Added RUG_EasyCheck, for simple checking whether an inventory contains x amounts of whatever item (returns true/false). Should now be possible to do just about anything without actually using any other commands than the four "Easy" ones.
- Fixed it up for Arma 2 release, should work fine now :) Arma 2 example mission has some stuff in it to give people an idea of how it all works.
- Added a 'Your items' bag for Arma 2, which contains all the items you are carrying (map, compass etc). Also removed the RUG Inventory ones since they're obsolete. Arma 2 items can be added and edited to the scripts inside the itemControl.sqf under RUG_Inventory\ItemActions.
- Minor improvements to gunControl.sqf and RUG_Inventory.sqf (now crouches when opening an 'empty' inventory).
- Changed the font ;)
- Fixed many instances of overriding nil. My bad!

v.0.6 BETA
- Improved RUG_EasyAdd and RUG_EasyTransfer by adding an optional true/false switch for checking if there is space: they now output false and do not move any items if check is set to true and there is not enough size to add/transfer the items
- Added new function, RUG_Inventory_InitVehicleVars, which inits the necessary vehicle variables (RUG_Inventory_Size and RUG_Inventory_Name) independently of the RUG_Inventory.sqf script where they used to be initialized.
- Removed some more nil= appearances from some of the template items. Oops
- Added a "RUG_Inventory_Core.Intro" map to the package -> only contains the scripts and init files, and has properly named and ordered template items so as to avoid the clutter of the other test mission. For advanced users (um, that's me, I guess).
- Added some comments to the HireMan.sqf and BuyVehicle.sqf scripts -> note to users, there are many MUCH better ways of doing this, but since the scripts are there...

v.0.5 BETA
- Added RUG_EasyAdd, RUG_EasyRemove and RUG_EasyTransfer functions: allows for simplified item adding/removing/transfering of items. Also added custom resources and a sound to notify of items being added/removed using these commands. Instructions for use in their headers
- Moved the bulk of the global variable initialization to RUG_Inventory_Init.sqf which should now be run to init the inventory system.
- Slight changes in RUG_Inventory.h (moved some controls around a little - the general text area should have some more space now)
- Added a text to the ammo bag inventory screen instead of the standard one.
- Made all executions of RUG_Inventory.sqf and RUG_Inventory_Trade.sqf within the scripts use spawn instead of execvm.
- Added more comments to various scripts and added some more instructions to the in-game items.
- None of the scripts that require the string name of the item are case sensitive any longer.
- Added RUG_Inventory_Monitor.sqf script which simply checks for certain items that need to immediately affect a unit when they are added/removed. Currently used to switch the map/compass etc. on and off.
- Removed the nil = in front of a bunch of scripts. Oops for redefining engine commands!
- Fixed a problem by which the Your ammo inventory could be filled with size 0 items which would then be lost. Now you cannot put any items of any size inside an inventory with a size of 0.
- Minor fixes in various scripts etc.
- Changed the look of the inventory screen slightly - old look is available in ORIGINALRUG_Inventory.h if you want to revert to it :) New look has more space for general messages and slightly more space for descriptions, as well as a slightly larger picture.
- Added green (positive balance) and red (negative balance) text to the Balance number when trading

v.0.4 BETA
- Added examples for how to purchase stuff such as soldiers and vehicles
- Added a working system for transfering magazines between gear and inventory
- Fixed some minor issues with some of the existing items

v.0.3 BETA
- Added MANY new items + pictures, showcasing the various uses of the inventory system
- Spiffed up the dialog again slightly by adding item pictures
- Changes to Take/Drop/Use default actions : placing a code within the [{}] of the spawn will make that code launch if the action is successfully completed (take/drop/use). The code will have the following parameters : _this select 0 = _curValue (amount dropped/taken/used), _curSel (item dropped/taken/used), _i (number that indicates how many times the scripts have run - they will run once for every case of _curvalue. Useful for limiting the script running to just one for instance).
- Added integrated gear-menu functionality - simply press "G" while in inventory mode to access the gear menu of the object (if applicable), and then close the gear menu to return to the inventory. Still researching possibility of doing this in a reverse order.
- Added functionality to transfer all types of guns (main, secondary and pistols) from inventory to gear (via a special item). Also left some guns in the ammo box to showcase this.
- Added comments here and there

V.0.2 BETA
- Added a working trading system, invoked simply by changing the action to "RUG_Inventory_Trade.sqf".
- Changes to the way items are created due to the trading system - now requires a third element in the 9th entry : value
- Small changes to all scripts to accomodate for the trading system.
- Slight visual overhaul of the inventory screen - still pending further improvements.
- Added new function : RUG_Inventory_ftotalvalue : returns total value of inventory
- Added new scripts : RUG_Inventory_Trade.sqf and RUG_Inventory_TradeCheck.sqf
- Added ability to flag items undroppable/takeable/sellable/buyable (with default scripts).

v0.1 BETA
- Initial release

« Last Edit: 17 Dec 2010, 09:38:46 by Wolfrug »
"When 900 years YOU reach, look as good you will not!"

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: RUG Inventory for Arma 2
« Reply #1 on: 16 Dec 2010, 19:17:24 »
really glad to see this making it back. :)

just tested.. something about a NIL being overridden?

Code: [Select]
11:19:43 WARNING: NIL VARIABLE OVERRIDEN; Please fix Mission or loaded addon-scripts
11:19:44 Error in expression <e = _values select _i;
11:19:44 call _code;
11:19:44 };
11:19:44 nil;
11:19:44 >
11:19:44   Error position: <nil;
11:19:44 >
11:19:44   Error Undefined variable in expression: nil
11:19:44 File x\cba\addons\hashes\fnc_hashEachPair.sqf, line 27
11:20:18 Error in expression <e = _values select _i;
11:20:18 call _code;
11:20:18 };
11:20:18 nil;
11:20:18 >
11:20:18   Error position: <nil;
11:20:18 >
11:20:18   Error Undefined variable in expression: nil
11:20:18 File x\cba\addons\hashes\fnc_hashEachPair.sqf, line 27

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: RUG Inventory for Arma 2
« Reply #2 on: 17 Dec 2010, 00:19:29 »
Thanks loki! Crap, ages since I looked over these scripts, lots of old nil='s left in there. Now I'm ashamed.  :-[ Anyway, I fixed most of them as far as I can tell, and reuploaded the mission. Please let me know if it persists. My bad!

Same goes for all the other...two..people who downloaded it: please do redownload :)

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

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: RUG Inventory for Arma 2
« Reply #3 on: 17 Dec 2010, 02:49:59 »
not to worry..

but you did miss a couple.. :P

Line 168: nil = [_InventoryObject,_owner, 0, [_InventoryObject,_owner]] spawn RUG_Inventory_MainWindow;

Line 106: nil = [RUG_Inventory_Target, RUG_Inventory_Caller, 0, [RUG_Inventory_Target, RUG_Inventory_Caller]] spawn RUG_Inventory_TradeWindow;

i changed them to yo = blah.. and all is well in RUG_land


i think arma has finally come along enough to make small scale rpg's now..

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: RUG Inventory for Arma 2
« Reply #4 on: 17 Dec 2010, 07:25:16 »
Just a quick question:
Why are you using such a way to execute scripts within a script?  ???

You only need to use the "handler method" when executing scripts in the global scope (waypoints, triggers, etc.) and even then you can use a local variable, inside scripts you can just type [RUG_Inventory_Target, RUG_Inventory_Caller, 0, [RUG_Inventory_Target, RUG_Inventory_Caller]] spawn RUG_Inventory_TradeWindow;..
« Last Edit: 17 Dec 2010, 07:26:50 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
Chuck Norris can divide by zero.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: RUG Inventory for Arma 2
« Reply #5 on: 17 Dec 2010, 09:44:40 »
Thanks again loki  :-[ I did it quickly last night and must've been half-asleep. Fixed those two as well and uploaded it AGAIN. Hopefully it won't do it any longer now. Siigh.

@ h-: As to why I used that...search me ;) I made these scripts back in 2008 or something for ArmA and I wasn't terribly good at this whole scripting bit then. I could probably improve them a hundredfold if I did them today, but they work, so hey...if it ain't broke, don't fix it. I know I don't have to use a handle inside scripts, unless I want to do something with that handle. So yeah, I...really don't know.


Thanks for making me aware of these, loki - let me know if you find anything else! And if you want to design something with these scripts, all you really need are the four Easy commands + the knowledge of how to create items (which is explained in Template_Items.sqf). I'll be here for all your questions as well, if you're curious. Heck, if you want some functionality it doesn't have yet, I'd be glad to add it!

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

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: RUG Inventory for Arma 2
« Reply #6 on: 17 Dec 2010, 19:59:24 »
right on!.. glad you're motivated to work with this.  :clap:

did find 1 more error though..

Code: [Select]
Error in expression <_this execVM"RUG_Inventory\RUG_Inventory>
  Error position: <_this execVM"RUG_Inventory\RUG_Inventory>
  Error Type Script, expected Bool

in RUG_Inentory_Filler.sqf

line 38

Code: [Select]
if (!_trade) then {(_parentDisplay) displaySetEventHandler ["KeyDown", "_this execVM""RUG_Inventory\RUG_Inventory_GearCheck.sqf"""]} else {(_parentDisplay) displaySetEventHandler ["KeyDown", ""]};
i do have some ideas for this.. i'll get them organized and send them to ya.

i really hope you don't mind me going over this with a fine tooth comb. :)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: RUG Inventory for Arma 2
« Reply #7 on: 18 Dec 2010, 20:01:44 »
No, that's fine :) Don't expect any scripting beauty though, this suite is already a cranky old machine. But, as mentioned: it works!

I'm guessing that error is in the arma.rpt, right? Might have something to do with changes they've made to the displayseteventhandler command, I can check it out, but I don't consider it high priority since the function still works (opens gear window when pressing G when the inventory window is open).

Please, gimme all your ideas! I'll be glad to tinker with them. Note though that over X-mas and maybe New Years I'll probably not be within range of a Arma 2-worthy computer, so... :)

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

Offline MWPA

  • Members
  • *
This question is mainly for Wolfrug.

I'm using RUG_Inventory as a primary means of purchasing support assets.  I have the COIN module set up with various vehicles and fortifications (etc.) available at certain locations.  I have a loop that will easyAdd RUG_money periodically to the player's inventory based on how many trigger areas he controls.  Rather than add another loop that does the same with COIN funds, I'd like to have an item available that converts set amounts of RUG_money into COIN funds instead.  I figure four items would do it: one for 100, 500, 1000, and 10000 and give each vendor enough of the items to cover a few hours of gaming.  This is where I'm stumped.  I'm not sure what (or how) to get or set with the getVariable and setVariable commands.

I'm using the generic COIN module name: BIS_coin_0 and I haven't changed any variable names.  The amount of funds is changed by:
 _this setVariable ["BIS-COIN_funds", "number"]
I can't seem to getVariable the amount of funds to add the converted funds to.  After adding the two amounts, using the setVariable command seems easy.  I just can't reach that point in the script.

This is more of a problem for me with COIN than RUG_Inventory.  The inventory scripts have been very easy to work with. 

I appreciate your help,

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer

Sorry for the delay in responding, I've been hella busy. Also I didn't want to respond before I had a chance to figure out of the CoIn system works, which I've now after a bit of testing in the editor found out.

So, basically, getvariable and setvariable both work fine - the hitch here is that it's for some truly odd reason based on STRINGS rather than numbers - so to add, say, $100 using these commands, you would have to do this:

Code: [Select]
_oldvalue = BIS_coin_0 getvariable "BIS_COIN_funds";
_scalar = call compile (_oldvalue select 0);
_newvalue = _scalar + 100;
_newvaluestring = str (_newvalue);
BIS_coin_0 setvariable ["BIS_COIN_funds", _newvaluestring];

Which is, quite frankly, ridiculous! Strange are indeed the ways of the BIS...

But, as it were, you could use the script above to create a custom item Use code which would run the above script, and add (as you say) 100, 500, 1000 etc. COIN money on use, and simply make the item cost 100, 500 etc. in "RUG Money" when bought from vendors - as you had planned.

The alternative, to add a constant monitoring script, is indeed a lot of work, especially as I'm not sure how often you would need to keep RUG money & COIN money synchronized (whenever you earn more COIN money, whenever you build or sell something, etc). Also keeping in mind you might be able to e.g. earn COIN money while you have your inventory open, which might accidentally delete the earned money (especially if it's open in the trade screen). If you can't earn COIN money separate from RUG Money, however, then creating a monitor script might be possible, if you want a direct 1-1 transfer of RUG money to COIN; what we'd have to figure out is the display name of the CoIn interface, and create a custom eventhandler than checks for it opening and closing, and then whenever this happens add/subtract COIN money based on currently carried RUG money (and when closing subtract the COIN money that was used from RUG money). It's a bit of work, but I don't think it's impossible.

Glad you're enjoying my scripts, and do ask if there's anything else that comes up!

Wolfrug out.

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