obrien979 4 Posted July 12, 2019 I am having problems running a if..then..else statement. I have placed these statements in the init line of the veh1. The statement below is what I currently am using. if ((player distance veh1) < 2) then {hint "Get in vehicle"} else {hint "Goto vehicle"}; I am successful in getting the else portion to work. "Goto Vehicle" appears on screen at mission start. But as I decrease my distance to the veh1 to the point I am leaning on the vehicle, the "Get in vehicle" statement doesn't activate. I have also tried the following: _dist = player distance veh1; if (_dist < 2) then {hint "Get in Vehicle"} else {hint "Goto vehicle"}; But again no luck. I am sure it is a simple error on my part, but I am struggling. TIA Share this post Link to post Share on other sites
mr555ru 8 Posted July 12, 2019 The init code is executed only once, at the time of initialization of the object (which is at the mission start), unless you specify a loop or some other way to keep the code running until player approaches the vehicle. Share this post Link to post Share on other sites
obrien979 4 Posted July 12, 2019 2 hours ago, mr555ru said: The init code is executed only once, at the time of initialization of the object (which is at the mission start), unless you specify a loop or some other way to keep the code running until player approaches the vehicle. Thanks for the sight, now how could I do a loop? 😏 Share this post Link to post Share on other sites
killzone_kid 1331 Posted July 12, 2019 not gonna do you any good, as you will have one or the other hint displayed repeatedly 2 Share this post Link to post Share on other sites
Spatsiba 89 Posted July 12, 2019 Considering simplicity I think you could just: Create a file called "initPlayerLocal.sqf" in your root mission folder, next to "mission.sqm" etc. Create a folder called "scripts" in your root mission folder. Create another file called "getInVehicleHint.sqf" inside the "scripts" folder. //Copy paste this into "initPlayerLocal.sqf". execVM "scripts\getInVehicleHint.sqf"; //copy paste this inside getInVehicleHint.sqf //Loops. while (true) do { sleep 0.1; hintSilent "Goto vehicle"; if ((player distance veh1) < 2) then {hintSilent "Get in vehicle"}; //2 metres is quite close. I'd recommend 4 or so. //exits the loop. if (vehicle player == veh1) exitWith {}; }; Keep in mind this is a somewhat dirty way to do it and I'll probably get someone shout at me for teaching bad practice BUUUUT it is the simplest way and therefore probably the easiest to understand and begin learning from. Share this post Link to post Share on other sites
obrien979 4 Posted July 12, 2019 18 minutes ago, Spatsiba said: Considering simplicity I think you could just: Create a file called "initPlayerLocal.sqf" in your root mission folder, next to "mission.sqm" etc. Create a folder called "scripts" in your root mission folder. Create another file called "getInVehicleHint.sqf" inside the "scripts" folder. //Copy paste this into "initPlayerLocal.sqf". execVM "scripts\getInVehicleHint.sqf"; //copy paste this inside getInVehicleHint.sqf //Loops. while (true) do { sleep 0.1; hintSilent "Goto vehicle"; if ((player distance veh1) < 2) then {hintSilent "Get in vehicle"}; //2 metres is quite close. I'd recommend 4 or so. //exits the loop. if (vehicle player == veh1) exitWith {}; }; Keep in mind this is a somewhat dirty way to do it and I'll probably get someone shout at me for teaching bad practice BUUUUT it is the simplest way and therefore probably the easiest to understand and begin learning from. Would you call this via an init line on player or via a trigger...or what do you suggest? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 12, 2019 45 minutes ago, Spatsiba said: Keep in mind this is a somewhat dirty way to do it and I'll probably get someone shout at me for teaching bad practice BUUUUT it is the simplest way and therefore probably the easiest to understand and begin learning from. Well I'd go for a draw3d eventhandler and play a bit around using color and text select usage depending on distance, and also cleanly remove the EH once the player has boarded the vehicle, to give a full example. Nothing wrong with giving a quick heads up, but as you already acknowledged it's dirty. 25 minutes ago, obrien979 said: Would you call this via an init line on player or via a trigger...or what do you suggest? @Spatsiba wrote how to do it. //initPlayerLocal.sqf addMissionEventHandler ["Draw3D", { _veh = YourVehicleName;//adjust to your vehicle _pos = ((getposatl _veh) vectoradd [0,0,4]);//text will appear 4m above the vehicle _check = player distance2D _veh < (2 + sizeOf typeOf _veh); _text = ["Get Closer","Get In"] select _check; _color = [[1,0,0,1],[0,1,0,1]] select _check;//red if too far away, otherwise green drawIcon3D ["", _color, _pos, 0.8, 0.8, 0, _text, 1, 0.0315, "EtelkaMonospacePro"]; if (player in crew _veh) then {removeMissionEventhandler ["Draw3D",_thisEventhandler]};//remove the EH when the player is inside }]; Should be self explanatory, check up select on the wiki, makes most if statements obsolete, should get you started. This also keeps the hint free for debugging or other purposes, since there can only be a single hint for every frame. Cheers 2 Share this post Link to post Share on other sites
zagor64bz 1225 Posted July 12, 2019 @Grumpy Old Man Damn....you never end to surprise me with your awesome wisdom. Not only this solution is more efficient.. it is even aesthetically prettier. I'm sure you may be grumpy sometimes, but you're definitely wise, ma man. 1 Share this post Link to post Share on other sites