Jump to content

[Release] Case Unboxing


Spodermayt

Recommended Posts

Case Unboxing

You know you want to.

 

Installation:

You need to goto the MAP EDITOR and place items yourself! Rename them to "Notebook"!!!

Create a new file called case_unboxing.sqf

Place it into Mission.pbo -> custom (Create a custom folder if you don't have it.)

 

Place this into the created file:

//////////////////////////////////
//Spodermayt's Case Unbox Script//
/////Haven't opened enough.../////
///////May luck be with you///////
//////////////////////////////////
_cash = {_x == "ItemGoldBar10oz"} count magazines player;

if !(_cash>=5) then {
		titleText [format["You dont have enough money. (Remember to remove your weapon!)",_costs,CurrencyName] , "PLAIN DOWN", 2];
	} else {
_crap = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"]; call BIS_fnc_selectRandom; //worthless
_meh = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"]; call BIS_fnc_selectRandom; //low-tier
_good = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"]; call BIS_fnc_selectRandom; //mid-tier
_godtier = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"]; call BIS_fnc_selectRandom; // high-tier
_hacker = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"]; call BIS_fnc_selectRandom; //rare
_impossible = ["SMAW","Javelin"]; call BIS_fnc_selectRandom; //super-rare

_selection = [_crap,_meh] call BIS_fnc_selectRandom;
if (_selection == _meh) then {
_selection2 = [_meh,_good] call BIS_fnc_selectRandom;
} else {
cutText [format["You got a worthless weapon."], "PLAIN DOWN"];
_weapon = _crap;
};

if (_selection2 == _good) then {
_selection3 = [_good,_godtier] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2)",_name,_weapon];
cutText [format["You got a low-tier weapon."], "PLAIN DOWN"];
_weapon = _meh;
};

if (_selection3 == _godtier) then {
_selection4 = [_godtier,_hacker] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a mid-tier weapon (%2)",_name,_weapon];
cutText [format["You got a mid-tier weapon."], "PLAIN DOWN"];
_weapon = _good;
};

if (_selection4 == _hacker) then {
_selection5 = [_hacker,_impossible] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a high-tier weapon (%2)",_name,_weapon];
cutText [format["You got a high-tier weapon."], "PLAIN DOWN"];
_weapon = _godtier;
};

if (_selection5 == _impossible) then {
sideChat format["%1 unboxed a super-rare weapon (%2)",_name,_weapon];
cutText [format["You got a super-rare weapon."], "PLAIN DOWN"];
_weapon = _impossible;
} else {
sideChat format["%1 unboxed a rare weapon (%2)",_name,_weapon];
cutText [format["You got a rare weapon."], "PLAIN DOWN"];
_weapon = _hacker
};

player removeMagazine "ItemGoldBar10oz";
player removeMagazine "ItemGoldBar10oz";
player removeMagazine "ItemGoldBar10oz";
player removeMagazine "ItemGoldBar10oz";
player removeMagazine "ItemGoldBar10oz";
player addWeapon _weapon;
}; 

Here's a SC version if someone wants it:

//////////////////////////////////
//Spodermayt's Case Unbox Script//
/////Haven't opened enough.../////
///////May luck be with you///////
//////////////////////////////////
_costs = 5000;

if !([ player,_costs] call SC_fnc_removeCoins) then {
		titleText [format["You dont have enough money. (Remember to remove your weapon!)",_costs,CurrencyName] , "PLAIN DOWN", 2];
	} else {
_crap = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"]; call BIS_fnc_selectRandom; //worthless
_meh = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"]; call BIS_fnc_selectRandom; //low-tier
_good = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"]; call BIS_fnc_selectRandom; //mid-tier
_godtier = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"]; call BIS_fnc_selectRandom; // high-tier
_hacker = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"]; call BIS_fnc_selectRandom; //rare
_impossible = ["SMAW","Javelin"]; call BIS_fnc_selectRandom; //super-rare

_selection = [_crap,_meh] call BIS_fnc_selectRandom;
if (_selection == _meh) then {
_selection2 = [_meh,_good] call BIS_fnc_selectRandom;
} else {
cutText [format["You got a worthless weapon."], "PLAIN DOWN"];
_weapon = _crap;
};

if (_selection2 == _good) then {
_selection3 = [_good,_godtier] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2)",_name,_weapon];
cutText [format["You got a low-tier weapon."], "PLAIN DOWN"];
_weapon = _meh;
};

