Jump to content
Fr3eMan

Link object to inventory

Recommended Posts

Good day all!

I have a question, there is the way to attach/link by script to the inventory (uniform/vest/backpack) an object as the mobile cellphone of the editor?

  • Like 1

Share this post


Link to post
Share on other sites

Short answer, no not without making an addon to make it into a inventory item.

  • Sad 1

Share this post


Link to post
Share on other sites
5 hours ago, Fr3eMan said:

Good day all!

I have a question, there is the way to attach/link by script to the inventory (uniform/vest/backpack) an object as the mobile cellphone of the editor?

 

I don't know what you're trying to do, but:

- inventory are just classes and pictures displayed and managed by user interface.

- if you name an object like your phone, say myPhone, this object (weaponHolder in fact) becomes null when you place it in inventory.

   i.e. before you grab it:   cursorObject returns myPhone, getMagazineCargo cursorObject returns : [["MobilePhone"],[1]]

         after, once in inventory (closed),   myPhone is null (the weaponHolder is deleted), so isNull myPhone is true

 

Now, if you want to know if a player has taken this phone (so named myPhone), you can script something like:

player addEventHandler ["Take", { params ["_unit", "_container", "_item"];  if (_container == myPhone) then {hint "you have the right cell phone"}];

in initPlayerLocal.sqf for example.   (player must be played at this time)

Then, you can add a variable to this player, do what you want...

 

Now, the problem is you can't make a difference between 2 or more cell phones once in inventory (it's just a count as for any magazine, for the same class of object).

So, if there is just one cell phone like this in game, you can detect when the player has no more cell phone in his inventory. Easy (see the second code below, you can simplify).

But, if you have several phones that can be taken in game, you could count them and decide something like this:
 

player addEventHandler ["take", {
  params ["_unit", "_container", "_item"];
  if (_container == phone) then {
    hint "you have the cell phone";
    _unit setVariable ["nbrOfCells",{_x == "mobilePhone"} count Magazines _unit];
  }
}];

so the count is set with the number of cells in inventory when you picked the good one. You can continue to pick extra cells that doesn't matter.

 

Then, when you remove them from inventory:

player addEventHandler ["put", {
  params ["_unit", "_container", "_item"];
  if (_item == "mobilePhone") then {
    if ((_unit getVariable ["nbrOfCells",-1]) > {_x == "mobilePhone"} count Magazines _unit) then {
      hint "you let the cell phone"
    }
  }
}];

Of course, it's a workaround. You can't say that you put the "right phone" on the ground, you just played with a number of magazine!, but it's probably enough for gaming.

Unfortunately, you can't renew this code as myPhone definitely stays null... and it's an harder work to give a name a specific cell phone on ground in this case.

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Sorry I misunderstood the question and also didn't realise there was a mobile phone inventory item. When did that get added? with Old Man?

  • Like 1

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

×