Jump to content
Sign in to follow this  
alleycat

Are there event handles for inventories?

Recommended Posts

While trying to create my own ghetto water drinking items I have encountered a problem:

If I want to have an addaction for a player to use if he has a specific item in inventory how do I do that in an efficient way? I know how to check the player inventory for items, however hammering the game with a looping script seems not a good idea. Is there some event handler that detects whenever the player inventory is changed?

Share this post


Link to post
Share on other sites

You say "hammering" and I know what you mean, but you should do a while loop or wait until combined with the weapons command. While can be combined with a sleep to make the loop give up CPU time to other scripts and the game engine.

Here's a lit of the eventhandlers available to the vanilla game. As you can see, there's nothing there useful to you.

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers

Share this post


Link to post
Share on other sites

trigger condition

player hasWeapon "EvMap"
//or whatever

Share this post


Link to post
Share on other sites

That is of no use as it repeatedly loops all all the time, which I want to avoid

Share this post


Link to post
Share on other sites

Well I don't believe you can escape any kind of loop. After that, what you can do to limit the amount of checks performed, is wait until the gear menu is opened.

_dspl = findDisplay 106;
While {true} do {
   waitUntil {! isNull _dspl;};
   waitUntil { isNull _dspl;};
   if (player hasweapon ) exitWith {};
};
Stuff to do;

Don't know if it's worth it though. Needs testing.

Edited to maybe less retarded stuff.

Now that I think about it, it's still retarded and is prone to much more fuckups.

Edited by BlackMamb

Share this post


Link to post
Share on other sites

The thing I wonder is how much constantly looping stuff can a client take before it drags down performance.

Share this post


Link to post
Share on other sites
That is of no use as it repeatedly loops all all the time, which I want to avoid

A couple of triggers will not affect your performance at all. They're checked every 0.5 seconds which is by far enough.

A waitUntil is checked every frame and thus also better to use than a while-loop (if no sleep).

I'd say the scripting engine can take a lot more of heat than what you think it can.

The thing I wonder is how much constantly looping stuff can a client take before it drags down performance.

Tons.

Share this post


Link to post
Share on other sites

_dspl = findDisplay 106;
While {true} do {
   waitUntil {! isNull _dspl;};
   waitUntil { isNull _dspl;};
   if (player hasweapon ) exitWith {};
};
Stuff to do;

http://community.bistudio.com/wiki/User_Interface_Event_Handlers

I looked at UI eventhandlers, perhaps they can be used. However when I tried this it would not do anything:

_handleee = (findDisplay 106) displayAddEventHandler ["onLBDrag", "hint 'test'"]; 

Assuming 106 is the inventory screen?

Share this post


Link to post
Share on other sites

When using the event names listed below with the ctrlSetEventHandler command, the prefix "on" in the name is not required and must be removed. (e.g. 'ButtonDown' instead of 'onButtonDown')

So try with:

_handleee = (findDisplay 106) displayAddEventHandler ["LBDrag", "hint 'test'"];

Anyways, loops works just fine and you will never notice them with proper usage.

Share this post


Link to post
Share on other sites
moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "hint str _this;"];

http://community.bistudio.com/wiki/displayAddEventHandler

Put it into the player init field in editor. OBVIOUSLY THAT SHIT WONT WORK. Would be too easy, shit simply working in this game. fuckthis shit, Ill code a loop instead.

Share this post


Link to post
Share on other sites

Look here at some of the inventory functions. They may be of use to you, if you get creative with them.

Share this post


Link to post
Share on other sites

Can you only add the displayAddEventhandler when the dialog is open.

example

this wont work for me

handle = (findDisplay 106) displayAddEventhandler ["MouseButtonDown","hint 'test code';"];

unless it's preceded by waitUntil {!isnull (findDisplay 106)};

After that it works fine.

Share this post


Link to post
Share on other sites

i don't know if i'm missing something here but why do it so complicated?

the addaction command has an array with lots of options. one of them is a condition for the action to be visible. so what i would do is just add the action by default but add the condition of the player having a certain item. i use that a lot in my little mod and it works just fine.

_unit addAction ["drink something", "script_that_removes_item_and_decreases_thirst.sqf", [], 1, false, true, "", """classnameOfdrinkableInventoryObject"" in (magazines _this)"];

"magazines" can be replaced by "weapons" if you want to use stuff that goes in the map/watch/radio/compass slot. the condistion is green. watch the double quotation marks.

Share this post


Link to post
Share on other sites

Yeah, but all those solutions are pretty much the same: that's a loop checking one condition. He wants to avoid that, but really, it's not necessary here, I think.

Share this post


Link to post
Share on other sites
Yeah, but all those solutions are pretty much the same: that's a loop checking one condition. He wants to avoid that, but really, it's not necessary here, I think.

True.

No matter how you turn and twist this in the end a "loop" is done, it's just a matter of appearance!

Share this post


Link to post
Share on other sites
i don't know if i'm missing something here but why do it so complicated?

the addaction command has an array with lots of options. one of them is a condition for the action to be visible. so what i would do is just add the action by default but add the condition of the player having a certain item. i use that a lot in my little mod and it works just fine.

"magazines" can be replaced by "weapons" if you want to use stuff that goes in the map/watch/radio/compass slot. the condistion is green. watch the double quotation marks.

That is an awesome find, saved me probably 2-3 days of hacking something together, thx.

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  

×