Jump to content
MMAXIMUSS

Spawning with onmapsingleclick

Recommended Posts

How are you doing? Fine I hope. 

 

I'm trying to have my vehicles spawned at a selected location. I can't use openMap because the menu -already opened- blocks it, I think. So it would be cool that when I open my map after closing the menu and click on a position, the vehicle will spawn there. Any idea?

 

case 36: { // minigun boat (Armed) if (commandpointsblu1 >= 5) then { hint "Vehicle ready ! Exit and click on the map to deliver it!";

commandpointsblu1 = commandpointsblu1 - 5;

ctrlSetText [1000, format["%1",commandpointsblu1]];

onMapSingleClick { vehic = "B_Boat_Armed_01_minigun_F" createVehicle _pos; };

};

} else { hint "Not enough command points";

};

};

 

Thanks!

Share this post


Link to post
Share on other sites

Use addMissionEventHandler:

ClickOnMapEH = addMissionEventHandler ["MapSingleClick", {_pos = (_this select 1); /* YOUR CODE */; removeMissionEventHandler ["MapSingleClick",ClickOnMapEH];}];

Or:

closeDialog; // Closes your dialog
sleep 0.01; // Needs time to close
openMap true; // Opens map
_mapEH = addMissionEventHandler ["MapSingleClick", {_pos = _this select 1; /* YOUR CODE */; openMap false;}];
waitUntil {!visibleMap}; // Wait until map is closed, either by ESC/M or map click
removeMissionEventHandler ["MapSingleClick",_mapEH]; // removes eventhandler so it doesn´t stack and spawn more than one vehicle
// And if you want to open your dialog again:
createDialog "yourDialog";

The second option is a bit more elegant since you don't have to use a global variable. The mission eventhandler doesn't have any effect on the engine behaviour in contrast to onMapSingleClick.

  • Like 1

Share this post


Link to post
Share on other sites

Wow thanks! So 

case 36: { // minigun boat (Armed) 
if (commandpointsblu1 >= 5) then { hint "Vehicle ready ! Click on the map to deliver it!";
commandpointsblu1 = commandpointsblu1 - 5;
ctrlSetText [1000, format["%1",commandpointsblu1]];
closeDialog; // Closes your dialog
sleep 0.01; // Needs time to close
openMap true; // Opens map
_mapEH = addMissionEventHandler ["MapSingleClick", {_pos = _this select 1; vehic = "B_Boat_Armed_01_minigun_F" createVehicle _pos; openMap false;}];
waitUntil {!visibleMap}; // Wait until map is closed, either by ESC/M or map click
removeMissionEventHandler ["MapSingleClick",_mapEH]; // removes eventhandler so it doesn´t stack and spawn more than one vehicle};
};
} else { hint "Not enough command points";
};
};

Would solve all my "misery"? 

Share this post


Link to post
Share on other sites

Well this won't solve your problems with depressions, money and stress. :S

Tbh I didn't explicitly test how it works with a dialog, but I have done something similar in the past.

The code I tested:

openMap true;
_mapEH = addMissionEventHandler ["MapSingleClick", {player setPos (_this select 1); openMap false;}];
waitUntil {!visibleMap};
removeMissionEventHandler ["MapSingleClick",_mapEH];
systemChat "End";

 

Just now, MMAXIMUSS said:

ctrlSetText [1000, format["%1",commandpointsblu1]];

Leave out that part. It's just a waste of resources since the dialog is instantly closed.

 

 

Share this post


Link to post
Share on other sites

hahahaha, true... Wouldn't it be nice if we could code our lives ;-). Thanks a ton! I will test this in some hours.

  • Like 1

Share this post


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

hahahaha, true... Wouldn't it be nice if we could code our lives ;-). Thanks a ton! I will test this in some hours.

What for? Be teleported naked on a battlefield and wait to be respwaned many times a day?

  • Like 1

Share this post


Link to post
Share on other sites
20 hours ago, pierremgi said:

What for? Be teleported naked on a battlefield and wait to be respwaned many times a day?

 

If that is what you would like to do, I won't judge.... :f: 

 

22 hours ago, 7erra said:

Well this won't solve your problems with depressions, money and stress. :S

Tbh I didn't explicitly test how it works with a dialog, but I have done something similar in the past.

The code I tested:


openMap true;
_mapEH = addMissionEventHandler ["MapSingleClick", {player setPos (_this select 1); openMap false;}];
waitUntil {!visibleMap};
removeMissionEventHandler ["MapSingleClick",_mapEH];
systemChat "End";

 

Leave out that part. It's just a waste of resources since the dialog is instantly closed.

 

 

 

I tried the code but no luck. Nothing happens, map doesn't even open. I'm trying for over 3 weeks now, maybe I should give up. Thanks for the support though! 

