Jump to content
Sign in to follow this  
pebcak

List Count * Clients

Recommended Posts

I have a trigger (in the editor) with

Name: T2

Activation: OPFOR

OnAct: serpentList=+thislist ; serpentListCount=Count serpentList ; {_x AddEventHandler ["killed","serpentList=serpentList-[_This Select 0]; serpentListActive=(serpentListCount-(Count serpentList)>=1);"]} ForEach serpentList ; DeleteVehicle T2

(It counts all OPFOR within the trigger area at the start and places the info into a list then kills itself, and sets up an event handler to reduce the count as units get killed.)

However, in MP the list value is multiplied by all clients.  Pretty obvious what's happened now I've tested it.  How do I stop this from happening?  The idea being that there is another trigger waiting to be fired once all of the units in this list have been killed.  Works SP, but in MP it clearly becomes impossible beyond one player.  smile_o.gif

Share this post


Link to post
Share on other sites

You have to be careful with using eventhandlers in MP, especially using them for mission structure. Most eventhandlers (if not all) have local effects, so any code in your eventhandler will be local to each client where the EH was added locally (in your case it'd be every single player), so that means when one of them is killed, your variable is updated X amount of times for the number of players (once per each player). I'd reccomend you don't use an eventhandler for this (they should only really be used for local effects), and instead use a much simpler method with just triggers that is less likely to fail (as it seems like such an unnecessarily complex method for a seemingly simple task). Is there a problem with simply using a trigger and the count command? Like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Condition:{alive _X} count serpentList < count serpentList

On Act: serpentListActive = {alive _X} count serpentList; {if(!alive _X)then{serpentList = serpentList - [_X]}} foreach serpentList

I have no idea what you're trying to do but I always try to use triggers in MP whenever possible, scripts and eventhandlers are usually more work than they're worth to get working correctly and can often be replaced by triggers.

Share this post


Link to post
Share on other sites

I'm not really sure what best practices are so I'm kind of blundering around in the dark until I find something that works. wink_o.gif

What I'm trying to do is simply have a list of units, defined at the start, that when all killed trigger an event.

I did simply use '{alive _x} count [serpent1,serpent2,serpent3] == 0;' as the condition but I was experiencing a strange half-second stutter. I had a number of these kinds of condition running - about 10 - and converting them all to the above over-complicated solution stopped the stutter, so I thought I was on to something. Ah well.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×