Jump to content
hoverguy

[Release] Simple Weapon Shop System

Recommended Posts

hoverguy, thanks.

 

Ok, I'm a tester :)

I added "B_HuntingBackpack" into Items, the shop 'sells' it to me, but I don't see it in my inventory

 

Hmmm.... i have bought a machine-gan, after that - backpack, and the machine gun disappeared :blink: (at the same time - the backpack isn't present)

 

Yeah but it's a weapon shop... I won't add clothing support. Wait for my clothing shop release :)

Share this post


Link to post
Share on other sites

I'm going to try to modify this for my mod, which won't use any of the normal A3 items so I'll be removing them and adding my own.  Is it possible to add the ability to sell items to the shop then other players can buy them from it?

Share this post


Link to post
Share on other sites

I'm going to try to modify this for my mod, which won't use any of the normal A3 items so I'll be removing them and adding my own.  Is it possible to add the ability to sell items to the shop then other players can buy them from it?

Nope, there is no such option.

Share this post


Link to post
Share on other sites

1. Yes you can compile all the fncs, or you can use the CfgFunctions method

2. disableSerialization is needed when you want to store displays/controls in variables

3. You set the variable HG_myCash on player's initialization using setVariable (player setVariable["HG_myCash",15000]), then maybe something like this:

 

[] spawn 
{
    {
        _x addEventHandler 
        [
            "Killed", 
            {
                private["_unit","_killer];
                _unit = _this select 0;
                _killer = _this select 1;
       
                if((isPlayer _killer) AND {_killer != _unit}) then
                {
                    private["_oldCash","_newCash"];
                    _oldCash = _killer getVariable "HG_myCash";
                    _newCash = _oldCash + 200;
                    _killer setVariable ["HG_myCash",_newCash];
                };
           
            }
        ];
    } forEach allUnits;

};

Just to clarify, this eventhandler will apply to any AI that is killed and is not the player?

Will it also work with dynamically spawned units if so?

 

Share this post


Link to post
Share on other sites

Just to clarify, this eventhandler will apply to any AI that is killed and is not the player?

Will it also work with dynamically spawned units if so?

 

 

Basically if the killer is a player & the killed unit is not the killer then the code is fired. So yeah the code is applied to players and AIs.

 

 If you want to add this EVH to dynamically spawned units, just add this in the script where you spawn AIs on the fly:

_unit addEventHandler 
[
    "Killed", 
    {
        params["_unit","_killer];
       
        if((isPlayer _killer) AND {_killer != _unit}) then
        {
            private["_oldCash","_newCash"];
            _oldCash = _killer getVariable "HG_myCash";
            _newCash = _oldCash + 200;
            _killer setVariable ["HG_myCash",_newCash];
        };          
    }
];

If you also want to add it to players, use initPlayerLocal.sqf and set the public param to true on the "HG_myCash" variable.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

 

 

Basically if the killer is a player & the killed unit is not the killer then the code is fired. So yeah the code is applied to players and AIs.

 

 If you want to add this EVH to dynamically spawned units, just add this in the script where you spawn AIs on the fly:

_unit addEventHandler 
[
    "Killed", 
    {
        params["_unit","_killer];
       
        if((isPlayer _killer) AND {_killer != _unit}) then
        {
            private["_oldCash","_newCash"];
            _oldCash = _killer getVariable "HG_myCash";
            _newCash = _oldCash + 200;
            _killer setVariable ["HG_myCash",_newCash];
        };          
    }
];

If you also want to add it to players, use initPlayerLocal.sqf and set the public param to true on the "HG_myCash" variable.

 

I'm using alive and they're kind of sticky on back-engineering and modifying that sort of thing.

Would using a trigger to catch newly spawned AI and running a script from the trigger work or would there be a more efficient way?

Share this post


Link to post
Share on other sites

This weapons shop is great! I am integrating this and your vehicle shop into a version of a certain popular dynamic SP mission, and successfully switched the script to using that missions money system (was fairly easy even for a script noob like me). 

 

Two problems regarding this:

1) Some items are still not handled, binoculars being perhaps the most important ones but also was unable to buy a 9k32 missile for my RHS Igla launcher. 

2) There is conflicts when using both HVSS and HWSS, I had to rename some GUI classes in the HVSS to be able to use both.

 

Looking forward to the clothing shop!

Share this post


Link to post
Share on other sites

This weapons shop is great! I am integrating this and your vehicle shop into a version of a certain popular dynamic SP mission, and successfully switched the script to using that missions money system (was fairly easy even for a script noob like me). 

 

Two problems regarding this:

1) Some items are still not handled, binoculars being perhaps the most important ones but also was unable to buy a 9k32 missile for my RHS Igla launcher. 

2) There is conflicts when using both HVSS and HWSS, I had to rename some GUI classes in the HVSS to be able to use both.

 

