BlackSheep 0 Posted August 11, 2013 I've tinkered a little corpses delete function. ;) Question? Will this also run on a Dedicated Server? Due to the query "(distance player)"? Because the object player is always a null object to a Dedicated Server, right? If so, how can I overcome this? With playable unit or units or switchable? :confused: /* Author: GrumpySheep Description: Delete's all dead units Parameter(s): GS_fnc_DeleteDead = compile preprocessFileLineNumbers "fn_deletedead.sqf"; Usage: if (isServer) then { [ 300] spawn GS_fnc_DeleteDead; }; */ private "_dis"; _dis = [_this, 0, 350] call bis_fnc_param; while {true} do { { if ( (_x isKindOf "Man") && (_x distance player > _dis) ) then { deleteVehicle _x }; } foreach allDead; sleep 2; }; true Thanks in advance for your time and help! :) Greetings BlackSheep Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 playableUnit = MP switchableUnit = SP :) Share this post Link to post Share on other sites
BlackSheep 0 Posted August 11, 2013 Ok thanks, but when i use switchableUnits in Editor, if ( (_x isKindOf "Man") && ( (_x distance _this > _dis) count switchableUnits == 0) ) then { deleteVehicle _x }; it gives me an error :confused: Error in expression < { { if ( (_x isKindOf "Man") && ( (_x distance _this > _dis) count switchableU> Error position: <distance _this > _dis) count switchableU> Error count: 1 elements provided, 3 expected Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 I think you for an && in the condition field. Like if ( (_x isKindOf "Man") && (_x distance _this > _dis) && count switchableUnits == 0 ) then { deleteVehicle _x }; Can't test (I'm at work) :( Share this post Link to post Share on other sites
BlackSheep 0 Posted August 11, 2013 Thanks again Throws me the same error as before :confused: God damn MP scripting, hehe ;) Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 (edited) Hmm, sometimes if you're getting "Error count: 1 elements provided, 3 expected" it's looking for a position. Let's break this down. So on the condition: (_x distance _this > _dis) _x is an element from allDead, (which should be fine). _dis = [_this, 0, 350] call bis_fnc_param; What is _this? Also, the prtivate statement needs to be an array. Like: private ["_dis"]; EDIT: Sorry, was being sleepy - _this is equal to 300 in this case isn't it? If it is, then we're trying to do: _x distance 300 > _dis which would throw an error like the one you described. The value of this would need to be a position/object [x element, y element, z element] Edited August 11, 2013 by Das Attorney Share this post Link to post Share on other sites
BlackSheep 0 Posted August 11, 2013 Hmm, sometimes if you're getting "Error count: 1 elements provided, 3 expected" it's looking for a position. Let's break this down. So on the condition: (_x distance _this > _dis) _x is an element from allDead, (which should be fine). _dis = [_this, 0, 350] call bis_fnc_param; What is _this? It loads a script parameter. See http://community.bistudio.com/wiki/BIS_fnc_param Example 1: _target = [_this, 0, objNull, [objNull,[]], [2,3]] call bis_fnc_param; If (_this select 0) is not defined, default objnull is used. If (_this select 0) is defined, but is neither of type Object nor Array, error message is logged and default objNull is used. If (_this select 0) and is Array, but it's count is neither 2 nor 3, error message is logged and default objNull is used. Example 2: _answer = [_this, 1, 42] call bis_fnc_param; If (_this select 1) is not defined, default 42 is used. No limit for data types or number of elements exists. Also, the prtivate statement needs to be an array. Like: private ["_dis"]; EDIT: Sorry, was being sleepy - _this is equal to 300 in this case isn't it? Ah no, it´s equal to _dis :) [_this, 0, 350] call bis_fnc_param; If this select 0 is empty then use 350 as parameter >> http://community.bistudio.com/wiki/private Example 1: private "_varname"; Example 2: private ["_varname1", "_varname2"]; Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 Ah, I didn't know that about private statements, thanks :) Can you try getting the values logged to see what they are? Like: hint format ["_this: %1 _dis: %2", _this, _dis]; So hopefully you should see an array with 3 numerical elements for _this, and a number for _dis So that it satisfies the requirements for distance command (for example: _x distance [number, number, number] > number). Put that in the code before the condition check and see what the hint gives you. Share this post Link to post Share on other sites
BlackSheep 0 Posted August 11, 2013 Ok, lets say i call the function with [] spawn GS_fnc_DeleteDead; _dis = [_this, 0, 350] call bis_fnc_param; // if this select 0 is empty, then _dis will use a value of 350 as default If I call [200] spawn GS_fnc_DeleteDead; so _this will by 200 and _dis will become 200 __________ This one works, but not in MP, right? if ( (_x isKindOf "Man") && (_x distance player > _dis) ) then { deleteVehicle _x }; So I have to check the distance to all playableunits or not? :confused: Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 Okay I think I see :) - Is the purpose of this function to delete dead bodies if they are over a set distance from ANY player? If so, leave it with me and I'll knock up a quick script tonight for you. Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 If that is what you needed, here is a function which will do it for you :) Make sure to run on server only. horde_fnc_delete_dead = { /* Author: Das Attorney Usage: if (isServer) then { [300] call horde_fnc_delete_dead; }; Deletes bodies that are over 300m away from any player. Make sure you select switchableUnits or playableUnits for SP/MP */ private ["_threshold", "_too_close", "_body"]; _threshold = _this select 0; { _too_close = false; _body = _x; { if (_body distance _x < _threshold) exitWith { _too_close = true; }; } forEach switchableUnits; /* switchableUnits for SP playableUnits for MP */ if (not _too_close) then { deleteVehicle _body; }; } forEach allDead; }; Share this post Link to post Share on other sites
kylania 567 Posted August 11, 2013 Why not forEach (switchableUnits + playableUnits); so you don't need to change the code for SP vs MP? Share this post Link to post Share on other sites
das attorney 857 Posted August 11, 2013 (edited) Very good :) After I posted, the same notion occurred to me and I started to agonize over putting in something like this: _units = []; if (isMultiplayer) then { _units = playableUnits; } else { _units = switchableUnits; }; So the whole thing would be like this: horde_fnc_delete_dead = { /* Author: Das Attorney Usage: if (isServer) then { [300] call horde_fnc_delete_dead; }; Must be called for on the SERVER only! Deletes bodies that are over 300m away from any player. */ private ["_threshold", "_too_close", "_body", "_units"]; _threshold = _this select 0; _units = []; if (isMultiplayer) then { _units = playableUnits; } else { _units = switchableUnits; }; { _too_close = false; _body = _x; { if (_body distance _x < _threshold) exitWith { _too_close = true; }; } forEach _units; if (not _too_close) then { deleteVehicle _body; }; } forEach allDead; }; It's funny sometimes how when you're scripting you can't see the wood for the trees, but a fresh pair of eyes can make all the difference :) EDIT: Weird how we came to the same conclusion through different methods... Edited August 11, 2013 by Das Attorney Share this post Link to post Share on other sites
BlackSheep 0 Posted August 12, 2013 Thank you very much guy´s :) Share this post Link to post Share on other sites
das attorney 857 Posted August 12, 2013 You're welcome buddy :) Share this post Link to post Share on other sites