Adding a custom menu for tools/items

J3T

Valued Member!
Hey there, can someone lend me in the right direction or give me a tutorial how to add functions for specific items in the players inventory? I guess it is something in the clientfiles, but im not 100% sure.

thanks J3T
 
How do you want the actual implementation of the menu to be? If you want something like how you can right click on the hatchet in the players tool belt and have a context menu come up with "Chop Wood" in it then I'd really like to know the server-side mod only answer as well. :)

One way you can do this now is the same as many of the mods posted already... when the action menu appears (scroll your mouse wheel - action menu comes up on the left) check the players inventory for a specific item. If it is there, add some action to the menu. This is done by adding an "addAction" call within fn_selfActions.sqf. For example...

Code:
_hasItem = "ItemIdHere" in magazines player;
if (_hasItem) then {
    s_player_some_action = player addAction[("Some Action"), "path\to\action_script.sqf", ["args","to","pass","to","action","script"], 0, false, true, "", ""];
} else {
    player removeAction s_player_some_action;
    s_player_some_action = -1;
};

It is also a very good idea to put the remove action code somewhere (usually near the beginning) in your action script so that the menu item is removed from the action menu as soon as the action / animation starts. Meaning...

Code:
// top of action_script.sqf
private ["_foo"];
_foo = "bar"
player removeAction s_player_some_action;
s_player_some_action = -1;
 
// logic that performs the action you want done.

For a real example of what I am talking about, check out Krixes's self blood bag mod. It is one of the more clean and well commented mods on the site that I've seen yet.

Hope this helps...

Edit: Forgot a closing parenthesis in one of my code examples.
 
Yeah i Know how to implement it on the scroll wheel. I need it like the hatchet. But it doesn't matter for me whether it's client-side or server-side

Cheers J3T
 
The ItemAction is defined in the CfgMagazines, which I believe cannot be overwritten.

I'm unaware of any other way to add it. Out of interest here is the code for a Tent.

Code:
        class ItemActions {
            class Pitch {
                text = $STR_PITCH_TENT;
                script = "spawn player_tentPitch;";
 
Is there a way to add a function to the scroll wheel that allows you to switch weapons in your backpack without having to open your gear and backpack and doing it that way?
 
Is there a way to add a function to the scroll wheel that allows you to switch weapons in your backpack without having to open your gear and backpack and doing it that way?


Yeah, that should be pretty easy. Just get the class id of the current weapon, get the class id of the weapon in the backpack, then remove the primary, remove the one the one the backpack, add the id from the backpack to the primary, and then add the one from the primary to the backpack.
 
Yeah, that should be pretty easy. Just get the class id of the current weapon, get the class id of the weapon in the backpack, then remove the primary, remove the one the one the backpack, add the id from the backpack to the primary, and then add the one from the primary to the backpack.

What would the script be? I don't have experience writing them. :/
 
Not really. Its good advice. You could at least try to do something to give back to the community instead of just coming on here and begging for scripts. That, in my opinion, is lame.

Alright well I've got a script working, however, I have 2 problems. First, this is the line telling it that if I have an M40A3 blah blah blah

Code:
if (("M40A3" in weapons player)) then {

Obviously this means that anybody who gets an M40A3 will get the weapon change option and get another weapon for free so how can I tell it to not only check if it has that one weapon in my hands, but the other weapon that I'm switching to is in my backpack? Second, I can remove one gun from my hands and change it to the other, but what's the command to put the original gun in my backpack?
 
Alright well I've got a script working, however, I have 2 problems. First, this is the line telling it that if I have an M40A3 blah blah blah

Code:
if (("M40A3" in weapons player)) then {

Obviously this means that anybody who gets an M40A3 will get the weapon change option and get another weapon for free so how can I tell it to not only check if it has that one weapon in my hands, but the other weapon that I'm switching to is in my backpack? Second, I can remove one gun from my hands and change it to the other, but what's the command to put the original gun in my backpack?

(configFile >> 'cfgWeapons' >> (currentWeapon player)) I think

Edit: This will read for pistols / others weapons as well, not just primary weapons like the DMR
 
Guess you should learn then.

I see where you are coming from, but you could have given him an example (even if it is incorrect) to get him started, the first script I ever wrote was a modification of player 2's custom spawn and it's only because she was patient and got me started that I ever finished it. Sometimes people need more of a push than just "do it yourself"

Wow that was kinda cruel.

It may have been harsh, but he does have a point.
 
(configFile >> 'cfgWeapons' >> (currentWeapon player)) I think

Edit: This will read for pistols / others weapons as well, not just primary weapons like the DMR

Doesn't that just check in the current weapons, not what's in the backpack?
 
Doesn't that just check in the current weapons, not what's in the backpack?

I was giving you the code for whats in your hands, I honestly have no idea if you can read the inventory of a backpack. I'll try to see if I can't find something to help you out.
 
Still can't get anything to work for the backpack. I've tried addWeaponCargo, addWeaponCargoGlobal, and clearWeaponCargo and none of them do anything. Any ideas?
 
Still can't get anything to work for the backpack. I've tried addWeaponCargo, addWeaponCargoGlobal, and clearWeaponCargo and none of them do anything. Any ideas?

idk try cfgBackpack or something. No clue man. I've already exhausted my minute cache of information
 
Back
Top