Jump to content
  • 0

Admin Tool: Add Key to Toolbelt


Guest

Question

Hi,

im trying to make an admin tool which allows admins to make keys by looking at a locked car and executing the following script:

	_own = cursorTarget getVariable "CharacterID";
	_num = parseNumber _own;
	sleep 2;
	diag_log(format["GETKEY: OwnerID: %1", _num]);
	 _green = {
	 			_keyColor = "Green";
				_keyNumber = _num;
				diag_log(format["Key is %1!", _keyColor]);
				};
	 _red = {
	 			_keyColor = "Red";
				_keyNumber = (_num - 2500);	
				diag_log(format["Key is %1!", _keyColor]);
				};
	 _blue = {
	 			_keyColor = "Blue";
				_keyNumber = (_num - 5000);
				diag_log(format["Key is %1!", _keyColor]);
				};
	 _yellow = {
	 			_keyColor = "Yellow";
				_keyNumber = (_num - 7500);
				diag_log(format["Key is %1!", _keyColor]);
				};
	 _black = {
	 			_keyColor = "Black";
				_keyNumber = (_num - 10000);
				diag_log(format["Key is %1!", _keyColor]);
				};
	 _none = {
				cutText ["Error!", "PLAIN DOWN"];
				exitWith{};
				};


    switch true do {
      case ((_num > 0) && (_num < 2501))  : _green;
      case ((_num > 2500) && (_num < 5001))  : _red;
	  case ((_num > 5000) && (_num < 7501))  : _blue;
	  case ((_num > 7500) && (_num < 10001))  : _yellow;
	  case (_num > 10000)  : _black;
      default _none;
    };

_keySelected = format[("ItemKey%1%2"), _keyColor, _keyNumber];
_object = format[("'%1'"), _keySelected];
diag_log(format["GETKEY: Adding Key %1!", _object]);
GearAdd = (vehicle player);
GearAdd addWeapon _object;

i dont really know why it isnt working but probably someone has an idea.

 

thanks for your help

 

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

I've posted a working solution here in the forum somewhere, but don't know where so here is what I am using myself:

private ["_ct","_id","_result","_inventory","_backpack"];

_ct = cursorTarget;
if (_ct isKindOf "LandVehicle" OR _ct isKindOf "Helicopter" OR _ct isKindOf "Plane" OR _ct isKindOf "Ship") then
{
	_id = _ct getVariable ["CharacterID","0"];
	_id = parsenumber _id;
	_result = "ItemKey";
	if (_id == 0) exitWith {cutText [format["%1 has ID 0 - No Key possible.",typeOF _ct], "PLAIN"];};
	if ((_id > 0) && (_id <= 2500)) then {_result = format["ItemKeyGreen%1",_id];};
	if ((_id > 2500) && (_id <= 5000)) then {_result = format["ItemKeyRed%1",_id-2500];};
	if ((_id > 5000) && (_id <= 7500)) then {_result = format["ItemKeyBlue%1",_id-5000];};
	if ((_id > 7500) && (_id <= 10000)) then {_result = format["ItemKeyYellow%1",_id-7500];};
	if ((_id > 10000) && (_id <= 12500)) then {_result = format["ItemKeyRed%1",_id-10000];};

	_inventory = (weapons player);
	_backpack = ((getWeaponCargo unitbackpack player) select 0);
	if (_result in (_inventory+_backpack)) then
	{
		if (_result in _inventory) then {cutText [format["Key [%1] already in your inventory!",_result], "PLAIN"];};
		if (_result in _backpack) then {cutText [format["Key [%1] already in your backpack!",_result], "PLAIN"];};
	}
	else
	{
		player addweapon _result;
		cutText [format["Key [%1] added to inventory!",_result], "PLAIN"];
	};
};

That works most of the time, I had like 1 or 2 times the key did't work but thats like 5%, don't know why :D

Link to comment
Share on other sites

  • 0

well your script looks exactly like my first one, cause it didnt work i tried it with switch commands but okay, i will try, thank you

I might not be exactely the same, someone posted a (not working) version of that here, and I fixed it up so it works.. might look 99% the same but it's not the same :P

If you want replace it with a switch-case, but I was to lazy to improve it and rather do my own custom scripts from scratch :)

 

Edit: was just looking at your code in the first post, looks a little weird you define functions for every key color, but never call them and even if it might nor work because the variables are defined privat and not outside of the function scope..

case ((_num > 0) && (_num < 2501))  : _green;

should be

case ((_num > 0) && (_num < 2501))  : call _green; // to actually call the function, I don't knwo if it can work without a call (or spawn), I am no ArmA scriping expert ^^
Link to comment
Share on other sites

  • 0

I've posted a working solution here in the forum somewhere, but don't know where so here is what I am using myself:

private ["_ct","_id","_result","_inventory","_backpack"];

_ct = cursorTarget;
if (_ct isKindOf "LandVehicle" OR _ct isKindOf "Helicopter" OR _ct isKindOf "Plane" OR _ct isKindOf "Ship") then
{
	_id = _ct getVariable ["CharacterID","0"];
	_id = parsenumber _id;
	_result = "ItemKey";
	if (_id == 0) exitWith {cutText [format["%1 has ID 0 - No Key possible.",typeOF _ct], "PLAIN"];};
	if ((_id > 0) && (_id <= 2500)) then {_result = format["ItemKeyGreen%1",_id];};
	if ((_id > 2500) && (_id <= 5000)) then {_result = format["ItemKeyRed%1",_id-2500];};
	if ((_id > 5000) && (_id <= 7500)) then {_result = format["ItemKeyBlue%1",_id-5000];};
	if ((_id > 7500) && (_id <= 10000)) then {_result = format["ItemKeyYellow%1",_id-7500];};
	if ((_id > 10000) && (_id <= 12500)) then {_result = format["ItemKeyRed%1",_id-10000];};

	_inventory = (weapons player);
	_backpack = ((getWeaponCargo unitbackpack player) select 0);
	if (_result in (_inventory+_backpack)) then
	{
		if (_result in _inventory) then {cutText [format["Key [%1] already in your inventory!",_result], "PLAIN"];};
		if (_result in _backpack) then {cutText [format["Key [%1] already in your backpack!",_result], "PLAIN"];};
	}
	else
	{
		player addweapon _result;
		cutText [format["Key [%1] added to inventory!",_result], "PLAIN"];
	};
};

That works most of the time, I had like 1 or 2 times the key did't work but thats like 5%, don't know why :D

I added this to my Blurgaming Antihack :) 

 

works like a charm

 

thx axe!

Link to comment
Share on other sites

  • 0

Well i found your error buddy! Sometimes its not working because all keys above id 10000 are black and not red!

change:

if ((_id > 10000) && (_id <= 12500)) then {_result = format["ItemKeyRed%1",_id-10000];};

to

if ((_id > 10000) && (_id <= 12500)) then {_result = format["ItemKeyBlack%1",_id-10000];};
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...