if (_selection3 == _godtier) then {
_selection4 = [_godtier,_hacker] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a mid-tier weapon (%2)",_name,_weapon];
cutText [format["You got a mid-tier weapon."], "PLAIN DOWN"];
_weapon = _good;
};

if (_selection4 == _hacker) then {
_selection5 = [_hacker,_impossible] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a high-tier weapon (%2)",_name,_weapon];
cutText [format["You got a high-tier weapon."], "PLAIN DOWN"];
_weapon = _godtier;
};

if (_selection5 == _impossible) then {
sideChat format["%1 unboxed a super-rare weapon (%2)",_name,_weapon];
cutText [format["You got a super-rare weapon."], "PLAIN DOWN"];
_weapon = _impossible;
} else {
sideChat format["%1 unboxed a rare weapon (%2)",_name,_weapon];
cutText [format["You got a rare weapon."], "PLAIN DOWN"];
_weapon = _hacker
};

player addWeapon _weapon;
};

And add this to your selfActions (around line 100)

_unboxing = cursorTarget isKindOf "Notebook";
	if ((speed player <= 1) && _unboxing && (player distance cursorTarget < 5)) then {
		if (s_player_unbox < 0) then {
			s_player_unbox = player addAction ["Open a Case","custom\case_unboxing.sqf",cursorTarget, 0, false, true, "",""];
		};
	} else {
		player removeAction s_player_unbox;
		s_player_unbox = -1;
	};
Link to comment
Share on other sites


I get open case option on my notebook however nothing happens.

 

my case_unboxing.sqf is in  my custom folder

rpt error im getting

 

