Home   Help Search Login Register  

Author Topic: Buy Script Help  (Read 2413 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
Buy Script Help
« on: 28 Aug 2008, 05:54:45 »
Hello.

I am assuming this is a multiplayer problem.
(Though I don't think it belongs in multiplayer section. Sry if it does but read the rest and you tell me)

At the moment, I am just giving the player the weapon he buys, originally I tried to add them to an ammo-box, but for some reason, even though you could see it in the box, it wouldn't let you pick it up. I have no idea why, but you would hit take, and it would just do nothing.

So my question is, do I have to publicvariable something in order for it to allow me to pick it up?

really right now, my biggest problem is adding magazines to the player, because I can't find a good way to see if you are carrying to many magazines, as there are different slots for different types, and count magazines player isnt really working how I would need it.

this is my script to add magazines(which works fine) but any suggestions on how to check your magazines? And would it be better/easier to just add them to a ammo-crate? (Also of course, if I was, then what was I doing wrong that was no letting me take the magazines?
Code: [Select]
_idc, 108;
_index = lbCurSel _idc;
_itemClass = lbData [_idc, _index];
_amount = parseNumber (ctrlText 109);
_temp_a = [];

for[{_i=0}, {_i < count magazines player}, {_i=_i+1}] do
{
_mag = magazines player select _i;
player sidechat format ["%1", _mag];
if (_mag == _itemClass) then
{
_temp_a = _temp_a + [_mag];
};
};
for [{_m=count _temp_a}, {_m < _amount}, {_m=_m+1}] do
{
player addMagazine _itemClass;
player groupchat "Added mag";
};
« Last Edit: 28 Aug 2008, 05:56:38 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Buy Script Help
« Reply #1 on: 28 Aug 2008, 06:44:51 »
When working on Sahraniville we noticed that buying a weapon and sticking it in a crate would make the weapon appear there, but you couldn't pick it up. We eventually used Spooner's Money system, and then decided to use the shop system he had too.

I've noticed a similar bug when someone takes a weapon from a crate/vehicle in MP at the same time as you. You click the weapon and try taking it in the gear menu but it doesn't let you, then after some time it disapears out of the gear menu. I believe this is related to the problem you are having.

I think the server (at least) needs to know the weapon is there before you can just take it and put it in your gear. At the moment your making the weapon local to the player who bought it (as actions are local to the player who clicks them), but the server hasn't a clue it's there.

I'm not to good with the MP commands in ArmA, so I would take the publicvariable route - although there may be a better way. You will need to make it so when it adds the gun to the crate, it adds it to the server and the player who executed the script. If that still doesn't work try making it so the weapon is added on ALL players on the server.

For checking magazines, you simply have count magazines player. Remember medic's have less slots so you may need to check the unit type. I see your script already uses them commands. Does it not work ?

And yeh, since the map is in a MP enviourment, and half of your thread is about a MP problem, it should be put in the MP board. I'm sure a mod/admin will move it for you if you ask them nicely :)
« Last Edit: 28 Aug 2008, 06:50:02 by JasonO »

Offline ModestNovice

  • Members
  • *
Re: Buy Script Help
« Reply #2 on: 28 Aug 2008, 06:55:13 »
right ok thanks Jason0. Yeh I am just adding it locally to the player, like Spon Money does, but yeh I believe I will try the crate.

I think I will try this.
Code: [Select]
p_array = [Civ1,Civ2,Civ3,Civ4,Civ5,etc...];
{
if (player == _x) then
{
_crate addWeaponCargo [weapons, number];
}
}foreach p_array;
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Buy Script Help
« Reply #3 on: 28 Aug 2008, 10:21:09 »
To figure out how many magazine/weapon slots a unit has left is not as easy as you'd hope :) Some magazines (stingers, m246 mags...) are larger, others smaller. Also, as mentioned, some unit classes have less total slots available. In RUG Inventory I devised a config-reading system where I (sort of awkwardly) go through a config check and end up knowing whether or not there's space in my inventory. It looks something like this:

Code: (Extract from magControl.sqf by Wolfrug) [Select]
// This variable (_canadd) is set to false if there's not enough space in your gear

_canadd = true;
_magazines = magazines RUG_Inventory_Caller;

// Medics have less space for both large and small gear. This check varies the slots accordingly

_medic = 10311;
_normal = 11399;
_bigSlots = 12;
_smallslots = 8;
_unitClass = getNumber (configFile >> "CfgVehicles" >> (typeOf RUG_Inventory_Caller) >> "weaponSlots");
if (_unitClass == _medic) then {_bigSlots = 8; _smallslots = 4};

// Assumes all slots are free

_bigslotsfree = _bigslots;
_smallslotsfree = _smallslots;

// Quick loop that checks the total slot-size of each mag, and depending on type and size, removes free slots from either pistol or main inventory.

for "_i" from 0 to ((count _magazines) - 1) do
{
_curMag = _Magazines select _i;
_curMagSizeARMA = getNumber (configFile >> "CfgMagazines" >> _curMag >> "type");
_divisor = 256;
if (_curMagSizeARMA < _divisor) then {_divisor = 16};
_slotsize = _curmagsizearma / _divisor;
if (_divisor == 256) then {_bigslotsfree = _bigslotsfree - _slotsize} else {_smallslotsfree = _smallslotsfree - _slotsize};
};

// Final check for main/pistol mags: if the mag in question is too big, _canadd will be made false

if (_type == 256) then
{
if ((_bigslotsfree - (_MagSizeArma/_type)) < 0) then {_canadd = false};
//hint format ["Big ammo: %1", _bigslotsfree];
};
if (_type == 16) then
{
if ((_smallslotsfree - (_MagSizeArma/_type)) < 0) then {_canadd = false};
hint format ["Small ammo: %1", _smallslotsfree];
};

// Adds the magazine and deletes the item/tells you there's not enough room.

if (_canadd) then {
RUG_Inventory_Caller addmagazine _MagClassName;
_n=[] spawn RUG_Inventory_Use_Default;
}
else {ctrlSetText [_InvGen, "Not enough room in your gear!"]};

// End of script

Of course there's a bunch of local variables before that need to be determined, such as _MagClassName, RUG_Inventory_Caller and _MagSizeArma. The last one I got by doing this:

Code: [Select]
_curMagSizeARMA = getNumber (configFile >> "CfgMagazines" >> _curMag >> "type");
_MagClassName is obviously just the class name of the magazine, and RUG_Inventory_Caller can easily be replaced by "Player". :)

Anyway, not sure if that's going to work out of the box, but it gives you an idea of how it can be done. And note: Spooner WILL have done this a -lot- more fluently in his own system! So if you only can, try using his code instead ;) This is just to give you the general idea.

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Buy Script Help
« Reply #4 on: 28 Aug 2008, 10:50:47 »
Yes, with crates you have to add weapons on all machines or you get into trouble. If you just want the player to have access, though, I think you can just add it on the server and the local machine. I suspect that what is added on the local machine is what is visible (saves communicating with the server to find out contents), but once you try to pick it up it has to check that it is still there on the server to prevent 2 people picking up the same item at the same time. However, there is no real excuse not to work out the correct slots on the player object and give it directly.

Although I've done a lot more with slots in my SPON Money system, I have to admit that it was quite clunky and really does need a good purging, so I don't particularly expect people to work out what I was doing (my first script that queries the config). However, here is some of my elegance at work ;P It avoids the assumptions Wolfrug is making about available slots.
Code: [Select]
private "_slotsValue";
_slotsConfig = configFile >> "CfgVehicles" >> (typeOf player) >> "weaponSlots";
if (isText (_slotsConfig)) then
{
_slotsValue = call compile (getText _slotsConfig);
}
else
{
_slotsValue = getNumber _slotsConfig;
};

_maxLargeSlots = floor ((_slotsValue mod 4096) / 256);
_maxSmallSlots = floor ((_slotsValue mod 256) / 16);
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ModestNovice

  • Members
  • *
Re: Buy Script Help
« Reply #5 on: 29 Aug 2008, 00:33:46 »
righto thanks Wolfrug and Spooner.

yeh I had a look in ur money scripts and was quite confused on how you were checking it.  :D

so to add it on the server would I just do:
Code: [Select]
if (isServer) then
{
_crate addWeaponCargo [wep, num];
};
_crate addWeaponCargo [wep, num];

*EDIT* OK NEED HELP AGAIN ...
sry for not format

Code: [Select]
_idc = 110;
_index = lbCurSel _idc;
_num = lbValue [_idc, _index];
_itemClass = ((buy_weapons select _num) select 1);
_sellPrice = ((buy_weapons select _num) select 3);
_name = ((buy_weapons select _num) select 1);
_amount = parseNumber (ctrlText 109);
temp_a = [];
if ((!(player hasWeapon _itemClass)) AND (!(_itemClass in magazines player))) exitWith {};
for [{_a=0},{_a < count mags_array}, {_a=_a+1}] do
{
_mag = ((mags_array select _a) select 0);
if (_mag == _itemClass) then
{
temp_a = temp_a + [[_mag]];
};
};
if (player hasWeapon _itemClass) then
{
DCV_Cash = DCV_Cash + _sellPrice;
player removeWeapon _itemClass;
player groupchat format [localize "STR_sold", _itemClass, _sellPrice, DCV_Cash];
lbDelete [_idc, _index];
_weapons_array = [];
{
if (!(_x select 0 == _name)) then
{
_weapons_array = _weapons_array + [[_x select 0, _x select 1]];
};
}foreach weapons_array;
weapons_array = _weapons_array;
}
else
{
tem_b = [];
if (count temp_a >= _amount) then
{
for [{_i=0}, {_i < _amount}, {_i=_i+1}] do
{
player removeMagazine _itemClass;
lbDelete [_idc, _index];
player sidechat format ["%1", _i];
mag_name = ((mags_array select _i) select 2);
tem_b = tem_b + [[_mag_name]];
player sidechat format ["%1",_mag_name];
};

hint format ["%1", mag_name];
_mags_array = [];
{
if (!(_x select 2 == mag_name)) then
{
_mags_array = _mags_array + [[_x select 0, _x select 1, _x select 2]];
};
}foreach mags_array;
mags_array = _mags_array;
DCV_Cash = DCV_Cash + _sellPrice * _amount;
player groupchat format [localize "STR_sold_mag", _amount, _itemClass, (_sellPrice * _amount), DCV_Cash];

Basically I am trying to get it to remove the magazine from your array, but only remove the ones you sold, cuz before it was clearing your whole mag array. But I pretty much got it to work, it sells two, but when I close the dialog and open again, I have 3 mags? So for some reason its adding one back, anyone got any ideas where I go wrong?

PLEASE Help, again sry for the mess script, I have yet to discover a nice clean way to write. :(
« Last Edit: 29 Aug 2008, 02:51:55 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline ModestNovice

  • Members
  • *
Re: Buy Script Help
« Reply #6 on: 15 Sep 2008, 04:01:11 »
You geniuses :)

Thanks guys !!!

*EDIT*
rups!

OH NOES! I needs help... :o
Code: [Select]
DCV_fBuyMag =
{
_list = 108;
_index = lbCurSel _list;
_num = lbValue [_list, _index];
_amount = parseNumber (ctrlText 109);
_mag = ((mags_array select _num) select 1);
_price = ((mags_array select _num) select 2) * 2;
_count = ((mags_array select _num) select 3);
//hint format ["Mag: %1 \nPrice: %2 \nN: %3", _mag, _price, _count];
if (DCV_Cash < _price * _amount) exitWith {player groupchat format [localize "STR_cant_afford", "Mag"]};
if ((_amount + 1 == 1) OR (_amount == 0) OR (_amount < 0)) exitWith {player groupchat localize "STR_not_valid"};


//Thanks Spooner and Wolfrug :)
private "_slotsValue";
_slotsConfig = configFile >> "CfgVehicles" >> (typeOf player) >> "weaponSlots";
if (isText (_slotsConfig)) then
{
_slotsValue = call compile (getText _slotsConfig);
}
else
{
_slotsValue = getNumber _slotsConfig;
};

_maxLargeSlots = floor ((_slotsValue mod 4096) / 256);
_maxSmallSlots = floor ((_slotsValue mod 256) / 16);
//player groupchat format ["Big: %1  Small: %2", _maxLargeSlots, _maxSmallSlots];
DCV_Cash = DCV_Cash - _price * _amount;
for[{_i=0}, {_i < _amount}, {_i=_i+1}] do
{
player addMagazine _mag;
};
player groupchat format [localize "STR_mag_buy", _amount, _mag, (_price * _amount), DCV_Cash];

for "_i" from 0 to ((count magazines player) - 1) do
{
_curMag = magazines player select _i;
_curMagSizeARMA = getNumber (configFile >> "CfgMagazines" >> _curMag >> "type");
_divisor = 256;
//hint format ["%1", _curMagSizeARMA];
if (_curMagSizeARMA < _divisor) then
{
_divisor = 16
};
_slotsize = _curmagsizearma / _divisor;
if (_divisor == 256) then
{
if (!(_maxLargeSlots <= 0)) then
{
_maxLargeSlots = _maxLargeSlots - _slotsize;
//player sidechat "Big Slots";
player sidechat format ["%1", _maxLargeSlots];
}
else
{
};
}
else
{
if (!(_maxSmallSlots <= 0)) then
{
_maxSmallSlots = _maxSmallSlots - _slotsize;
//player sidechat "Small Slots";
player sidechat format ["%1", _maxSmallSlots];
}
else
{
};
};
};
};
I need it just to give me a mag if I have enough slots...

I try Wolfrugs code, but _type is undefinded...


Also, perhaps, you Gurus helps me cut my code down hehe, its looks so sloppy :(
« Last Edit: 15 Sep 2008, 05:19:58 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley