joikd 10 Posted December 16, 2012 After struggling to get this to work using nested if-then-else, switch, breakout, breakto, exitwith, and while do, I made it the long way using basic techniques that I know (I am very new at this). This long way does work, but it is very bloated. Most of the code is repeated over and over. There must be a more efficient way. I think someone who actually knows what they are doing could condense it fairly quickly. Any assistance would be greatly appreciated! private ["_nearby","_nearby5","_nearby4","_nearby3","_nearby2","_dis","_bPos","_zombiesNum","_type","_config","_canLoot","_inVehicle","_fastRun","_position","_counter"]; _inVehicle = vehicle player isKindOf "player"; _fastRun = _this select 0; _position = getPosATL player; _counter = 0; _nearby5 = count (_position nearObjects ["building",500]); if ((_nearby5 > 0) and (_nearby5 < 11)) then { _nearby = _position nearObjects ["building",500]; _counter = 1; { _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { _dis = _x distance player; _bPos = getPosATL _x; _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); if (_zombiesNum == 0) then { [_x,_fastRun] call building_spawnZombies; }; }; } forEach _nearby; }; if (_counter != 0) then { _counter = 0; } else { _nearby4 = count (_position nearObjects ["building",400]); if ((_nearby4 > 0) and (_nearby4 < 11)) then { _nearby = _position nearObjects ["building",400]; _counter = 1; { _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { _dis = _x distance player; _bPos = getPosATL _x; _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); if (_zombiesNum == 0) then { [_x,_fastRun] call building_spawnZombies; }; }; } forEach _nearby; }; }; if (_counter != 0) then { _counter = 0; } else { _nearby3 = count (_position nearObjects ["building",300]); if ((_nearby3 > 0) and (_nearby3 < 11)) then { _nearby = _position nearObjects ["building",300]; _counter = 1; { _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { _dis = _x distance player; _bPos = getPosATL _x; _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); if (_zombiesNum == 0) then { [_x,_fastRun] call building_spawnZombies; }; }; } forEach _nearby; }; }; if (_counter != 0) then { _counter = 0; } else { _nearby2 = count (_position nearObjects ["building",200]); if ((_nearby2 > 0) and (_nearby2 < 1000)) then { _nearby = _position nearObjects ["building",200]; { _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { _dis = _x distance player; _bPos = getPosATL _x; _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); if (_zombiesNum == 0) then { [_x,_fastRun] call building_spawnZombies; }; }; } forEach _nearby; }; }; Share this post Link to post Share on other sites
gc8 585 Posted December 16, 2012 use a function like this (Code not tested): SpawnCheck = { private ["_nearby","_ncount ","_distance ","_num"]; _num = _this select 0; _distance = _this select 1; _nearby = _position nearObjects ["building", _distance]; _ncount = count _nearby; if ((_ncount > 0) and (_ncount < _num )) then { _counter = 1; { _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { _dis = _x distance player; _bPos = getPosATL _x; _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); if (_zombiesNum == 0) then { [_x,_fastRun] call building_spawnZombies; }; }; } forEach _nearby; }; }; private ["_nearby","_nearby5","_nearby4","_nearby3","_nearby2","_dis","_bPos","_zombiesNum","_type","_config","_canLoot","_inVehicle","_fastRun","_position","_counter"]; _inVehicle = vehicle player isKindOf "player"; _fastRun = _this select 0; _position = getPosATL player; _counter = 0; [11,500] call SpawnCheck; if (_counter != 0) then { _counter = 0; } else { [11,400] call SpawnCheck; }; if (_counter != 0) then { _counter = 0; } else { [11,300] call SpawnCheck; }; if (_counter != 0) then { _counter = 0; } else { [1000, 200] call SpawnCheck; }; Share this post Link to post Share on other sites
joikd 10 Posted December 17, 2012 Wow, gc8!!! That works perfectly! Thank you so much! I have wasted so many hours on just this one little script. I can't believe how much you chopped off. This gives me a lot of hope that almost anything that I can think of can be done. But, it is also very discouraging as I am not anywhere near the level to do this kind of stuff, which is very frustrating since I have so many ideas. In case anyone doesn't know what this does--it fixes a huge flaw (at least I think) in DayZ where vanilla DayZ spawns zombies only out to 200 no matter what. I know one of the reasons was because a higher range was too much for the game to handle (too much spawning at once). Well, this allows the range to be larger, but will scale it back if there is too many spawn points. This takes care of one of the major flaws with zombies. I will now move on to the next one. I know DayZ might not be the most popular topic around here, but thank you for sharing your expertise. I appreciate the time and effort. Share this post Link to post Share on other sites
joikd 10 Posted December 18, 2012 It looks like "building" includes many more non-spawning buildings than I would have thought. I see now how important it is to filter those out with (from above): _type = typeOf _x; _config = configFile >> "CfgBuildingLoot" >> _type; _canLoot = isClass (_config); if (_canLoot) then { The in-game result of this, though, is that the spawn range is greatly reduced near industrial areas because of the many non-spawning "building"s (cargo containers maybe?). This can be overcome by raising the amount of "building"s checked per range, but then it is too demanding in non-industrial areas. Is there are way to pre-filter the "buildings"s that actually spawn, or not count those that are found that do not spawn? I tried replacing "building" with "CfgBuildingLoot", but that did not work. Maybe there is a way to replace "building" with all of the "CfgBuildingLoot" individual subclasses, or group those subclasses into something that can be used with nearObjects? Once again, any assistance would be greatly appreciated. Share this post Link to post Share on other sites