CRY3rn Posted December 26, 2014 Report Share Posted December 26, 2014 [deleted] Link to comment Share on other sites More sharing options...
blckeagls Posted December 27, 2014 Report Share Posted December 27, 2014 Use this for respawn: player addEventHandler ["Respawn", {INSERT_CODE_HERE}]; To get an array of all alive players use: _players = []; { if (alive _x) then { _players = _players + [_x]; }; } foreach playableUnits; //_players will be an array of all alive players You can also use this to select an alive player at random: _selectedPlayer = _players call BIS_fnc_selectRandom; Link to comment Share on other sites More sharing options...
CRY3rn Posted December 27, 2014 Author Report Share Posted December 27, 2014 [deleted] Link to comment Share on other sites More sharing options...
blckeagls Posted December 27, 2014 Report Share Posted December 27, 2014 Thanks for responding blckeagls but the "playableUnits" code is only really useful for the server itself. What I'm trying to do is more along the lines of scripting a local sqf to run on clients. So far, I'm just putting it into the initPlayerLocal.sqf but I haven't exactly tested the effects that revive or respawn have on the loop script. You could use a publicVariableHandler... Have the server tell the players when to execute it... Generally, you shouldn't have the clients spawn anything. I use addPublicVariableEventHandler to have client request stuff from the server.. ////////////////////////////////// ////In Mission Code for client//// ////////////////////////////////// ExecuteMission = { _Object = [1234,5678]; //Define an object or location waitUntil {(player distance _Object) < 100}; //Waits until player is within 100m of object or location serverMissionRequest = ["AIMISSION",true]; //Assigns variable to serverMissionRequest (true to add mission) publicVariableServer "serverMissionRequest"; //Sends the variable "serverMissionRequest" to the server waitUntil {(player distance _Object) > 200}; //Waits until player is 200m away from object or location serverMissionRequest = ["AIMISSION",false]; //Assigns variable to serverMissionRequest (false to remove mission) publicVariableServer "serverMissionRequest"; //Sends the variable "serverMissionRequest" to the server call ExecuteMission; //Executes this code again }; call ExecuteMission; //Spawns when player enters server player addEventHandler ["Respawn", {call ExecuteMission}]; //When player respawns, it executes ExecuteMission player addEventHandler ["Revive", {call ExecuteMission}]; //When player is revived, it executes ExecuteMission (Not sure if "Revive" is valid, need to test) ////////////////////////////// ////////In server code//////// ////////////////////////////// SpawnMission = { //_this = Variable passed from player [PlayerObject,["AIMISSION",1]] _player = _this select 0; //Will be the player object _arrayFromPlayer = _this select 1; //Will be ["AIMISSION",true] or ["AIMISSION",false] _String = _arrayFromPlayer select 0; //Will be "AIMISSION" _Value = _arrayFromPlayer select 1; // Will be true or false _playerPos = getPos _player; //Gets the players position if (_Value) then { //If _Value = true execute SpawnMissions.sqf, if false execute RemoveMission.sqf [_player,_playerPos,_String] exeVM "SpawnMission.sqf"; // Code to spawn mission with passing the player,their position,the string } else { [_player,_playerPos,_String] exeVM "RemoveMission.sqf"; // Code to remove mission with passing the player,their position,the string }; }; "serverMissionRequest" addPublicVariableEventHandler {_this call SpawnMission}; //When serverMissionRequest is received from a player, it executes "SpawnMission" Link to comment Share on other sites More sharing options...
CRY3rn Posted December 27, 2014 Author Report Share Posted December 27, 2014 [deleted] Link to comment Share on other sites More sharing options...
blckeagls Posted December 27, 2014 Report Share Posted December 27, 2014 That sounds very useful. I'll look into it a bit. Thanks for your help man! I editted it... made it more friendly to read and useful i think Link to comment Share on other sites More sharing options...
CRY3rn Posted December 27, 2014 Author Report Share Posted December 27, 2014 [deleted] Link to comment Share on other sites More sharing options...
blckeagls Posted December 27, 2014 Report Share Posted December 27, 2014 the publicVariableEventHandlers are used to do something when either a client or server recieves a public variable... so this can work for server or client... publicVariableServer "VariableName" <- sends public variable to server (owner PlayerObject) publicVariableClient "VariableName" <- sends public variable to client "VariableName" addPublicVariableEventHandler {execute something here}; <- used to do something when public variable is recieved Link to comment Share on other sites More sharing options...
CRY3rn Posted December 27, 2014 Author Report Share Posted December 27, 2014 [deleted] Link to comment Share on other sites More sharing options...
blckeagls Posted December 27, 2014 Report Share Posted December 27, 2014 yes... It's used for the client to issue a request to the server to initiate a script... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now