Jump to content
Sign in to follow this  
--Scorpion--

BIS Arma 2 Gunshop script

Recommended Posts

Here I present you the BIS Arma2 Gunshop Script

I wanted a script to buy any guns available in Arma 2 and after doing some research nothing came up, so I decided to do it myself. Since scripting have never been my cup of tea, it's pretty much basic stuff right now but it still do the job. With this script you'll be able to buy any Arma 2 guns from a handgun to a smokeshell. Right now, only Arma 2 guns are available but i plan to add all the Arma 2 OA guns too. I would like to hear any suggestion you may have regarding the script and way to improve it before I start adding more guns to the script. I hope people will find it useful.

Here a screenshot to give you a idea of what it look like ingame

arma2oa2011-10-2104-43-14-23.jpg

---Done---

-Added all the OA weapons (version 0.95 only)

-You can buy any Arma 2 weapons or magazines

-You can add as many gun dealer as you want

-You can buy as many gun as you want in a single visit

-You can now sell your weapon back to the saler for 1/3 of the price

-Support only SP

---Still to do---

-Only action, no interface (like our gear menu)

-MP compatibility

Special thanks to Riouken and Rydygier for finding a solution to sell magazine

Version 0.53 fix

Version 0.53 fix

-Added the posibility to sell your weapons

-Fixed the wrong script being called for the M240-MK48 ammo

-Changed few things here and there

Version 0.52 fix

-Changed all aP reference to player

-Added the posibility to have more than one gun saler on the map

-Eliminated the posibility to loose money without having the new bought weapon

-Added GP25 40mm flare and grenade

-Added M203 40mm flare and grenade

-Added all rocket type for the RPG7V and SMAW

-Adjusted price for the Rocket Launcher and their ammo

Version 0.53 link (Arma 2 user only)

http://www.megaupload.com/?d=RW5KMERZ

https://rapidshare.com/files/2716937494/BIS_Arma2_Gunshop_script0.53.utes.rar

Version 0.95 link (Arma 2 + OA user)

http://www.megaupload.com/?d=AC5YE0IE

https://rapidshare.com/files/4182868201/BIS_Arma2_Gunshop_script0.95.utes.rar

http://www.armaholic.com/page.php?id=15478

Edited by -[Scorpion]-
Added Rapidshare link

Share this post


Link to post
Share on other sites

Thanks for doing this, it looks interesting. I'll check it out.

Share this post


Link to post
Share on other sites

Download my mercs mission if your not sure how to do it via Interface has a gunshop and interface on that. Nice Work though,

Share this post


Link to post
Share on other sites

Thanks everyone for your comments

I've good news for you guys, while doing some research reading thread about a unrelated script, I've found a way to buy a new weapon while having already one. Instead of giving it directly to the player, the new bought weapon will be spawn in the player ammo crate. That way you'll be able to buy as many gun as you want in a single visit to the gun saler and at the same time it'll eliminate the possibility of loosing money without receiving the new gun.

The other good news is that I've finally figured a way to have as many gun saler as you want in your mission without the need to name it a specific name. The last change I'm gonna make is that I'll change aP reference to player in all the script to give more freedom to the mission maker and make it more easy to incorporate the script in a already existing mission. That way it should make the life of mission maker easier.

So you can expect a update in the coming days.

P.S. Anyone know what mercs mission JonieTurnock is talking about, I'll love to have a look at how he did it.

Share this post


Link to post
Share on other sites

Hi -[scorpion]- !

Nice idea with the script.

Why not just post it heare using the

 or [php] tags ?

That way you may get some usefull tips from people just taking a quick look.

Share this post


Link to post
Share on other sites

Thanks Grub, it seem to be the one he was talking about.

@Wiggum

You're probably right but being the stubborn guy I'm, I wanted to find the answer by myself so I'll never make the same error again.

Share this post


Link to post
Share on other sites

Looks absolutely fantastic!

Tell me; how do you obtain money? From scoring kills, completing objectives etc.?

Share this post


Link to post
Share on other sites
Looks absolutely fantastic!

Tell me; how do you obtain money? From scoring kills, completing objectives etc.?

Thanks

The most obvious way to add money is by completing objectives with the line myMoney = myMoney + x where x is the amount of money you want the player to gain. Another way for the player to make money is by letting him loot the dead body with these script.

dead.sqs

_unit = _this select 0

#start

? not (alive _unit) : goto "dead"

~1

goto "start"

#dead

mon = _unit addaction ["Take money","money.sqs"]

exit

This script check if the AI unit is dead before giving it the looting action.

money.sqs

_unit = _this select 0

myMoney = myMoney + random 250

_unit removeaction mon

exit

The only thing you've to do is add this line [this] exec "dead.sqs" to all AI units you want the player to be able to loot their dead body. Voilà a easy and fast way to make money.

Share this post


Link to post
Share on other sites

I think if you use

myMoney=500

that way it will be a global Variable and that way the money will be the same (500) for every player !

Share this post


Link to post
Share on other sites
that way it will be a global Variable and that way the money will be the same (500) for every player !

This script have no MP compatibility right now, maybe later.

Edited by -[Scorpion]-

Share this post


Link to post
Share on other sites

Anyone know the command to check if the player has a specific type of magazine ? I know for weapon is hasWeapon but i can't find it for magazine, anyone have a idea how I'll do that.

Share this post


Link to post
Share on other sites

Looking through ACE SYS Magazines there might be a CBA function you could use? however you may be able to find the answer in the code.

#include "script_component.hpp"

// This script is spawned when an improper mag was detected in player's inventory. It processes all mags of given type at once.

// A dummy AI is created to check if there are partially used mags of this type. if yes, they are changed to partially used mags of the new type,

// while those full are simply converted into the proper ones and given back to player.

//

//

//waituntil { GVAR(Processing) == 0 };

[_this select 0,_this select 1,_this select 2,_this select 3] spawn {

TRACE_1("Starting the script","");

private ["_muzzle", "_ammo", "_magcheck", "_c", "_magtoremove", "_newmag", "_weapon", "_unit", "_dummy", "_i", "_max", "_magCountArray", "_action"];

PARAMS_4(_magToRemove,_newMag,_weapon,_muzzle);

_unit = player;

if ((vehicle player)!= player) exitwith {

while { ({ _x == _magtoremove }count (magazines player)) > 0 } do {

_action = [player, _magtoremove] call CBA_fnc_removeMagazine;

_action = [player, _newmag] call CBA_fnc_addMagazine;

};

};

PUSH(GVAR(StartedMags),_magtoremove);

//Create a dummy

_dummy = createAgent ["ACE_CivDummy", [10,10,0], [], 0, "FORM"];

waitUntil { alive _dummy };

_unit reveal _dummy; // Handles delays in MP? reveal _dummy; // Handles delays in MP?

TRACE_1("Dummy alive","");

//safety script, delete dummy if it stays alive for some reason

[_dummy] spawn {

sleep 12;

{

if !(isNull _x) then { _x setdamage 1; deletevehicle _x; deletegroup (group _x); GVAR(Processing) = 0; GVAR(StartedMags) = [];GVAR(DoneMags) = [];/*[format["eliminating dummy %1",_x], "ace_sys_magazines"] call CBA_fnc_debug*/ };

} foreach [(_this select 0)];

};

GVAR(Processing) = 1; //announcing the mags are being processed so it doesn't trigger the check again

{

_x disableAI "TARGET";

_x disableAI "AUTOTARGET";

_x disableAI "MOVE";

_x disableAI "ANIM";

} foreach [_dummy];

_magcheck = false;

if (isClass (configFile >> "CfgWeapons" >> _weapon)) then { _magcheck = true };

removeAllWeapons _dummy;

if (_magcheck) then { _dummy addWeapon _weapon };

#ifdef DEBUG_MODE_FULL

hint format ["%1 amount = %2, Newmagtype = %3", _magtoremove,{ _x == _magtoremove }count magazines _unit, _newmag];

_dbg = format ["processing mag %1 amount = %2, newmagtype = %3 muzzle %4", _magtoremove,{ _x == _magtoremove }count magazines _unit, _newmag,_muzzle];

TRACE_1("",_dbg);

#endif

//Give magazines to the dummy until he finds a full one.

_i = 0;

_max = getNumber(configFile >> "CfgMagazines" >> _magtoremove >> "count");

_magCountArray = []; //array of amounts of ammo in each half-used magazine ie [3,16,28]

if (_magcheck) then {

for "_c" from 0 to ({ _x == _magtoremove }count (magazines _unit))-1 step 1 do {

_unit action ["DROPMAGAZINE", _dummy, _magtoremove];

waitUntil { ({ _x == _magtoremove }count magazines _dummy) > 0 };

_dummy removeweapon _weapon;

_dummy addweapon _weapon;

_dummy selectweapon _muzzle;

waituntil { (_dummy ammo _muzzle) > 0 };

#ifdef DEBUG_MODE_FULL

_dbg = format["got a mag, n = %1, ammo = %2 max = %3",{ _x == _magtoremove }count magazines _dummy,_dummy ammo _muzzle,_max];

TRACE_1("",_dbg);

#endif

if ((_dummy ammo _muzzle) == _max) then {

_action = [_dummy, _magtoremove] call CBA_fnc_removeMagazine;

_action = [_unit, _newmag] call CBA_fnc_addMagazine;

} else {

TRACE_1("Not full magazine","");

_ammo = _dummy ammo _muzzle;

_action = [_dummy, _magtoremove] call CBA_fnc_removeMagazine;

_action = [_dummy, _newmag] call CBA_fnc_addMagazine;

_dummy setVehicleAmmo (_ammo/_max);

TRACE_2("Giving new magazine back",(magazines _dummy),(_dummy ammo _weapon));

//_dummy action ["DROPMAGAZINE", _unit, _newmag];

_unit action ["TAKEMAGAZINE", _dummy, _newmag];

TRACE_2("Given new magazine back",_dummy,(_dummy ammo _weapon));

};

waituntil { count (magazines _dummy) == 0 };

TRACE_1("Pass over","");

};

};

TRACE_1("1st loop over",(count (magazines _dummy)));

_dummy setdamage 1;

deleteVehicle _dummy;

GVAR(Processing) = 0;

PUSH(GVAR(DoneMags),_magtoremove);

TRACE_2("Dummy destroyed",_magtoremove,GVAR(DoneMags));

};

