Jump to content

Recommended Posts

I want to make a new item that would display distance in meters to three objects placed on map, named c1, c2 and c3.

If any of players would have that classname ("item_locator") it would show up when the map is open this distance written in top left corner? How do I do that?

 

Script I have so far, but uses a hint and that is not optimal for multiplayer environment, as I want the item owner to be the only one with that information displayed?


// Define the player and the objects
private _player = player;
private _obj1 = c1;
private _obj2 = c2;
private _obj3 = c3;

// Check if the player has the item "case_locator"
if ([_player, "case_locator"] call BIS_fnc_invHasItem) then {
    // Get the distances to the objects
    private _dist1 = _player distance _obj1;
    private _dist2 = _player distance _obj2;
    private _dist3 = _player distance _obj3;

    // Display the distances as hints
    hint format [
        "Distances to objects:\nObject 1 (c1): %1 meters\nObject 2 (c2): %2 meters\nObject 3 (c3): %3 meters", 
        round _dist1, 
        round _dist2, 
        round _dist3
    ];
} else {
    hint "You don't have the case_locator item!";
};

Share this post


Link to post
Share on other sites

If you just need such hint when map is open, add, in initPlayerLocal.sqf (or else):


 

addMissionEventHandler ["Map", {
  params ["_opened", "_forced"];
  if (_opened) then {
    if ([player, "case_locator"] call BIS_fnc_invHasItem) then {
      private _dist1 = player distance c1;
      private _dist2 = player distance c2;
      private _dist3 = player distance c3;
      hint format [
        "Distances to objects:\nObject 1 (c1): %1 meters\nObject 2 (c2): %2 meters\nObject 3 (c3): %3 meters",  
        round _dist1,  
        round _dist2,  
        round _dist3
      ];
    } else {
      hint "You don't have the case_locator item!";
    };
  } else {hint ""};
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×