Home   Help Search Login Register  

Author Topic: PublicVariable help  (Read 1119 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
PublicVariable help
« on: 05 Sep 2008, 01:41:54 »
Hi I can't get my publicvariable to work right.


here is my in init.sqf
Code: [Select]
"trade" addPublicVariableEventHandler
{
civ = _this select 0;
amount = _this select 1;
item = _this select 2;
num = _this select 3;
if (player == civ) then
{
my_count = ((dcv_inv_array select num) select 1);
my_count = my_count + amount;
new_count = [item, my_count, num];
dcv_inv_array set [num, new_count];
player groupchat format [localize "STR_item_received", amount, item];
};
};




here is my script to open inventory menu(part)
Code: [Select]
player_array =
[
[Civ1, 0],
[Civ2, 1],
[Civ3, 2],
[Civ4, 3],
[Civ5, 4],
[Civ6, 5],
[Civ7, 6],
[Civ8, 7],
[Civ9, 8],
[Cop1, 9],
[Cop2, 10],
[Cop3, 11],
[Cop4, 12],
[Cop5, 13],
[Cop6, 14],
[Cop7, 15],
[Cop8, 16],
[Cop9, 17],
[Sher1, 18],
[Sher2, 19],
[Sher3, 20],
[Sher4, 21],
[Sher5, 22],
[Sher6, 23]
];

//--
test_array = [];
alive_p =
{
_p = _this select 0;
if ((alive _p) AND (!(isnull _p))) then
{
test_Array = test_array + [_p];
publicVariable "test_array";
};
};

{[_x select 0] call alive_p} foreach player_array;
{
//if ([_x select 0] call alive_p) then
//{
_index2 = lbAdd [_playerlist, format["%1 - %2", _x, name _x]];
lbSetData [_playerlist, _index2, format["%1", _x]];
lbSetValue [_playerlist, _index2, 0];
//};
} foreach test_array;
//--



and here is my trade script:
Code: [Select]
_playerlist = 31;
_index = lbCurSel 31;
_val = lbValue [31, _index];
_ind = lbCurSel 30;
item = lbData [30, _ind];
num = lbValue [30, _ind];
amount_to_send = parseNumber (ctrlText 33);
my_amount = ((dcv_inv_array select num) select 1);
p_name = lbData [_playerlist, _index];
if (my_amount < amount_to_send) exitwith {player groupchat format [localize "STR_not_enough", item]};
if ((amount_to_send + 1 == 1) OR (amount_to_send == 0) OR amount_to_send < 0) exitWith {player groupchat localize "STR_not_valid"};
if (item == "Rifle-Bag")exitWith {player groupchat localize "STR_cant_send"};
itemlist = 30;
player groupchat format [localize "STRitem_sent", p_name, amount_to_send, item];

my_amount = my_amount - amount_to_send;
_newitem_c = [item, my_amount, num];
dcv_inv_array set [num, _newitem_c];
lbClear itemlist;
{
if (_x select 1 > 0) then
{
_index = lbAdd [itemlist, format["%1: %2", _x select 0, _x select 1]];
lbSetData [itemlist, _index, _x select 0];
lbSetValue [itemlist, _index, _x select 2];
};
} foreach dcv_inv_array;

trade = [p_name, amount_to_send, item, num];
publicvariable "trade";


most important line being:


trade = [p_name, amount_to_send, item, num];
publicvariable "trade";


but for some reason there is not getting the item when I transfer it.


_playerlist = 31 //=IDC of combobox to select player to send to
"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 Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: PublicVariable help
« Reply #1 on: 05 Sep 2008, 14:34:44 »
1)addPublicVariableEventHandler
Read the above carefully, in particular:
Quote
Description:
If the EH detects a change via publicVariable on the given variableName, code will be executed.
The following arguments are transferred to the code:
* _this select 0: variableName
* _this select 1: New variable value

2)The Biki states
Quote
Multiplayer: Note that the EH is only fired on clients where the publicVariable command has not been executed, as publicVariable does not change the variable where it has been executed.
so your condition if (player == civ) then will never be true and will never execute.
« Last Edit: 05 Sep 2008, 14:50:38 by Mr.Peanut »
urp!