Share this post


Link to post
Share on other sites

Thanks Jonie

The problem is way too advanced for me so if nobody can make sense of all this for me we'll have to live without being able to sell any type of magazine. That's not really a big deal anyway since we'll only miss like 4-5 thing to sell(like grenade, mine, pipebomb, etc). Right now I've almost finished adding all the new action to sell old weapon, it only need a bit more testing to see if I didn't forgot something and I'll be able to start adding all the OA weapon so expect a new version in a week or two.

Share this post


Link to post
Share on other sites
-;2048452']Anyone know the command to check if the player has a specific type of magazine ? I know for weapon is hasWeapon but i can't find it for magazine' date=' anyone have a idea how I'll do that.[/quote']

magazines

_mags = magazines player;

_magtocheck = "30Rnd_556x45_Stanag";

if (_magtocheck in _mags) then
  {
       hint "You have a magazine for the M16!";
  };

That is just one way to do it. If you post some of your code and a bit more detail on what your trying to do we may be able to help you more.

Share this post


Link to post
Share on other sites

That's what I've for selling weapon and it work like a charm.

? player hasWeapon "nvgoggles" : goto "next"
~1
goto "close"

#next
player removeWeapon "nvgoggles"

myMoney = myMoney + 667
~1
hint format ["You have %1 $ now", myMoney]

exit


#close
Hint "You don't have that item, comeback when you have it"

exit

Using Riouken exemple I tried this but it don't work, anyone know why ?

_mags = magazines player

_checkMags = "mine"

? (_checkMags in _mags) : goto "next"
~1
goto "close"

#next
player removeMagazine "mine"

myMoney = myMoney + 250
~1
hint format ["You have %1 $ now", myMoney]

exit


#close
Hint "You don't have that item, comeback when you have it"

exit

Too bad BIS didn't include a hasMagazine command, it'll have been much easier.

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  

×