sideChat format["%1 unboxed a low-tier weapon (%2>
  Error position: <format["%1 unboxed a low-tier weapon (%2>
  Error Missing ;
File mpmissions\__CUR_MP.Tavi\custom\case_unboxing.sqf, line 29
Error in expression <BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2>
  Error position: <format["%1 unboxed a low-tier weapon (%2>
  Error Missing ;
File mpmissions\__CUR_MP.Tavi\custom\case_unboxing.sqf, line 29

my line 29

 

if (_selection2 == _good) then {
_selection3 = [_good,_godtier] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2)",_name,_weapon];  ///////// line 29////////////////
cutText [format["You got a low-tier weapon."], "PLAIN DOWN"];
_weapon = _meh;
};
Link to comment
Share on other sites

Seems pointless LOL .

it would be pointless if your trader already sells the the grand prizes like as50 or maaws

 

_hacker = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"]; call BIS_fnc_selectRandom; //rare

_impossible = ["SMAW","Javelin"]; call BIS_fnc_selectRandom; //super-rare

 

since my traders dont sell these,  this would be the only way a player can get them.

so it's worth the gamble

 

now if I can only get it to work............

Link to comment
Share on other sites

  • 6 months later...

Seems pointless LOL .

 

Very constructive.

 

 

 

I get open case option on my notebook however nothing happens.

 

my case_unboxing.sqf is in  my custom folder

rpt error im getting

 

sideChat format["%1 unboxed a low-tier weapon (%2>
  Error position: <format["%1 unboxed a low-tier weapon (%2>
  Error Missing ;
File mpmissions\__CUR_MP.Tavi\custom\case_unboxing.sqf, line 29
Error in expression <BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2>
  Error position: <format["%1 unboxed a low-tier weapon (%2>
  Error Missing ;
File mpmissions\__CUR_MP.Tavi\custom\case_unboxing.sqf, line 29

my line 29

 

if (_selection2 == _good) then {
_selection3 = [_good,_godtier] call BIS_fnc_selectRandom;
} else {
sideChat format["%1 unboxed a low-tier weapon (%2)",_name,_weapon];  ///////// line 29////////////////
cutText [format["You got a low-tier weapon."], "PLAIN DOWN"];
_weapon = _meh;
};

 

 

Nothing happens when you press "Open a case" in the scroll menu... Anyone know a fix?

 

Look for the section that says:

if (_selection5 == _impossible) then {
sideChat format["%1 unboxed a super-rare weapon (%2)",_name,_weapon];
cutText [format["You got a super-rare weapon."], "PLAIN DOWN"];
_weapon = _impossible;
} else {
sideChat format["%1 unboxed a rare weapon (%2)",_name,_weapon];
cutText [format["You got a rare weapon."], "PLAIN DOWN"];
_weapon = _hacker
};

The author missed a semicolon after _weapon = _hacker.

Link to comment
Share on other sites

Also, Spodermayt, I was planning on work on something very similar to this a couple days ago, but it seems you have beat me to it.  I do have a couple suggestions for you though.  I would find an item that could represent a case to be unboxed and add it to a trader.  Then, add a right-click function to the case to allow players to unbox it.  To me, this way seems like it would be a better experience for the player.  Also, for deciding which item is given in the case, I would suggest using a system similar to how loot is chosen to be spawned.  Use a multi-dimensional array with probabilities set up for each item to establish rarities.  Obviously, these are just suggestions.  Use whatever method you feel is best. ;)

Link to comment
Share on other sites

if (_selection5 == _impossible) then {
sideChat format["%1 unboxed a super-rare weapon (%2)",_name,_weapon];
cutText [format["You got a super-rare weapon."], "PLAIN DOWN"];
_weapon = _impossible;
} else {
sideChat format["%1 unboxed a rare weapon (%2)",_name,_weapon];
cutText [format["You got a rare weapon."], "PLAIN DOWN"];
_weapon = _hacker
};

The author missed a semicolon after _weapon = _hacker.

 

-----------------------

Good spot, but every time I click open case still, nothing happens :/

Link to comment
Share on other sites

I remember seeing a script that automatically places laptops at airfield control towers

 

can anyone link it to me please ??

 

I dont remember where but it was just something somebody added to make placeing laptops in all towers easier for a laptop script. maybe cctv or somthing

Link to comment
Share on other sites

I still use your wardrobe and zed bait and bomb...

and likely a few of your other releases.....

great work FreakingFred

 

it's been a LONG time...

good to see you here....

 

It has been a long time, haha!  Stupid growing up and responsibilities getting in the way of fun!  On a serious note though, I got married, got out of the military, had a daughter who just celebrated her 1st birthday, started going to school for Computer Science, and got an internship at a software development company.  My time is extremely limited these days, but I just recently got talked into hosting a DayZ server again, so I am back to good ol' SQF scripting.  You can expect to see some more of me, and hopefully some new releases of my own.  I have a lot of fresh ideas, and will be starting to develop them soon.

 

 

if (_selection5 == _impossible) then {
sideChat format["%1 unboxed a super-rare weapon (%2)",_name,_weapon];
cutText [format["You got a super-rare weapon."], "PLAIN DOWN"];
_weapon = _impossible;
} else {
sideChat format["%1 unboxed a rare weapon (%2)",_name,_weapon];
cutText [format["You got a rare weapon."], "PLAIN DOWN"];
_weapon = _hacker
};

The author missed a semicolon after _weapon = _hacker.

 

-----------------------

Good spot, but every time I click open case still, nothing happens :/

 

 

Hmmm.  I will take a more detailed look through the code and see if I can find any more issues.  Just to make sure, are you positive that you have the correct path set in your fn_selfActions.sqf?  Also, do you have any errors in your RPT related to this script?  Any details you can provide will assist me in assisting you. :)

Link to comment
Share on other sites

 

I remember seeing a script that automatically places laptops at airfield control towers

 

can anyone link it to me please ??

 

I dont remember where but it was just something somebody added to make placeing laptops in all towers easier for a laptop script. maybe cctv or somthing

 

 

That does sound familiar, but I am not sure where I saw it.  However, if you use any of the right-click deployables addons, then you could just add laptop to the list, and allow players to place their own laptops to use with this script.

Link to comment
Share on other sites

That does sound familiar, but I am not sure where I saw it.  However, if you use any of the right-click deployables addons, then you could just add laptop to the list, and allow players to place their own laptops to use with this script.

think I found it was

 

posted in the good ole dayz Dec 23 2013

 

page-3#entry79597

Link to comment
Share on other sites

I believe I found another error with the code.  If I am not mistaken, then the part that says:

_crap = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"]; call BIS_fnc_selectRandom; //worthless
_meh = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"]; call BIS_fnc_selectRandom; //low-tier
_good = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"]; call BIS_fnc_selectRandom; //mid-tier
_godtier = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"]; call BIS_fnc_selectRandom; // high-tier
_hacker = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"]; call BIS_fnc_selectRandom; //rare
_impossible = ["SMAW","Javelin"]; call BIS_fnc_selectRandom; //super-rare

Should actually be:

_crap = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"] call BIS_fnc_selectRandom; //worthless
_meh = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"] call BIS_fnc_selectRandom; //low-tier
_good = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"] call BIS_fnc_selectRandom; //mid-tier
_godtier = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"] call BIS_fnc_selectRandom; // high-tier
_hacker = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"] call BIS_fnc_selectRandom; //rare
_impossible = ["SMAW","Javelin"] call BIS_fnc_selectRandom; //super-rare

I don't believe there should be a semicolon between the array and the call.  Unfortunately, even after I edited this, the script still doesn't seem to be running properly.  I will update you guys if I figure anything else out.

Link to comment
Share on other sites

Okay, so I gave up on trying to fix the original code and ended up just rewriting this entire script myself.  Since I had already planned to develop and release a very similar addon, and due to the fact that I have completely rewritten the code, I will be starting my own thread for the release of this addon once I have fully tested it and worked out any issues, some of which I have already noticed.  The main issues I need to resolve are the possibilities of duping.  However, if you really want to try what I already have done, then just replace your case_unboxing.sqf with this:

private ["_trash","_common","_uncommon","_rare","_epic","_legendary","_chance","_rarity","_weapon","_name"];

_trash = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"];
_common = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"];
_uncommon = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"];
_rare = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"];
_epic = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"];
_legendary = ["SMAW","Javelin"];

_chance = round(random 100);
_rarity = _trash;

switch (true) do {
	case (_chance == 0): {_rarity = _legendary};
	case (_chance > 0 && _chance <= 5): {_rarity = _epic};
	case (_chance > 5 && _chance <= 15): {_rarity = _rare};
	case (_chance > 15 && _chance <= 35): {_rarity = _uncommon};
	case (_chance > 35 && _chance <= 65): {_rarity = _common};
	case (_chance > 65): {_rarity = _trash};
};

_weapon = _rarity call BIS_fnc_selectRandom;
_name = (getText (configFile >> 'cfgweapons' >> _weapon >> 'displayName'));
cutText [format["You have unboxed a %1!",_name], "PLAIN DOWN",2];
player addWeapon _weapon;

and make sure you add any checks or removal of currency as necessary.  I have added mine as a right-click option to empty silver briefcases, because I use single currency and do not have a need for them.  I just remove the briefcase at the beginning of my version of the script.

Link to comment
Share on other sites

Okay, so I gave up on trying to fix the original code and ended up just rewriting this entire script myself.  Since I had already planned to develop and release a very similar addon, and due to the fact that I have completely rewritten the code, I will be starting my own thread for the release of this addon once I have fully tested it and worked out any issues, some of which I have already noticed.  The main issues I need to resolve are the possibilities of duping.  However, if you really want to try what I already have done, then just replace your case_unboxing.sqf with this:

private ["_trash","_common","_uncommon","_rare","_epic","_legendary","_chance","_rarity","_weapon","_name"];

_trash = ["Colt1911","AK_74","glock17_EP1","LeeEnfield","M4A1","M9SD","M16A2"];
_common = ["M16A2GL","M4A1_Aim","UZI_EP1","MakarovSD","M4A3_CCO_EP1"];
_uncommon = ["M24","MP5SD","SVD_CAMO","Pecheneg_DZ","G36K_camo","G36_C_SD_camo"];
_rare = ["M240_DZ","Mk_48_DZ","M14_EP1","DMR_DZ"];
_epic = ["BAF_AS50_scoped","m107_DZ","SCAR_H_LNG_Sniper_SD"];
_legendary = ["SMAW","Javelin"];

_chance = round(random 100);
_rarity = _trash;

switch (true) do {
	case (_chance == 0): {_rarity = _legendary};
	case (_chance > 0 && _chance <= 5): {_rarity = _epic};
	case (_chance > 5 && _chance <= 15): {_rarity = _rare};
	case (_chance > 15 && _chance <= 35): {_rarity = _uncommon};
	case (_chance > 35 && _chance <= 65): {_rarity = _common};
	case (_chance > 65): {_rarity = _trash};
};

_weapon = _rarity call BIS_fnc_selectRandom;
_name = (getText (configFile >> 'cfgweapons' >> _weapon >> 'displayName'));
cutText [format["You have unboxed a %1!",_name], "PLAIN DOWN",2];
player addWeapon _weapon;

and make sure you add any checks or removal of currency as necessary.  I have added mine as a right-click option to empty silver briefcases, because I use single currency and do not have a need for them.  I just remove the briefcase at the beginning of my version of the script.

 

Looks good, I'll give it a go. If I run into any issues I'll just wait for your post :p

Link to comment
Share on other sites

I would suggest replacing the player add weapon command because it does not check if the player already has a weapon in the particular weapon slot.

Instead I would recommend using the BIS function inventory add.

Information on the command can be found here: http://www.ofpec.com/COMREF/index.php?action=read&id=231#invadd

 

I would replace: player addWeapon _weapon;

With: _result = [player,_weapon] call BIS_fnc_invAdd;

 

Then check if the _result variable equals true or false. If the variable is true then the player got the weapon and you can remove the cash.

If the _result variable equals false then the players weapon slot must already be occupied, in which case they would not be given the new weapon so you would not remove the cash.

 

 

Edit

You could also be nice to the player and do this (Only do this if the _result variable equals true):

// Make the player select the weapon
player selectWeapon _weapon;
 
// Get the array of magazines for the selected weapon
_magazineArray = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"); 
_magazine = _magazineArray select 0;
 
// Attempt to add 3 magazines for the selected weapon
for "_i" from 0 to 2 do {_magResult = [player,_magazine] call BIS_fnc_invAdd;};
 
// Reloads the current weapon
reload player;

Basically it attempts to add 3 clips for the new weapon if the player has space in their inventory. If there is not enough space for 3 clips it will add 2 or 1 or none.

The player will also select their new weapon and reload it.

 

Link to comment
Share on other sites

I would suggest replacing the player add weapon command because it does not check if the player already has a weapon in the particular weapon slot.

Instead I would recommend using the BIS function inventory add.

Information on the command can be found here: http://www.ofpec.com/COMREF/index.php?action=read&id=231#invadd

 

I would replace: player addWeapon _weapon;

With: _result = [player,_weapon] call BIS_fnc_invAdd;

 

Then check if the _result variable equals true or false. If the variable is true then the player got the weapon and you can remove the cash.

If the _result variable equals false then the players weapon slot must already be occupied, in which case they would not be given the new weapon so you would not remove the cash.

 

 

Edit

You could also be nice to the player and do this (Only do this if the _result variable equals true):

// Make the player select the weapon
player selectWeapon _weapon;
 
// Get the array of magazines for the selected weapon
_magazineArray = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"); 
_magazine = _magazineArray select 0;
 
// Attempt to add 3 magazines for the selected weapon
for "_i" from 0 to 2 do {_magResult = [player,_magazine] call BIS_fnc_invAdd;};
 
// Reloads the current weapon
reload player;

Basically it attempts to add 3 clips for the new weapon if the player has space in their inventory. If there is not enough space for 3 clips it will add 2 or 1 or none.

The player will also select their new weapon and reload it.

 

Thank you for this.  I actually have a different method of delivery planned but this will be a nice solution for the meantime, while I work on my official release.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...