quantenfrik 10 Posted June 10, 2014 hello, I need to get the location of the cursor so I can use it in ctrlMapScreenToWorld. I can get it as a hint by writing onMouseButtonDown = hint format ["%1\n%2", _this select 2, _this select 3]; in my dialogs.hpp, but how can I run it in a script so that I can assign it to a variable? I've tried to mess around with DisplayAddEventHandler, but I don't understand how they work at all. Anybody got an idea? Thanks in advance Share this post Link to post Share on other sites
quantenfrik 10 Posted June 10, 2014 found a solution: disableSerialization; //reduces errors _location = findDisplay 1200; //accesses the dialog _ctrl2 = _location displayCtrl 1300; //accesses the map control box, assigns it to ctrl2, which is control "object" _varx = _ctrl2 ctrlSetEventHandler ["MouseButtonDown","if (true) then { _location = findDisplay 1200; _ctrl2 = _location displayCtrl 1300; _varx2 = (_this select 2); _varx3 = (_this select 3); _position = _ctrl2 ctrlMapScreenToWorld [_varx2, _varx3]; _dialog = findDisplay 1200; _ctrl = _dialog displayCtrl 1000; _ctrl ctrlSetText format ['pos: %1', _position]; }"]; Share this post Link to post Share on other sites
ghost_nic 10 Posted June 18, 2014 Following on the above, I am trying to hint the real-time distance from the map cursor to the player while in map view. From various posts on the forums I have derived the code below which runs but outputs incorrect and erratic distances that are affected by speed of mouse movement, zoom etc. I have tried MouseMoving, MouseHolding & MouseButtonDown EH's all with the same problem. I would appreciate some help in getting this to work. openMap [true, false]; waitUntil {!(isNull (findDisplay 12))}; _index = (findDisplay 12) displayAddEventHandler [ "MouseMoving", " _WorldCoord = ((_this select 0) displayCtrl 51) ctrlMapScreenToWorld [_this select 1,_this select 2]; _WorldCoord = round(_WorldCoord distance player); hint str _WorldCoord; " ]; Share this post Link to post Share on other sites
Master85 1 Posted June 18, 2014 added to a display "MouseMoving" will return delta positions - i.e. the difference to the last position when added to a control it will return the position relative to the control - i.e. no delta positions so just add the eventhandler with ctrlAddEventHandler to the map control itself: openMap [true, false]; waitUntil {!(isNull (findDisplay 12))}; _index = ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler [ "MouseMoving", { _WorldCoord = (_this select 0) ctrlMapScreenToWorld [_this select 1,_this select 2]; _WorldCoord = round(_WorldCoord distance player); hintSilent str _WorldCoord; } ]; Share this post Link to post Share on other sites
ghost_nic 10 Posted June 18, 2014 thx, so the point of reference for the EH makes all the difference and adds more functionality :cool: Share this post Link to post Share on other sites