Looking forward to the clothing shop!

 

Hi and thanks for your feedback,

 

1) I'll look into it ASAP

2) I will release a merged version along with the clothing shop, so stay tuned :)

 

PS: For now if you want SVSS/SWSS merged content, here is the link -> https://www.dropbox.com/s/m3o7qalxnwqp4ud/HG_MC.rar?dl=0

Share this post


Link to post
Share on other sites

So I figured I'd post within this thread with my question regarding weapons, as opposed to the vehicle thread, even though I'm using the merged variance of SVSS and SWSS.

 

I've built my own shop class and class sets within that allow the purchase of weapons by class. (Small Arms, AR's, Snipers, LMGS, etc etc)

 

Oddly enough none of the RHS gear will appear on my person, unlike vanilla content, however RHS mags and items will work perfectly. Is there something I am perchance missing, or is there a way to perhaps get bought gear to appear within a box? (This would be my preferred overall outcome if at all possible.) Should get too crowded within the box due to there only being a max of 5 players on my mission at any time. Once more any feedback would be absolutely appreciated. :)

 

EDIT:

 

Ah I see a previous post explaining RHS weapons aren't entirely supported. This is indeed quite a shame.

Share this post


Link to post
Share on other sites

I don't have RHS, send me the link to download it via MP and I'll check this out tomorrow, thanks.

Share this post


Link to post
Share on other sites

To anyone whom intends to use this with RHS weapons. DO NOT!! use the ingame tooltip/display/class names of weapons from inside the game via Eden or Virtual, they will all display wrong.

 

They all designate as having weapon rather than weap. One Example being the Glock, it shows it as rhsusf_weapon_glock17g4 When it's ACTUAL classname is rhsusf_weap_glock17g4 This is the same for as far as I've seen. ALL weapons.

 

Digging through the RHS Files themselves reveal this to be true.

 

-Snip- Hoverguy added them below.

 

Example of an ingame tooltip/display of a classname.

 

rTxlz9p.jpg

 

 

This is INCORRECT

  • Like 2

Share this post


Link to post
Share on other sites

Thanks this will become very useful for my scenario and I don't have to do the heavy work myself.

 

Just one improvement would be to make the shop window wider. Some weapon names and ammunition are very long and they can't be seen, such as tracer rounds etc. so you don't know what you are buying.

 

Also if you want to improve the shop script even more, you could do a GUI like EUTW server has, where you can select multiple items and put into a "basket" and see the total purchase price and hit buy will buy all at once. Instead of buying individual things.

 

Some notes on how to add the currency to the GUI permanently, like at the bottom would be nice. Commands on how to add currency to player account.

 

Thanks.

Share this post


Link to post
Share on other sites

I'd also like to use this script to be able to buy CAS support using the CAS support provider module.

 

So I have set the support requester for bombing strike for example to 0 by default and for X$ I want to up it by 1. Any tips on how to do this?

Share this post


Link to post
Share on other sites

Thanks this will become very useful for my scenario and I don't have to do the heavy work myself.

 

Just one improvement would be to make the shop window wider. Some weapon names and ammunition are very long and they can't be seen, such as tracer rounds etc. so you don't know what you are buying.

 

Also if you want to improve the shop script even more, you could do a GUI like EUTW server has, where you can select multiple items and put into a "basket" and see the total purchase price and hit buy will buy all at once. Instead of buying individual things.

 

Some notes on how to add the currency to the GUI permanently, like at the bottom would be nice. Commands on how to add currency to player account.

 

Thanks.

 

Hi Zyme (you again?),

 

I know the weapons list is not wide enough, but if you move hover over an item in the list full name is displayed regardless of GUI size. But since you and a couple of other guys reported this being a bad point, lemme rectify it ;)

 

I was thinking of the "items to basket" feature when I first worked on this shop, maybe later, who knows? :)

 

And for the cash displayed in dialog, most of the guys who use my shop in their mission have their cash amount displayed in custom HUD so you get the point.

 

This is how you add cash to your balance:

player setVariable["HG_myCash",_yourValue];
// _yourValue is a number

Share this post


Link to post
Share on other sites

 

Hi Zyme (you again?),

 

I know the weapons list is not wide enough, but if you move hover over an item in the list full name is displayed regardless of GUI size. But since you and a couple of other guys reported this being a bad point, lemme rectify it ;)

 

I was thinking of the "items to basket" feature when I first worked on this shop, maybe later, who knows? :)

 

And for the cash displayed in dialog, most of the guys who use my shop in their mission have their cash amount displayed in custom HUD so you get the point.

 

This is how you add cash to your balance:

player setVariable["HG_myCash",_yourValue];
// _yourValue is a number

 

But then you need the old value. Would be nice if you had add and substract functions directly on player or named unit. Would be easier than having to grab the variable, update it and then set it. I could do it myself but I think it would be a good addition to be included in the script itself.

