Home   Help Search Login Register  

Author Topic: Concurrent array usage by many fired EH  (Read 1856 times)

0 Members and 1 Guest are viewing this topic.

Offline j0e

  • Members
  • *
    • j0e's home
Concurrent array usage by many fired EH
« on: 21 Feb 2012, 12:06:39 »
I'll try to be as clear as possible.
Of course the environment is the multiplayer.

PREFACE

I have an array in which I store the kills of each player:

  j0e_scores=[0,..,0]  // index 0->player1 and so on

A trigger covers the enemy soldiers and calls a script that parses each units by linking the killed-EH to it:

  <enemy> AddEventHandler ["KILLED",{_THIS Exec "score.sqs"}]

Until here, all is regular.

Note: the EHs are handled only by the server.

PROBLEM

When a massive kill is done, the server fires many EH in the same time.
I'm afraid, but not sure, that most of the "score.sqs" istances write their value in a situation of memory collision.

EXAMPLE

Player1 blows up a whole convoy: 18 soldiers are killed.
The score should be: player1=18.
Instead the stored value is often lower thant the expected one.

QUESTIONSUGGESTIONS

If the missed kills are due to the game that not fires all EHs, then there aren't solutions.
Otherwise, I'm thinking of three possible ways:

1) add a randomized pause (~) in the "score.sqs" to differentiate the instances timing and minimize collision events;

2) let each "score.sqs" istance to put itself in a FIFO list and wait its turn before changing the array;

3) provide an extra array with all enemy soldiers, identify the killed unit and add the killer in another array, in the same index;

  j0e_enemies=enemy1,enemy2,enemy3,..,enemyN
  j0e_killers=0,-1,-1,..,-1   // -1=alive or not killed by a player, 0=killed by player1

YOU

Any comment is appreaciated.