Lorenz94 6 Posted December 22, 2017 Hello, I wrote a teleport script that creates a marker on a minimap where the player selected from the list currently is. I would like to create this marker dynamically each 5 seconds, to mark the updated position on map. At the moment, I'm doing this with a "while loop", and all works as expected. What I want to add is the "ability" of the script to recognize when a different selection is made from the list to end the old marker creation loop and start a new one with the new selection' position. The code below is being execVMed onLBSelChanged: Spoiler _map = ((findDisplay 16407) displayCtrl 14017); //16407= GUI, 14017= mini map _list = ((findDisplay 16407) displayCtrl 14016); //14016= Scroll list, if needed _selPlayer = objectFromNetId (lbData [14016, lbCurSel 14016]); while {!isNull (findDisplay 16407)} do { createMarkerLocal ["teleport", getPos _selPlayer]; "teleport" setMarkerTypeLocal "hd_dot"; "teleport" setMarkerColorLocal "ColorWEST"; }; _map ctrlMapAnimAdd [0, 0.075, _selPlayer]; ctrlMapAnimCommit _map; //Found until now: _ctrl lbText (lbCurSel _ctrl) to get the selection text (in my case, in format -"%1 currently on %2", name _x, mapGridPosition _x-, where _x is a list of player that satisfy certain conditions) Thank you for the help! Share this post Link to post Share on other sites
pierremgi 4740 Posted December 22, 2017 Not sure to understand your ultimate aim, but some remarks: - createMarkerLocal will create a marker where the code runs, not for all players as createMarker will do. - creating a marker with the same name as a previous one doesn't work. - you just have to refresh (loop) setMarkerPos - The markers are displayed on minimap and main map by default. You don't have to specify that. Share this post Link to post Share on other sites
Lorenz94 6 Posted December 22, 2017 7 minutes ago, pierremgi said: Not sure to understand your ultimate aim, but some remarks: - createMarkerLocal will create a marker where the code runs, not for all players as createMarker will do. - creating a marker with the same name as a previous one doesn't work. - you just have to refresh (loop) setMarkerPos - The markers are displayed on minimap and main map by default. You don't have to specify that. Yes, I got all of this! In fact, the marker needs to be seen only buy the guy who uses the teleport script. onLBSelChanged I'm deleting the local marker, so if I select "P2" from "P1", P1's marker gets deleted and what's displayed now is P2's position. The problem with looping the setMarkerPos is that if I start the while for P1 and then I switch to P2 on the list, the marker of P1's position gets deleted, but the P1 while continues running and so it continues to update ALSO P1's position on map, while (sorry for the "pun") I need only the new player's position to be marked (locally, of course). Is it more clear now? Feel free to say No! English is not my native language. Thank you. Share this post Link to post Share on other sites
Lorenz94 6 Posted December 22, 2017 @pierremgi Tried as you said, but now I get two markers, "blinking" because, as I said, the while loop continues to run for each Unit I select from the list. What I tried: Spoiler _map = ((findDisplay 16407) displayCtrl 14017); _selPlayer = objectFromNetId (lbData [14016, lbCurSel 14016]); createMarkerLocal ["teleport", [0,0,0]]; "teleport" setMarkerTypeLocal "hd_dot"; "teleport" setMarkerColorLocal "ColorOrange"; _map ctrlMapAnimAdd [0, 0.8, _selPlayer]; ctrlMapAnimCommit _map; while {!isNull (findDisplay 16407)} do { "teleport" setMarkerPos (getPos _selPlayer); sleep 5; }; What I need is a way to check if the selection (onLBSelChanged) changes.. so I can put it as a condition for the marker! Thank you. Share this post Link to post Share on other sites
Larrow 2802 Posted December 23, 2017 5 hours ago, Lorenz94 said: I would like to create this marker dynamically each 5 seconds, to mark the updated position on map. At the moment, I'm doing this with a "while loop", and all works as expected. 4 hours ago, Lorenz94 said: onLBSelChanged I'm deleting the local marker, so if I select "P2" from "P1", P1's marker gets deleted and what's displayed now is P2's position. No need for the loop and deleting the old marker. When the UI loads add a onLBSelChanged to it that either creates the marker if it does not exist OR move the marker. _list = ((findDisplay 16407) displayCtrl 14016); //14016= Scroll list, if needed _list ctrlAddEventHandler [ "LBSelChanged", { params[ "_ctrl", "_index" ]; _selPlayer = objectFromNetId ( _ctrl lbData _index ); //If marker does not exist yet if ( getMarkerPos "teleport" isEqualTo [0,0,0] ) then { //Create marker createMarkerLocal ["teleport", getPos _selPlayer]; "teleport" setMarkerTypeLocal "hd_dot"; "teleport" setMarkerColorLocal "ColorWEST"; }else{ //Move marker "teleport" setMarkerPosLocal getPos _selPlayer; }; //animate map to new position _map = ctrlParent _ctrl displayCtrl 14017; _map ctrlMapAnimAdd [0, 0.075, _selPlayer]; ctrlMapAnimCommit _map; }]; //If the list has items if ( lbSize _list > 0 ) then { //set default list index to first ( this will cause EH to fire ) _list lbSetCurSel 0; }; Share this post Link to post Share on other sites
Lorenz94 6 Posted December 23, 2017 17 hours ago, Larrow said: No need for the loop and deleting the old marker. When the UI loads add a onLBSelChanged to it that either creates the marker if it does not exist OR move the marker. Thank you Larrow for your reply. Your code does what I've obtained until now, just in a more elegant way. I created this post because what I would like to implement is a timer to update the marker if the selection does not change. Say that someone stays 30s with the first selection on the list, I would like to see the marker updating each X seconds, with no need to change selection on the list. I tried to assign a variable to the marker and put the setPosMarker under a loop interupted if that variable becomes false, but I get an error on getVariable because "teleport" (the marker), is not a valid argument to the getVariable fuction. Hoping to ha been more clear now, I thank you both again for your time! You guys are always awesome Share this post Link to post Share on other sites
Larrow 2802 Posted December 25, 2017 On 12/23/2017 at 10:20 PM, Lorenz94 said: I created this post because what I would like to implement is a timer to update the marker if the selection does not change. Say that someone stays 30s with the first selection on the list, I would like to see the marker updating each X seconds, with no need to change selection on the list. Ok I see. Something like.. (untested) _list = ((findDisplay 16407) displayCtrl 14016); //14016= Scroll list, if needed _list ctrlAddEventHandler [ "LBSelChanged", { params[ "_ctrl", "_index" ]; //If index is a valid entry ( lbSetCurSel -1 is no selection but this EH will still fire ) if ( _index > -1 ) then { //Get object from listbox data _selPlayer = objectFromNetId ( _ctrl lbData _index ); //Get reference to map ctrl _map = ctrlParent _ctrl displayCtrl 14017; //Get local teleport marker _mrk = _map getVariable[ "marker", "" ]; //If marker does not exist yet if ( _mrk isEqualTo "" ) then { //Create marker _mrk = createMarkerLocal [ "teleport", getPos _selPlayer ]; _mrk setMarkerTypeLocal "hd_dot"; _mrk setMarkerColorLocal "ColorWEST"; //Store marker on map ctrl _map setVariable[ "marker", _mrk ]; }; //Set map next update to now _map setVariable [ "nextUpdateTime", time ]; //if the map update eh has yet to be initialised if ( isNil { _map getVariable "mapEH" } ) then { //Apply Drawn EH to map and store EH ID in variable on map ctrl _map setVariable [ "mapEH", _map ctrlAddEventHandler [ "Draw", { params[ '_map' ]; //If we have reached next update time if ( time >= ( _map getVariable "nextUpdateTime" ) ) then { //Get the listbox _listbox = ctrlParent _map displayCtrl 14016; //Get current listbox index _currentIndex = lbCurSel _listBox; //Get the current selected object _followObject = objectFromNetId ( _listbox lbData _currentIndex ); //Get teleport marker _mrk = _map getVariable "marker"; //If the object still exists and is alive? if ( !isNull _followObject && { alive _followObject } ) then { //Update marker position _mrk setMarkerPosLocal getPos _followObject; //Update map position _map ctrlMapAnimAdd [0, 0.075, _followObject ]; ctrlMapAnimCommit _map; //Set next update time to 10seconds from now _map setVariable [ "nextUpdateTime", time + 10 ]; //Change this for update frequency }else{ //Otherwise //Remove the map draw EH _map ctrlRemoveEventHandler[ "Draw", _map getVariable "mapEH" ]; //Flag EH as not initialised _map setVariable[ "mapEH", nil ]; //Remove teleport marker deleteMarkerLocal _mrk; //Delete map reference to marker _map setVariable [ "marker", "" ]; //Possibly control listbox entries from here //Remove entry from listbox _listbox lbDelete _currentIndex; //Set current selection to none ( make user choose new selection ) _listbox lbSetCurSel -1; }; }; }]]; }; }; }]; //If the list has items if ( lbSize _list > 0 ) then { //set default list index to first ( this will cause EH to fire ) _list lbSetCurSel 0; }; Share this post Link to post Share on other sites
Lorenz94 6 Posted January 2, 2018 On 25/12/2017 at 4:25 AM, Larrow said: Ok I see. Something like.. (untested) //Possibly control listbox entries from here //Remove entry from listbox _listbox lbDelete _currentIndex; //Set current selection to none ( make user choose new selection ) _listbox lbSetCurSel -1; Hi Larrow, really thank you for your time, you're very kind. Your code worked fine with a very little tweaking (I wanted the map to update position only on libchange, not on each marker update, no it's all set!). Can you please explain what the above code does? All works even without it, but I can't understand why you need to delete the current selection on the list! Thank you again! Share this post Link to post Share on other sites
Larrow 2802 Posted January 2, 2018 1 hour ago, Lorenz94 said: Can you please explain what the above code does? All works even without it, but I can't understand why you need to delete the current selection on the list! As you mentioned that this is used as a teleport position, where the user can select a listed item and display it on the map via a marker and this marker keeps updating the items position. I just thought if the item no longer exists or is dead you may not want the user to be able to select it (this teleport position is out of order as the follow item is dead), so delete the listbox item and set the selection to nothing, making the user choose a new selection. Share this post Link to post Share on other sites
Lorenz94 6 Posted January 2, 2018 6 hours ago, Larrow said: As you mentioned that this is used as a teleport position, where the user can select a listed item and display it on the map via a marker and this marker keeps updating the items position. I just thought if the item no longer exists or is dead you may not want the user to be able to select it (this teleport position is out of order as the follow item is dead), so delete the listbox item and set the selection to nothing, making the user choose a new selection. Makes perfectly sense, thank you. I'm still need your magic touch on the "civilian death" script anyway! :P Have a nice day! Share this post Link to post Share on other sites