Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Detect if player disconnect

  1. #1

    Detect if player disconnect

    Code:
    _addactionUser = (_this select 1);
    _id =(_this select 2);
    
    	if (!GLB_AlphaRally) exitwith {hint "Alpha Rally is already deployed. Un-deploy Rally point to access it.";};				
    	sleep 1;
    
    PAPABEAR sideChat format["%1 has picked up the Alpha Rally point",name _addactionUser];
    		hint format ["You have %1 seconds to deploy the rally point",_carrytime];
    		GLB_AlphaRally = false;publicVariable "GLB_AlphaRally";	
    		GLB_AlphaRallyTake=true;publicVariable "GLB_AlphaRallyTake";
    
    												
    _addactionUser addAction["<t color='#ffff00'>Build Alpha Rally</t>","occupation\rallypoints\AlphaRallyBuild.sqf","",1,false,true,"","GLB_AlphaRallyTake"];
    waituntil {!GLB_AlphaRallyTake};
    _addactionUser removeAction _id;
    GLB_AlphaRally = false;publicVariable "GLB_AlphaRally";
    This is some code for an addaction which gives a player a rally point.
    I need some code which will detect if "_addactionUser" has disconnected and then update GLB_AlphaRally = true. So the action is available again for other players.

    Any help appreciated. Thanks

  2. #2

  3. #3
    Quote Originally Posted by kylania View Post
    I looked but the wiki does an exceptional bad job at describing how to use it. I was hoping somebody could give me an example in context

  4. #4

  5. #5
    Quote Originally Posted by kylania View Post
    There's this example here.
    Hmm. I did look at that earlier. I just can't get my head around how i would use it.
    If i am understanding this correctly, every time a player disconnects, onplayerdisconnected gets that players name as (_this select 1). And i need to check if
    (_this select 1) == _addactionUser from my addaction script.

    But can i do that.

    BTW i tried several other ways. Including if (!alive _addactionUser) but that doesn't count for disconnecting. And i've even ran a timer which resets the GLB_AlphaRally = true after a set amount of time. But that doesn't work on dedicated servers because the addaction is local.

  6. #6
    you basically need to check ll playable units against the one disconnecting. Check first to ensure its not the __Server__ uid, then check through playable units uids to see if it is the player leaving.

    example...

    Code:
    _id = _this select 0; 
    	_caller = _this select 1; 
    	_uid  = _this select 2; 
    	
    			//check if the uid given is for player or server
    			//__server__ 
    			if (_caller != "__SERVER__") then 
    			{
    				        _player = objNull;
    						{
    					
    						if (getPlayerUID _x == _uid) exitWith 
    						
    						  {
    							   _player = _x;
    						  };
    						} 
    						forEach playableUnits;  
                              };
    basically any mention to _player is the player disconnecting. not sure how you will link it, but can try to use set variable(and true) to store anything like you want on _addactionUser.

    set it to something on the script above and then when _player leaves - set it to something else. have a script that gets the variable for the _player and check when it changes. if that makes sense
    [FOCK] Mikie J -
    Giving bad advice since 2007

    Looking for New Players/scripters at Fockersteam
    http://fockers.moonfruit.com/
    Email:

    A3
    3 Chpaters of Scripting Tutotials -http://www.armaholic.com/page.php?id=20465#comments MORE TO FOLLOW
    TvTCache Hunt - [FOCK]ers Cache Hunt TvT-x [ALPHA]
    Fock Recruit/Group Management - http://www.armaholic.com/page.php?id=19041

  7. #7
    Thanks Mikie boy . I appreciate you taking the time to write a example.

    The thing i really have trouble with is the set/get variable command.(which is what i need to use here).
    I've attempted what you said but i don't understand enough to make it work.

  8. #8
    You need to have in the activation script _whoeveactivated setvariable ["active", 1, true]; this in effect is setting a variable to this player, specific to him and set to a value of 1. U then can call another script to regularly check the value of this player and the active variable. If its 0 then remove whatever was created with the addaction script.
    In the onplayerdisconnect script have _player setvariable ["ACTIVE", 0, TRUE];

    THIS Is the change that the looping script will detect. Sorry on train typing on a not so smart phone

  9. #9
    Great help. So this is what i've cobbled together from everything you've told me. Just a rough edit but is this what you mean?

    init.sqf
    Code:
    if (isnil {GLB_AddActionUsed}) then {
    GLB_AddActionUsed = false;publicvariable "GLB_AddActionUsed";
    	};
    null = [] execvm "actionCheckLoop.sqf";
    
    onPlayerDisconnected { [_id, _name, _uid] call compile preprocessfilelinenumbers "playerDisconnected.sqf" };
    Addaction.sqf (Called using action on flagpol)
    Code:
     
    // SET VARIABLE TO CHECK IF ADDACTION USER IS STILL IN GAME
    	_whoeveactivated = (_this select 1);
    	_actionID=(_this select 2);
    	_whoeveactivated setvariable ["active", 1, true];
    	
    // ADD ACTION ALREADY USED
    if (GLB_AddActionUsed) exitwith 
    	{
    	hint "Come back later. Addaction is already used"
    	};
    	
    // GIVE USER ADDACTION
    _whoeveactivated addAction["Build Rally","createRally.sqf"];
    
    // SET CURRENT ACTION AS USED
    GLB_AddActionUsed=True;publicvariable "GLB_AddActionUsed";
    
    waituntil {createRally called};
    _whoeveactivated removeAction _actionID;
    playerdisconnected.sqf
    Code:
     
    _id = _this select 0; 
    	_caller = _this select 1; 
    	_uid  = _this select 2; 
    	
    			//check if the uid given is for player or server
    			//__server__ 
    			if (_caller != "__SERVER__") then 
    			{
    				        _player = objNull;
    						{
    					
    						if (getPlayerUID _x == _uid) exitWith 
    						
    						  {
    							   _player = _x;
    						  };
    						} 
    						forEach playableUnits;  
                              };
    			// SET PLAYER AS LEFT
    			_player setvariable ["ACTIVE", 0, TRUE];
    actionCheckLoop.sqf
    Code:
     while {true} do
    	{sleep 1;
    		_aVariable = _player getVariable "ACTIVE";
    		if (_aVariable == 0) then {
    			// IF ADDACTION USER DISCONNECTED THEN SET GLOBAL VAR TO ALLOW USE OF ADDACTION AGAIN
    			GLB_AddActionUsed=false;publicvariable "GLB_AddActionUsed";
    		};
    };
    Last edited by BangaBob; Jul 18 2013 at 16:41.

  10. #10
    yeah sort of....

    playerdisconnected - _player should be inside that scope.

    actionCheckLoop - this wont work as you need to pass the specific player with the actual setvariable - however you could set all players to "active", 0 when they join, that way you could use this method. Remember to set _player to player if running from init.sqf

    other way is to run this script as a function and pass the specific player with the setvariable active to it.

    see how you get on and let me know -

Page 1 of 3 123 LastLast

Similar Threads

  1. AI does not detect player
    By B00tsy in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 5
    Last Post: Jul 29 2012, 14:50
  2. Detect player trigger
    By Funkman in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 7
    Last Post: Jun 24 2011, 19:36
  3. detect if player is incargo
    By kakagoegie in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 9
    Last Post: Sep 18 2005, 17:52
  4. any way to detect when is the player looking
    By 5133p39 in forum OFP : CONFIGS & SCRIPTING
    Replies: 4
    Last Post: Jul 19 2005, 16:03
  5. How to detect if a player has a weapon
    By SpeedyDonkey in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 16
    Last Post: Jul 5 2003, 08:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •