webbie. 3 Posted June 15, 2018 Hi all, Im looking for a way to add a player proximity scan to my pvp server. Similiar thing has been done in exile using an XM8. all i want to ba able to do is see a hint when you activate the scan that counts players in within a given range. Thanks in advance for any assistance offered. Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 15, 2018 Something like this could do the trick: //init.sqf or wherever you seem fit GOM_fnc_scan = { params [["_scanObject",objNull],["_scanRadius",15],["_debug",false]]; GOM_scanActive = true; if (_debug) then {systemChat "Starting to scan!"}; waitUntil { _nearPlayers = _scanObject nearEntities _scanRadius select {isPlayer _x}; hintsilent format ["Players detected:\n%1",count _nearPlayers]; !(_scanObject getVariable ["GOM_fnc_scanActive",true]) }; if (_debug) then {systemChat "Stopped scanning!"}; }; //call function in object init field _scan = [test,15] spawn GOM_fnc_scan; //to disable scanning sometime later, if needed: test setVariable ["GOM_fnc_scanActive",false,true]; Cheers 1 Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 Fantastic @Grumpy Old Man Ill give it a try now. Much appreciated! 1 Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 @grumpyoldman is their something I could do here //call function in object init field _scan = [test,15] spawn GOM_fnc_scan; to just allow a addaction? so basically it runs only when selected Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 so thinking on it I thought maybe it could run all the time but how could I do it so the variable would apply to all players Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 15, 2018 17 minutes ago, webbie. said: @grumpyoldman is their something I could do here //call function in object init field _scan = [test,15] spawn GOM_fnc_scan; to just allow a addaction? so basically it runs only when selected GOM_fnc_scan = { params [["_scanObject",objNull],["_scanRadius",15],["_debug",false]]; if (_debug) then {systemChat "Starting to scan!"}; hint "Starting to scan!"; sleep 1; waitUntil { _nearPlayers = _scanObject nearEntities _scanRadius select {isPlayer _x}; hintsilent format ["Players detected:\n%1",count _nearPlayers]; !(_scanObject getVariable ["GOM_fnc_scanActive",true]) }; if (_debug) then {systemChat "Stopped scanning!"}; hint "Stopped scanning!"; }; //add scan action to object test addAction ["Scan for Players",{ params ["_object","_caller","_ID"]; if (_object getVariable ["GOM_fnc_scanActive",false]) exitWith { _object setUserActionText [_ID,"Scan for Players"]; _object setVariable ["GOM_fnc_scanActive",false,true]; }; _object setUserActionText [_ID,"Stop scanning for Players"]; _object setVariable ["GOM_fnc_scanActive",true,true]; _scan = [_object,15] spawn GOM_fnc_scan; },[],0,true,true,"","_this isEqualTo vehicle _this",5]; You can activate/deactivate the scanning with a single action, should work fine. 8 minutes ago, webbie. said: so thinking on it I thought maybe it could run all the time but how could I do it so the variable would apply to all players What do you mean? This will detect all players, or do you want to add the action for every player? Cheers Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 So I want to add the function to all players, obviously I cant call all of them test so is their a fuction to add that to allplayers globally? Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 ah nevermind I see what you've done their, perfect, Thank you so much for your assistance! Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 15, 2018 If you want every player to have the addaction on all of the objects simply put the above example into initPlayerLocal.sqf, so every client connecting will receive the actions automatically. Cheers 1 Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 Im obviously doing something wrong, Ive added it to the initplayerlocal, The script is running but its looking for a variable to apply it too eg. GOM_fnc_scan = { params [["_scanObject",objNull],["_scanRadius",15],["_debug",false]]; if (_debug) then {systemChat "Starting to scan!"}; hint "Starting to scan!"; sleep 1; waitUntil { _nearPlayers = _scanObject nearEntities _scanRadius select {isPlayer _x}; hintsilent format ["Players detected:\n%1",count _nearPlayers]; !(_scanObject getVariable ["GOM_fnc_scanActive",true]) }; if (_debug) then {systemChat "Stopped scanning!"}; hint "Stopped scanning!"; }; //add scan action to object???What goes here??? addAction ["Scan for Players",{ params ["_object","_caller","_ID"]; if (_object getVariable ["GOM_fnc_scanActive",false]) exitWith { _object setUserActionText [_ID,"Scan for Players"]; _object setVariable ["GOM_fnc_scanActive",false,true]; }; _object setUserActionText [_ID,"Stop scanning for Players"]; _object setVariable ["GOM_fnc_scanActive",true,true]; _scan = [_object,15] spawn GOM_fnc_scan; },[],0,true,true,"","_this isEqualTo vehicle _this",5]; Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 ah sorry nevermind "player" having a bit of brainfart, thanks again Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 1 more question Do you think rather than being a toggle it could be an action you actually select and it runs it for say 5 secs and scans once everytime you select it? Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 15, 2018 Well you went from wanting a simple hint over an addAction and now it should only run for n seconds. Best make up your mind regarding wanted functionality first. Doubt it's considered convenient having to activate an addAction every 5 seconds but here you go: GOM_fnc_scan = { params [["_scanObject",objNull],["_scanRadius",15],["_duration",5],["_debug",false]]; _scanObject setVariable ["GOM_fnc_scanActive",true,true]; if (_debug) then {systemChat "Starting to scan!"}; hint "Starting to scan!"; sleep 1; _stopTime = time + _duration; waitUntil { _nearPlayers = (_scanObject nearEntities _scanRadius) - [player] select {isPlayer _x}; hintsilent format ["Scan duration: %1\nPlayers detected: %2",[-(time - _stopTime),"HH:MM"] call BIS_fnc_timeToString,count _nearPlayers]; time > _stopTime }; if (_debug) then {systemChat "Stopped scanning!"}; _scanObject setVariable ["GOM_fnc_scanActive",false,true]; hint "Stopped scanning!"; }; //add scan action to object player addAction ["5s Scan for Players",{ params ["_object","_caller","_ID"]; _scan = [_object,15,5] spawn GOM_fnc_scan; },[],0,true,true,"","_this isEqualTo vehicle _this AND !(_this getVariable ['GOM_fnc_scanActive',false])",5]; Cheers Share this post Link to post Share on other sites
webbie. 3 Posted June 15, 2018 Thank You and apologies my thinking was that I didnt want it to be running the checks constantly so I thought this method would be better suited so players could run it as needed. Thank you I do appreciate the time you've given. 1 Share this post Link to post Share on other sites