Share this post


Link to post
Share on other sites
21 hours ago, pierremgi said:

What for? Be teleported naked on a battlefield and wait to be respwaned many times a day?

I like the sound of a anti material rifle  as a hand, so whenever I high-five someone it makes quite the epic sound.

52 minutes ago, MMAXIMUSS said:

I tried the code but no luck. Nothing happens, map doesn't even open. I'm trying for over 3 weeks now, maybe I should give up. Thanks for the support though! 

What do you mean the map doesn't even open? You mean that you can't open the map? Or that the above code isn't working in combination with?

Share this post


Link to post
Share on other sites

To open the map:

  openmap [true,false];
  titleText["Select Map Position", "PLAIN"];

then:

 onMapSingleClick "
    some stringed code here;
    openmap [false,false];
    onMapSingleClick ' ';
   false
"

The stackable version MEH is not very useful in this case (click on map). You just have to "stringify" your code, like here.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you all for your help! I'm away from home during the week, but I will test it all on Friday. And show you a clip ;). Thanks again for the persistence! 

Share this post


Link to post
Share on other sites

Hey again :) 

 

To be sure, is this the way? (case 36)

Spoiler

_index = lbCurSel 2102;


_spawnPos = getpos player;
_spawnPos = [(_spawnPos select 0)+30, _spawnPos select 1];

addEWS_EH = {
    (_this select 0) addEventHandler ["IncomingMissile", {
        _target = _this select 0;
        _attacker = _this select 3;

        if(player in crew (_target)) then {
            _target say3D ["alarmCar", 2, 1];
            _azi = (_target) getDir (_attacker);

            titleText [format["Incoming Missile: Bearing %1", str floor _azi], "PLAIN", 0.4];
        };
    }];
};

vehic = nil;

