Jump to content
Sign in to follow this  
ColonelKernel

Execute scripts when map is open

Recommended Posts

Hi.

How can I make a script run when the map is opened? I tried this but it doesn't work:

While {visibleMap} do {

 

Share this post


Link to post
Share on other sites
addMissionEventHandler
[	"Map",
	{	params ["_isOpened","_isForced"];
		// do what you want
	}
];

 

Share this post


Link to post
Share on other sites
16 minutes ago, Lucullus said:

addMissionEventHandler
[	"Map",
	{	params ["_isOpened","_isForced"];
		// do what you want
	}
];

 

Thanks for your reply.

This is what I'm trying to do:

0 = [] spawn {
addMissionEventHandler
[	"Map",
	{   params ["_isOpened","_isForced"];
	While {true} do {
     _allVehs = player nearobjects ["allvehicles", 1000];
     _allEmptyVehs = _allVehs select {{alive _x} count crew _x == 0};
     {
	 player forgettarget _x;
     sleep 0.1;
	 player reveal _x;
     } foreach _allEmptyVehs;
  sleep 3;
  };
	}
];
};

What you told me to do does work but the game lags for a few seconds and then gives me generic errors. Any idea what's wrong?

Share this post


Link to post
Share on other sites

Why this code? forgetTarget then reveal ?

 

Note: read:   _allEmptyVehs = _allVehs select {alive _x && count crew _x == 0};

 

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

Why this code? forgetTarget then reveal ?

 

Note: read:   _allEmptyVehs = _allVehs select {alive _x && count crew _x == 0};

 

It's because I want the position of the empty vehicles to be updated on the map. More on that in this topic:

 

Share this post


Link to post
Share on other sites
2 hours ago, ColonelKernel said:

It's because I want the position of the empty vehicles to be updated on the map. More on that in this topic:

 

Hey, I think empty vehicles won't be able to move by themselves, if somebody or AI take it then it's not empty anymore.


I like the idea of "scanning vehicles and showed it on the map", but I'll rather use much simpler noob approach.

Btw, I placed several vehicles in Stratis Agia Marina and found "reveal" command won't actually reveal all vehicles in the given region. Did u manage to get all vehicles showed on map?
However I get everything showed up when using marker.

 

Share this post


Link to post
Share on other sites

Hi, this is a noob version of the script. As a noob, I can't get it working with "reveal" command, so I replace it with marker.

init.sqf :

_id = addMissionEventHandler ["Map", {_this execVM "placeVehMarker.sqf"} ];

 


placeVehMarker.sqf :
 

_allVehs = player nearObjects ["allVehicles", 1000];
_allEmptyVehs = _allVehs select { (alive _x) && (count crew _x == 0) };

{
    _vehMarker = str _x;
    deleteMarkerLocal _vehMarker;
    _vehMarker = createMarkerLocal [_vehMarker, getPos _x];
    if (_x isKindOf "Land") then { _vehMarker setMarkerTypeLocal "c_car"; _vehMarker setMarkerColorLocal("ColorBlue"); };
    if (_x isKindOf "Tank") then { _vehMarker setMarkerTypeLocal "b_armor"; _vehMarker setMarkerColorLocal("ColorRed"); };
    if (_x isKindOf "Ship") then { _vehMarker setMarkerTypeLocal "c_ship"; _vehMarker setMarkerColorLocal("ColorYellow"); };
    if (_x isKindOf "Air") then {    _vehMarker setMarkerTypeLocal "o_air"; _vehMarker setMarkerColorLocal("ColorGreen"); };
    _vehMarker setMarkerSizeLocal [1, 1];
} forEach _allEmptyVehs;
 

  • Like 1

Share this post


Link to post
Share on other sites
On 8/18/2017 at 8:42 PM, pierremgi said:

Note: read:   _allEmptyVehs = _allVehs select {alive _x && count crew _x == 0};

This checks that the vehicle is alive (i.e not damaged) and empty, but I was aiming for it to be empty not counting the dead crew (or at least that's what I believe I have done!). I think the dead crew inside vehicles make them non-empty. (I recall somebody saying that in a post)

Edit: Found it (it's for Arma 2 but I believe it's the same for Arma 3):

 

Share this post


Link to post
Share on other sites
23 hours ago, palatine said:

Hi, this is a noob version of the script. As a noob, I can't get it working with "reveal" command, so I replace it with marker.

init.sqf :

_id = addMissionEventHandler ["Map", {_this execVM "placeVehMarker.sqf"} ];

 


placeVehMarker.sqf :
 

_allVehs = player nearObjects ["allVehicles", 1000];
_allEmptyVehs = _allVehs select { (alive _x) && (count crew _x == 0) };

{
    _vehMarker = str _x;
    deleteMarkerLocal _vehMarker;
    _vehMarker = createMarkerLocal [_vehMarker, getPos _x];
    if (_x isKindOf "Land") then { _vehMarker setMarkerTypeLocal "c_car"; _vehMarker setMarkerColorLocal("ColorBlue"); };
    if (_x isKindOf "Tank") then { _vehMarker setMarkerTypeLocal "b_armor"; _vehMarker setMarkerColorLocal("ColorRed"); };
    if (_x isKindOf "Ship") then { _vehMarker setMarkerTypeLocal "c_ship"; _vehMarker setMarkerColorLocal("ColorYellow"); };
    if (_x isKindOf "Air") then {    _vehMarker setMarkerTypeLocal "o_air"; _vehMarker setMarkerColorLocal("ColorGreen"); };
    _vehMarker setMarkerSizeLocal [1, 1];
} forEach _allEmptyVehs;
 

I appreciate the time you spent writing this. But like I said before, the purpose of the reveal command is for the vehicles to be known to my squad mates so that I can order them to get in without pointing at the vehicle or use the clunky Mount (key 4) menu.

Thank you all the same.

Share this post


Link to post
Share on other sites

Since this is related to this thread, I'll post this again here:

Quote

I did find a way (which is kind of silly!) ....:

0 = [] spawn {
    While {true} do {
  
  {
     waitUntil {visibleMap};
     _allVehs = _x nearobjects ["allvehicles", 800];
     _allEmptyVehs = _allVehs select {{alive _x} count crew _x == 0};
     {
     player forgettarget _x;
     player reveal _x;
     } foreach _allEmptyVehs;
     } foreach units group player;
    sleep 2;
    waitUntil {shownMap};
    };
};

The red text does what the topic says.

Share this post


Link to post
Share on other sites
On 8/18/2017 at 11:51 PM, palatine said:

Btw, I placed several vehicles in Stratis Agia Marina and found "reveal" command won't actually reveal all vehicles in the given region

You're right. Some vehicles don't get revealed (like the humming bird).

Share this post


Link to post
Share on other sites
3 hours ago, ColonelKernel said:

Since this is related to this thread, I'll post this again here:

The red text does what the topic says.

 

Hey bro, you don't need that clunky "while do wait until in EH" - just to reveal empty vehicles on map.
Those empty vehicles wont move anywhere so you don't need to run the script over and over to update its position.

It might be a different story if you want to track the movement all vehicles (not empty one) real time on map.

All you need is execute the mission event handler, so everytime you open the map the code executed.
The sample code I gave you do the trick.I've adopted it into my own addons and run the code with over 400 empty vehicles on map.

 

 

3 hours ago, ColonelKernel said:

I appreciate the time you spent writing this.

 

No worries, I like the idea of displaying empty vehicles on the map. I have adopted this into my own addons. This will help a lot during zombie missions. :D

 

 

3 hours ago, ColonelKernel said:

But like I said before, the purpose of the reveal command is for the vehicles to be known to my squad mates so that I can order them to get in without pointing at the vehicle or use the clunky Mount (key 4) menu.

 

Then you can add the "reveal" command back into the code, just replace those markers with reveal.
The point is you dont need any "while do" just to do the work described in this thread.

 

Anyway good luck for your quest. :)

Share this post


Link to post
Share on other sites
19 hours ago, palatine said:

Those empty vehicles wont move anywhere so you don't need to run the script over and over to update its position.

It might be a different story if you want to track the movement all vehicles (not empty one) real time on map.

What you say is true in most scenarios. But not all.

Consider a case where the vehicle crew disembark their assigned vehicle. Then for your code to work you have to close the map and reopen it. Of course it's not that big an issue but I was looking to polish my code a little bit! (of course to the professional it may not be polished at all but for a noob like me that's as good as it gets!)

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
Sign in to follow this  

×