Alpine_gremlin 13 Posted October 7, 2017 Hey guys! So I`m just trying to run a simple check to see if the player is a certain distance from a building: _playerPos = position player; _nearestBuilding = nearestBuilding player; _meters = _playerPos distance _nearestBuilding; if (_meters < 6.5) then { systemChat format ["%1 is inside", name player]; sleep 0.1; }; Unfortunately nothing shows up in system chat and I get no error messages. I executed the script from init.sqf. Anyone have an idea what I`m missing? EDIT: When called from a radio trigger while conditions are met, the message pops up. However I would like the script to run continually and show the text when conditions are actively met. Share this post Link to post Share on other sites
pierremgi 4890 Posted October 7, 2017 Your code isn't a loop! so, run once and bye bye! Too bad if there is no player closer than 6.5 m from the center of a building (yes, center). nearestBuilding is not a fine command. Some map buildings are missing and all edited buildings are not returned by this command (use nearestObject instead) If you want to quickly see what buildings work, just run: addMissionEventHandler ["draw3D", { drawIcon3D ["A3\ui_f\data\map\VehicleIcons\iconexplosiveat_ca.paa", [1,0,0,1], nearestbuilding player ,1,1,360,"",0, 1,"EtelkaMonospacePro"] }]; Watch for the red dot. Share this post Link to post Share on other sites
Sgt. Dennenboom 98 Posted October 7, 2017 So your script in an infinite loop could look something like this: _distance = 6.5; while {true} do { if (count (nearestObjects [player,["House","Building"],_distance]) > 0) then { systemChat format ["%1 is inside",name player]; }; sleep 0.1; }; There are also different ways of checking whether a player is inside a building. Killzone Kid made a nice and much more accurate check for whether the player is in a house on this wiki page: lineIntersectsSurfaces Share this post Link to post Share on other sites
Alpine_gremlin 13 Posted October 8, 2017 Thanks guys! I got it to work perfectly! Share this post Link to post Share on other sites
Tajin 349 Posted October 9, 2017 If you want to save some performance while comparing 2 distances, then use distanceSqr instead of distance. You'll just have to change 6.5 to its square. That way the engine doesn't have to calculate the squareroot. Use "distance" only if you need to show the actual distance to the player. Share this post Link to post Share on other sites
Tankbuster 1746 Posted October 9, 2017 Distance2d is a lot quicker than distance and marginally quicker than distancesqr and it doesn't require extra maths afterwards Share this post Link to post Share on other sites