Share this post


Link to post
Share on other sites

But then you need the old value. Would be nice if you had add and substract functions directly on player or named unit. Would be easier than having to grab the variable, update it and then set it. I could do it myself but I think it would be a good addition to be included in the script itself.

 

The thing you don't understand is that I don't provide a MONEY/CURRENCY system but just the shop. So what you do outside of the shop with the variable is up to you and if you need something to easily manage your cash, do it. Because most of the time mission makers use their own money var or whatever var they want to buy things. HG_myCash is just a placeholder.

 

But I am a good guy so I've just added a add/sub cash function. Download in the first post :)

 

EDIT:

 

To add cash

[_amount,0] call HG_fnc_addOrSubCash;

To sub cash

[_amount,1] call HG_fnc_addOrSubCash;

Note -> Negative numbers are allowed

  • Like 1

Share this post


Link to post
Share on other sites

1. Yes you can compile all the fncs, or you can use the CfgFunctions method

2. disableSerialization is needed when you want to store displays/controls in variables

3. You set the variable HG_myCash on player's initialization using setVariable (player setVariable["HG_myCash",15000]), then maybe something like this:

 

[] spawn 
{
    {
        _x addEventHandler 
        [
            "Killed", 
            {
                private["_unit","_killer];
                _unit = _this select 0;
                _killer = _this select 1;
       
                if((isPlayer _killer) AND {_killer != _unit}) then
                {
                    private["_oldCash","_newCash"];
                    _oldCash = _killer getVariable "HG_myCash";
                    _newCash = _oldCash + 200;
                    _killer setVariable ["HG_myCash",_newCash];
                };
           
            }
        ];
    } forEach allUnits;

};

 

I am doing the same thing; but where do I put this spawned code? Player init? Init.sqf? Before the addAction to call the store? And what about units that spawn dynamically? Would this even work or will I need to give those spawned groups their own event handler?

 

If it matters: None of the enemies will be other players. This is just a two player thing I am making to play with my brother so all the enemies are AI that spawn randomly or based on triggers; none of them are manually placed.

 

I already had them giving cash, but for my own thing I was doing but... Making dialogs is a pain in the ass, I saw this and thought I would incorporate it instead. Just not sure if all I need to do is change the variable name or not.

Share this post


Link to post
Share on other sites

Hi,

You spawn AIs on the go via function? If you do, just add the EVH without the spawn thread in your function for every spawned unit, you don't have to add it to you and your bro because as you said enemies are only AIs.

For the money variable, you can use yours or do whatever you want with mine, it's just a placeholder. I provide a function to add or sub cash (user request) so it's easier to manage (see post above yours).

Share this post


Link to post
Share on other sites

Hey, i like to give a player some money, when he picks up an item. 
I created an object and put in the init:

this addaction ["Take cash!","cash.sqf"];

 
The cash.sqf looks like this:
 

[150,0] call HG_fnc_addOrSubCash; 
_object = _this select 0; deletevehicle _object;
titleText ["+ 150 €!", "PLAIN DOWN"];

But it doesn't work. Getting this error:

[150,0] call |#|HG_fnc_addOrSubCash
_object = _this se....'
Error Undefined Variable in Expression: hg_fnx_addorsubcash
File ...\...\cash.sqf, line 1

Can someone help me with this?

Share this post


Link to post
Share on other sites

Make sure the function is defined in the function library (CfgFunctions -> HG_ShopFncs)

Also I guess hg_FNX_addorsubcash is a typo, doesn't change a thing anyway.

Share this post


Link to post
Share on other sites

Thanks! That worked for me.

 

Yeah, FNX was a typo, should be "fnc".

Share this post


Link to post
Share on other sites

Hi i have to say that i don't understand where to put this script. i try in the init and in the player. nothing works. can you tell me where it go.

[] spawn 
{
    {
        _x addEventHandler 
        [
            "Killed", 
            {
                private["_unit","_killer];
                _unit = _this select 0;
                _killer = _this select 1;
       
                if((isPlayer _killer) AND {_killer != _unit}) then
                {
                    private["_oldCash","_newCash"];
                    _oldCash = _killer getVariable "HG_myCash";
                    _newCash = _oldCash + 200;
                    _killer setVariable ["HG_myCash",_newCash];
                };
           
            }
        ];
    } forEach allUnits;

};

It wil be easy just to say  put it in a new sqf or in the initPlayerLocal.

  • Thanks 1

Share this post


Link to post
Share on other sites

This was a request so he knew where to add stuff.
 
You have AIs in your mission or you only play with humans?

Share this post


Link to post
Share on other sites

Good morning, I'm using BMR system so the AI spown in when you are 350 m away from them. I'm trying to get money from killing AI so can you help me.

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

×