Gacku 0 Posted March 11, 2023 Greetings, I'm one of those people who comes up with incredibly niche ideas without having much experience in scripting, so I was hoping someone here could help me. I have a script that jams the TFAR radio, and ideally the players' radios would go back to working correctly once the jammer is destroyed. However, I've run into a couple of problems. The first is that the players inside the jammer range can hear radio transmissions from outside of it, which isn't a huge problem so if it can't be fixed then so be it. The second problem is that, even though the players' radios go back to working once they are outside the range of the jamming script, they do not go back to working if the jamming entity is destroyed while they are inside of it. You can imagine how this might be an issue. Code posted below, and I greatly appreciate any help that can be given. YourFunctionName = { _unitInJammerArea = []; params ["_jammer"]; while {alive _jammer} do { _unitInJammerArea = nearEntities [_jammer, ["Man"], 200]; _allUnits = allPlayers - entities "HeadlessClient_F"; _notInJammerArea = _allUnits - _unitInJammerArea; if !(count _notInJammerArea isEqualTo 0) then { { _x setVariable ["tf_receivingDistanceMultiplicator", 1]; _x setVariable ["tf_sendingDistanceMultiplicator", 1]; } foreach _notInJammerArea; }; if !(count _unitInJammerArea isEqualTo 0) then { { _x setVariable ["tf_receivingDistanceMultiplicator", 0]; _x setVariable ["tf_sendingDistanceMultiplicator", 0]; } foreach _unitInJammerArea; }; sleep 5; }; { _x setVariable ["tf_receivingDistanceMultiplicator", 1]; _x setVariable ["tf_sendingDistanceMultiplicator", 1]; } foreach _unitInJammerArea; }; Share this post Link to post Share on other sites
Stormmy1950 42 Posted March 11, 2023 radiojammer = { params ["_jammer"]; private _unitInJammerArea = []; private _allUnits = allPlayers - entities "HeadlessClient_F"; while {alive _jammer} do { _unitInJammerArea = nearEntities [_jammer, ["CAManBase"], 300]; private _notInJammerArea = _allUnits - _unitInJammerArea; if (count _notInJammerArea isNotEqualTo 0) then { { _x setVariable ["tf_receivingDistanceMultiplicator", 1]; _x setVariable ["tf_sendingDistanceMultiplicator", 1]; } foreach _notInJammerArea; }; if (count _unitInJammerArea isNotEqualTo 0) then { { _x setVariable ["tf_receivingDistanceMultiplicator", 0]; _x setVariable ["tf_sendingDistanceMultiplicator", 0]; } foreach _unitInJammerArea; }; sleep 5; }; { _x setVariable ["tf_receivingDistanceMultiplicator", 1]; _x setVariable ["tf_sendingDistanceMultiplicator", 1]; } foreach _allUnits; }; Try this. Also dont forget to delete Hidden characters when you copy from here. Share this post Link to post Share on other sites
Gacku 0 Posted March 12, 2023 I tried this script and it didn't work at all. I've requested an error log from my unit's server to see if I can identify a specific problem. Share this post Link to post Share on other sites
pierremgi 4817 Posted March 12, 2023 YourFunctionName = { params ["_jammer","_gain"]; _jammerArea = [getpos _jammer,200,200,0,false,200]; while {alive _jammer} do { { _gain = if (_x inArea _jammerArea) then [{0},{1}]; _x setVariable ["tf_receivingDistanceMultiplicator", _gain]; _x setVariable ["tf_sendingDistanceMultiplicator", _gain]; } foreach allPlayers; sleep 5; }; { _x setVariable ["tf_receivingDistanceMultiplicator", 1]; _x setVariable ["tf_sendingDistanceMultiplicator", 1]; } foreach allPlayers; }; Not tested Share this post Link to post Share on other sites
Gacku 0 Posted March 15, 2023 The players can still hear radio transmissions from outside the range, but it no longer disables their radio when they are inside the range when it's destroyed, and that's good enough for me. Thanks! Share this post Link to post Share on other sites
Dedmen 2652 Posted March 15, 2023 params ["_jammer","_gain"]; Doesn't make sense to pass in gain as a variable, its not a parameter, and its never used without being overwritten. _gain = if (_x inArea _jammerArea) then [{0},{1}]; I'd recommend not using the obscure if else syntax that noone knows, rather use private _gain = [1,0] select (player inArea _jammerArea); // if player in area gain is zero foreach allPlayers; This is not needed, the variables used here are only ever read for the local player, no need to set it on other players. But you need to make sure that this script runs on every players machine. _x setVariable ["tf_receivingDistanceMultiplicator", _gain]; This is wrong, the smaller this value is, the greater range the radio can receive. So here you are increasing receiving range while you're inside the jammed area. I'm quite sure that is not what you want. You want to set this to a high value if jammed, or if you're on TFAR 1.0 just use TFAR_globalRadioRangeCoef global variable instead, though that cannot be 0, you can use a small value like 0.00001. Share this post Link to post Share on other sites
pierremgi 4817 Posted March 15, 2023 6 hours ago, Dedmen said: params ["_jammer","_gain"]; "_gain" here is declared as local variable, not a parameter. That's what a learned from BIKI and forum, a long time ago. You can add extra local variables in params AFTER all passed params if I'm right. Extract: "It is a good practice to make your local variables private (through private or params) in order to avoid overwriting a local variable of the same name" Why I coded like that? because, if I'm right: params ["_jammer","_gain"]; , when the only passed parameter is _jammer, is same as : params ["_jammer"]; private "_gain"; Now, til further advice, it's (probably?) better to declare a local variable (_gain here) outside of the while do loop , (in same scope, for sure). I mean, I always thought it's not a good idea declaring local variables again and again in loops. Perhaps I'm wrong. Share this post Link to post Share on other sites