Now...here's the easiest way I can think of off the cuff, since I haven't got ArmA with me to verify.
The command
findNearestEnemy is one of those excellent little things that came with ArmA, and should be able to serve you here. Basically what it does is find the closest enemy to the unit that the unit KNOWS about. So no madman going crazy shooting at people behind a building or out of sight. Now, it only finds enemies, which might be a bit of a problem - unless you turn the guy to sideEnemy, upon which EVERYONE will be his enemies. Turning anyone to sideEnemy is as simple as addrating -10000.
Now the thing is, as sideEnemy there's a good chance he'll go crazy all on his own, so there's really no need to do the extra dofire/dotarget thing, but if not, you could try doing something like:
_victim = madMan findNearestEnemy (position madMan);
madMan dotarget _victim;
madMan dofire _victim;
Repeat at will.
You could also try messing with the nearTargets command, since it returns every kind of unit from all sides that your guy knows about, but you'd have to create a special parsing portion of the script that removes all the extra information and only returns the actual unit
Here's the link to the nearTargets command:
nearTargetsBasically what it returns is an array of arrays, the enemy of all sane ArmA scripters. So it looks sort of like this:
[Known guy 1 array, known guy 2 array, known guy 3 array....]
And each known guy array looks something like:
[Position, Type, Side, Subjective Cost, Object]
So to access for instance the first actual UNIT in a neartargets array, you'd have to do something like:
_mainarray = madMan nearTargets 100;
_mainArrayDude1 = ((_mainArray select 0) select 4);
madMan dotarget _mainArrayDude1;
madMan dofire _mainarraydude1;
Of course, the nearTargets array isn't constructed based on distance to target (so you could in fact be targeting the person the furthest away by select the first (0) element in the array). So what you'd have to do is first parse through the whole nearTargets array, compare distances, and then select one.
From that point of view, the easiest is simply to mess with the sides and stuff
(make all civilians RACS by grouping them with a non-existent RACS leader, then make the madman OPFOR...or something).
Good luck anyway! I do hope your next ouevre will not require Queens Gambit! Would love to play some ol' nominesine again!
Wolfrug out.