switch (_index) do {
    case 0: { // Small Truck 1
        if (commandpointsblu1 >= 4) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 4;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "I_G_Offroad_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 1: { // Small Truck 2
        if (commandpointsblu1 >= 6) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 6;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "I_G_Van_01_transport_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 2: { // Prowler Unarmed
        if (commandpointsblu1 >= 5) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 5;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_LSV_01_unarmed_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 3: { // Prowler Armed
        if (commandpointsblu1 >= 13) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 13;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_LSV_01_armed_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 4: { // Hunter Unarmed
        if (commandpointsblu1 >= 5) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 5;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MRAP_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 5: { // Hunter HMG
        if (commandpointsblu1 >= 18) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 18;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MRAP_01_hmg_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 6: { // Hunter GMG
        if (commandpointsblu1 >= 25) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 25;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MRAP_01_gmg_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 7: { // Marshall
        if (commandpointsblu1 >= 35) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 35;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_APC_Wheeled_01_cannon_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 8: { //HEMETT Transport Covered
        if (commandpointsblu1 >= 8) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 8;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Truck_01_covered_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 9: { // Pawnee
        if (commandpointsblu1 >= 25) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 25;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Heli_Light_01_armed_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 10: { // Blackfoot
        if (commandpointsblu1 >= 45) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 45;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Heli_Attack_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 11: { // HummingBird
        if (commandpointsblu1 >= 15) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 15;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Heli_Light_01_F" createVehicle [ _spawnPos, [100]];
        } else {
            hint "Not enough command points";
        };
    };
    case 12: { // M-900 Civ.
        if (commandpointsblu1 >= 12) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 12;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "C_Heli_Light_01_civil_F" createVehicle _spawnPos;
            vehic setVariable ["color",13];
        } else {
            hint "Not enough command points";
        };
    };
    case 13: { // Taru Empty
        if (commandpointsblu1 >= 18) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 18;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "O_Heli_Transport_04_F" createVehicle _spawnPos;
            null = [vehic] execVM "\a3\Air_F_Heli\Heli_Transport_04\Scripts\Heli_Transport_04_basic_black.sqf";
        } else {
            hint "Not enough command points";
        };
    };
    case 14: { // GhostHawk
        if (commandpointsblu1 >= 22) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 22;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Heli_Transport_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 15: { // Huron
        if (commandpointsblu1 >= 26) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 26;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Heli_Transport_03_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 16: { // Panther IFV
        if (commandpointsblu1 >= 25) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 25;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_APC_Tracked_01_rcws_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 17: { // ATV Quad
        if (commandpointsblu1 >= 1) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 1;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Quadbike_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 18: { // Cheetah AA
        if (commandpointsblu1 >= 30) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 30;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_APC_Tracked_01_AA_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 19: { // Slammer
        if (commandpointsblu1 >= 40) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 40;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MBT_01_cannon_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 20: { // Bobcat
        if (commandpointsblu1 >= 28) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 28;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_APC_Tracked_01_CRV_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 21: { // SF SUV
        if (commandpointsblu1 >= 2) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 2;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "C_Offroad_01_F" createVehicle _spawnPos;
            sleep 1;
            vehic setObjectTexture [0, "#(argb,8,8,3)color(0.141,0.118,0.082,1)"];
            vehic animate ["Hidepolice", 1];
            vehic animate ["Hideservices", 1];
            vehic animate ["Hidebackpacks", 0];
            vehic animate ["Hidebumper1", 0];
            vehic animate ["Hidebumper2", 0];
            vehic animate ["Hideconstruction", 0];
            vehic animate ["Hidedoor1", 1];
            vehic animate ["Hidedoor2", 1];
            vehic animate ["Hidedoor3", 1];
            vehic animate ["Hideglass2", 1];
        } else {
            hint "Not enough command points";
        };
    };
    case 22: { // MLRS Artillery
        if (commandpointsblu1 >= 75) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 75;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MBT_01_mlrs_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 23: { // Scorcher Artillery
        if (commandpointsblu1 >= 75) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 75;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MBT_01_arty_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 24: { // Fuel Truck 
        if (commandpointsblu1 >= 10) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 10;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Truck_01_fuel_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 25: { // Wipeout CAS
        if (commandpointsblu1 >= 45) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 45;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Plane_CAS_01_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 26: { // Slammer Urban Purpose
        if (commandpointsblu1 >= 40) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 40;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_MBT_01_TUSK_F" createVehicle _spawnPos;
            [vehic] remoteExec ["addEWS_EH", 0, true];
        } else {
            hint "Not enough command points";
        };
    };
    case 27: { // Stomper RCWS
        if (commandpointsblu1 >= 20) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 20;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UGV_01_rcws_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 28: { // Stomper Scout
        if (commandpointsblu1 >= 10) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 10;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UGV_01_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 29: { // Greyhawk ATG
        if (commandpointsblu1 >= 15) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 15;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UAV_02_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 30: { // Greyhawk CAS
        if (commandpointsblu1 >= 15) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 15;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UAV_02_CAS_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 31: { // MQ-12 Falcon
        if (commandpointsblu1 >= 15) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 15;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_UAV_03_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 32: { // Darter UAV
        if (commandpointsblu1 >= 5) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 5;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UAV_01_F" createVehicle _spawnPos; createVehicleCrew vehic;
        } else {
            hint "Not enough command points";
        };
    };
    case 33: { // Blackfish (Infantry)
        if (commandpointsblu1 >= 40) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 40;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_VTOL_01_infantry_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 34: { // Blackfish (Vehicle)
        if (commandpointsblu1 >= 40) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 40;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_VTOL_01vehicle_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 35: { // Blackfish (Armed)
        if (commandpointsblu1 >= 45) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 45;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_T_VTOL_01_armed_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
    };
    case 36: { // minigun boat (Armed) 
        if (commandpointsblu1 >= 5) then { 
        hint "Vehicle ready ! Click on the map to deliver it!";
        commandpointsblu1 = commandpointsblu1 - 5;
        ctrlSetText [1000, format["%1",commandpointsblu1]];
        openmap [true,false];
         titleText["Select Map Position", "PLAIN"];
          onMapSingleClick "vehic = "B_Boat_Armed_01_minigun_F" createVehicle _pos;
        openmap [false,false];
        onMapSingleClick ' ';
   false"
    } else { hint "Not enough command points";
    };
  };
    case 37: { // Y-32 (vehicle)
        if (commandpointsblu1 >= 40) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 40;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "O_T_VTOL_02_vehicle_grey_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
     };
    case 38: { // Rearm truck
        if (commandpointsblu1 >= 20) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 20;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
               vehic = "B_Truck_01_ammo_F" createVehicle _pos;
        } else {
            hint "Not enough command points";
        };
     };
     case 39: { // Repair truck
        if (commandpointsblu1 >= 20) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 20;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_Truck_01_Repair_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
     };
     case 40: { // Hellcat
        if (commandpointsblu1 >= 25) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 25;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "I_Heli_light_03_unarmed_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
     };
     case 41: { // Sentinel
        if (commandpointsblu1 >= 20) then {
            hint "Vehicle ready !";
            commandpointsblu1 = commandpointsblu1 - 20;
            ctrlSetText [1000, format["%1",commandpointsblu1]];
            vehic = "B_UAV_05_F" createVehicle _spawnPos;
        } else {
            hint "Not enough command points";
        };
     };
};
vehic = nil;
publicVariable "commandpointsblu1";
//hint format["index: %1",_index];

 

Much respect for coding pro's...

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

×