StowMarines / StowMarines-Community

This project manages all of the issues and recommendations that are brought up by the community. It will allow us to give a fair response to each user in a formal manner and allow users to see if an issue has already been brought up. Furthermore, it will allow leadership and other staff members the ability to track their progress on certain matters.
3 stars 0 forks source link

Replace triggers with distance checks for helipads #33

Closed markusa380 closed 3 years ago

markusa380 commented 3 years ago

It's generally regarded as good practice to use script-based distance checks instead of triggers where the latter isn't super critical - triggers run at a low interval and will cause performance hits on the server. Script-based distance checks however can be controlled to run every 5 seconds or so.

Use nearestObject to check for the closest air vehicle and if the distance between the pad and the vehicle is smaller than ~5 meters the pad is occupied.

SM-BJS commented 3 years ago

I'll look into it.

SM-BJS commented 3 years ago

I have created the script and it works with no trouble, however when you attempt to execute it upon different helipads, it's crashes the game, any suggestions?:

helipadMarker = (_this select 0);
helipad = (_this select 1);
nearObj = (getPos helipad) nearestObject "Air";
helipadPos = (getPos helipad);

[] spawn {
    while { true } do {
        if ((nearObj distance helipadPos)< 10) then {
            helipadMarker setMarkerColor "colorRed";
        }
        else {
        helipadMarker setMarkerColor "colorGreen";
        };
    };
};
SM-BJS commented 3 years ago

It should work fine with a script for each object, but it has trouble executing the script with different targets at the same time even if execute individually.

markusa380 commented 3 years ago

You forgot to add sleep in your loop, e.g. sleep 5;.

Also local variables should be named with _ prefix.

Also I doubt it's that simple in MP - you will probably have to remoteExec some stuff, but I might be wrong.

markusa380 commented 3 years ago

Also you need to calculate nearObj every loop not only in the beginning.

SM-BJS commented 3 years ago

After conversing with Markus to sort the issue, it has been fixed with the following code:

if (isServer) exitWith {

    _this spawn{
        while { true } do {
            sleep 5;
            _helipadMarker = (_this select 0);
            _helipad = (_this select 1);
            _helipadPos = (getPos _helipad);
            _nearObj = (getPos _helipad) nearestObject "Air";
            if ((_nearObj distance _helipadPos)< 10) then {
                _helipadMarker setMarkerColor "colorRed";
            }
            else {
            _helipadMarker setMarkerColor "colorGreen";
            };
        };
    };

};

@Halliwedge would you be able to give this a test and see if it works for more than one player? It's currently only on helipad 5 and 6.

SM-BJS commented 3 years ago

Tested this out with Marc on the server and works with no issues. I'm going to keep this open until Helios have thoroughly tested it on Friday.

SM-BJS commented 3 years ago

Just did some extra testing with Halli and it works fine. I will place the script on all the other helipads for mass testing this Friday.

SM-BJS commented 3 years ago

After mass testing today, no bugs were found. If you find any problems with the helipads in the future, please open a new issue.

Thanks for your help @markusa380.