And for your secondary question: how to add the cash only to the killer i'd recommend you
to use arrays with subarrays
Warning!!!!! - it's probably getting a little bit complicated now !!!!!
If you have an init.sqs put:
cash_array = [] inside.
*** read what i added at the end of my post afterwards before going on ***
If not then put the code into your very first unit's init field, which you placed onto the map:
If the very first unit you placed onto the map is also included to the cash system, put the following code into it's
init field:
cash_array = [[this,0]:note - the init fields of units use the 'first being placed / first being executed' system, because of this
you need to initialize the cash_array by the first unit's init field.
*** ----------------------------------------------------------------------------------------- ***
Now into each unit which should take part in the cash system put the following code into it's init field:
cash_array = cash_array + [[this,0]]Now the eventhandler:
this addEventHandler ["killed",{"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 5; _x set [1,temp_cash]}" forEach cash_array}]If this unit gets killed, it will determine which unit of cash_array is the killer and will add 5 to the second element of
the subarray where the killer unit is inside.
A unit's init field should look then like this:
cash_array = cash_array + [[this,0]]; this addEventHandler ["killed",{"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 5; _x set [1,temp_cash]}" forEach cash_array}]OK, explanation:
Now you have an array: cash_array, which look like this in theory:
[[unit1,0],[unit2,0],[unit3,0]]This array features 3 elements where each element again features 2 subelements: the unit itself and a number.
You can access an element of this cash_array by:
cash_array select x:note - x stands for a number from 0 to 2 (while 0 is the first element and 2 the last one).
If you want to find out what is the score of let's say unit 2 you need to store element 2 (cash_array select 1) into
a temporary array:
temp_array = cash_array select 1Now you can access the numeric value by:
temp_array select 1-----------------------------------------------------------------------------------------------------------------------------------------------
I hope you didn't get lost somewhere inbetween here.
:edit - !!!!!!!! wait wait wait !!!!!!!!!
I just figured out that not always the first unit's init field, being placed on the map first
will become executed first.
East units go for West units.
This means the very first East unit being placed executes it's init field before any West unit does.
So if you have placed all West units before and later add East units, still the first init field to be
executed is the one of the first East unit you placed.
This further means that you need to initialize your cash_array by the first East unit you've placed.
~S~ CD