5133p39 16 Posted June 24, 2007 I would like to know the most reliable way of getting array of all players on the server, and assign them some "id" used when broadcasting variables to compose such variables (call compile format["bcMsg%1",playerIdx]) to avoid any possible conflicts resulting in loss of the broadcasted information. Without the need of naming the playable units, or grouping them under some named unit, or any other method which needs the mission designer to occupy his mind with. Simply put, i am searching for the simplest way for the user. So far i made the following two scripts which are run by the server and the clients. Server part:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_idx"]; aPlayers = []; while {true} do { if (not isNil "addMe") then { addedUnit = addMe; if (not (addedUnit in aPlayers)) then { aPlayers = aPlayers + [addedUnit]; }; _idx = aPlayers find addedUnit; addedUnit = [addedUnit,_idx]; publicVariable "addedUnit"; addMe = nil; }; Sleep 0.1; }; Client part:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_added"]; pIdx = -1; addedUnit = [objNull,-1]; while {pIdx<0} do { _added = addedUnit; if (_added select 0 != player) then { addMe = player; publicVariable "addMe"; } else { pIdx = _added select 1; }; Sleep 0.1; }; The first, server part, is running indefinitely. When server receive the 'addMe' variable it will be eventually added into the player's array 'aPlayers' and a confirmation will be send back to the client together with the index under which the player is listed in the 'aPlayers' array. The second, client part, will run only at the start (or when JIP player connects), and will be running and trying to send the reference to the player unit until it gets the confirmation and index number from the server. I wrote it right now, i didn't tested it, so there may be some glitches (i am after a loooong night), but you should get the idea. And now to my two questions: Q #1: Is something like this this really needed? I mean the confirmation part - is it needed? How does the broadcasting work? Is it possible that some broadcasted variable could be overwritten by different value sent by any other client before the original value gets processed by the server? (i think it could happen, but i know nothing for sure). Q #2: In case the Q#1 is valid, had anyone thought about different (better) solution? ...please note that i want a solution as much user-friendly as possible, so naming the playable units, grouping them, and such, is a big nono. Share this post Link to post Share on other sites
sickboy 13 Posted June 24, 2007 I create a trigger on the server and run through the found objects, then if a vehicle is found, I use the crew command to get units inside vehicles, etc. Using the isPlayer command to check if the unit is a player yes/no. To make sure the clients can send/receive commands in all kinds of orders, forms and even have multiple commands broadcasted and received I wrote 2 functions, which cover the Sending and Receiving: http://www.pastebin.ca/587041 No need to use a channel id or whatever this way, but the functions could easily be expanded for such application. The above functions are built in my SIX_Misc addon, part from Pack1. Take a look if you wish, you can also take any code from it if you need to; just a credit would be enough. Share this post Link to post Share on other sites