Porky243 1 Posted April 2, 2013 Hello soldiers, now I can finally open up a new Thread on my own. I am kind of in need of some help with a script I wrote for a mission I created. I wanted the players in a mp game to be able to request a dynamic heli transport, like the one possible with the new Support Module. The steps should be to mark the exfiltration area with a green smoke grenade in order for a heli to show up, pick up the requester and take him to wherever he wants to. I found many perfectly working scripts out there, but none of them was working as I wanted i.e. acting dynamically without pre-placing markers or anything like that on the mission. So I tried to do it myself. After hours of headache producing trial and error I made a script that works perfectly on singleplayer tests. Yesterday I implemented it into my mp mission and tried it out with some friends, while the first test was a success, it somehow got screwed up later on in the mission ( No dedicated server, another player was hosting), like the pilot arrived, but didn't take off again and so on. I never finished any script in arma or arma 2, but now I had this Idea, and I really wanted to get it done. I looked at some similar scripts to learn the parts that confused me till then. I literally ate the BisWiki and countless sites. I know this script (s) still need some basic tweaking in order to function properly (for example I still need to implement an Alive check so the heli won't grow old upon sudden player death) but for now I just want to learn how it works to get this into multiplayer properly so the functions won't interfere with each other if multiple players kick off that script at the same time and things like that. And of course I do appreciate any advices and hints to improve the script's mechanics aswell. By the way I'm german and to make it easier for my friends, the hints and chat messages in this script are german aswell, but I rewrote the comments so you guys will know whats going on. I even added comments on almost any line just in case someone who is still learning stumbles upon my script. I noticed some complex scripts don't have many explanations in them what makes them hard to understand for a newbie like me. I put in information on any line so its easy to understand what I did there. So here is the script that uses the fired eventhandler: Smoke2.sqf /////////////////////////////////////////////////////////// ////// Script Green_Smoke_Detect by Porky243 /////// ////// Checks if green smoke nade has been /////// ////// thrown and starts heli exfiltration /////// /////////////////////////////////////////////////////////// //Assign variables //player addEventHandler ["fired",{_this execvm "smoke2.sqf"}] ///// Eventhandler - passed array is [unit, weapon, muzzle, mode, ammo, magazine, projectile] _shooter = _this Select 0; ///// Player who triggers the Eventhandler _ammotype = _this Select 4; ///// Used Ammo Type - A Green Smoke Grenade in this case _thrownnade = _this select 6; ///// Fired object, Green Smoke Grenade in this case ///// if (_ammotype == "SmokeShellGreen") then ///// Check if fired ammo was a Green Smoke Grenade { _shooter removeEventhandler ["fired",0]; sleep 2; ///// Remove Eventhandler to prevent mutliple triggin by spamming smokes Hint "Position ist markiert, CAS ist in Bewegung"; ///// Show a hint _LZ = getPos _thrownnade; ///// Position of thrown smoke grenade _Helipad = "Land_Helipadempty_F" createVehicle _LZ; ///// spawns invisible helipad on smoke grenade for better heli landing _handle = [_shooter,_Helipad,_LZ] execVM "CAS.sqf"; ///// start the heli spawn and exfil script }; else exitWith {}; And the main script CAS.sqf /////////////////////////////////////////////////////////// ////// Script CAS - Come and Rescue by Porky243 /////// ////// spawns heli to pick up player /////// /////////////////////////////////////////////////////////// //Assign variables _shooter = _this select 0; ///// player running script from smoke2.sqf _helipad = _this select 1; ///// In Smoke2.sqf created helipad _lz = _this select 2; ///// position of helipad _spawnpos = (getpos _helipad); ///// helipad position (unneccessary due to _lz, but I was too lazy to change yet) _angle = random 360; ///// Angle from wich heli will approach (random direction) _distance = 1000; ///// distance between heli spawnpoint and created helipad - 1000m _pos1 =[(_spawnpos select 0) + _distance*(cos _angle),(_spawnpos select 1) + _distance*(sin _angle), 500]; ///// line to pick a random direction and angle for spawn //create group for heli _heligrp = createGroup WEST; ///// A group is needed for the Bis function called below //spawn heli sleep 3; ///// A 3 second delay ( not really neccessary I think) _veh = [_pos1,random 360,"lb_black", _heligrp] call BIS_fnc_spawnVehicle; ///// Function to spawn a Black Little Bird (MH9) with the random direction _helicrew = _veh select 1; ///// pick the helicrew from the Array the Bis Function returns [Vehicle,Crew,Group] _heli = _veh select 0; ///// pick the heli itself from the Array {_x allowdamage false} foreach _helicrew; ///// get those pilots immortal ( may be removed later on) //land in lz _wp1 = _heligrp addWaypoint [_lz, 0]; ///// add a waypoint for the helicrew to the helipad created by the smokegrenade _wp1 setWaypointType "MOVE"; ///// set the waypoint type to move _wp1 setWaypointBehaviour "CARELESS"; ///// set the Behaviour of the crew to careless, so they won't act stupid upon enemy fire _wp1 setWaypointStatements ["true", "(vehicle this) land 'GET IN'"]; ///// give them a statement upon reach to land for the requester to get in //wait until requester is in heli waitUntil {_shooter in _heli}; //Heli vehicle chat - Pick destination on map _heli vehicleChat "Wählen Sie Ihren Zielpunkt durch einen Klick auf die Karte."; ///// Vehicle chat showing message "Pick your target by clicking the map // pick destination - create helipad on destination mapclick = false; ///// Global variable mapclick to use for checking if clicked sleep 0,5; ///// Wait 0,5 seconds between showing message and auto opening map openmap true; ///// Open the map onMapSingleClick "_tz = 'Land_Helipadempty_F' createVehicle _pos; mapclick = true;TGPOS = _pos;TZ = _tz; onMapSingleClick '', true;"; /////Create a Helipad on clicked position, turn the variable mapclick to true waitUntil {mapclick}; ///// and make _tz and _pos global // Wait for the mapclick sleep 0,5; ///// wait another 0,5 seconds before auto closing the map openmap false; ///// close the map again _heli vehicleChat "Zielkoordinaten eingetragen, sind auf dem weg."; ///// Heli says "Target coordinates received, we are oscar mike" sleep 1; ///// wait another second // set heli waypoint on destination _wp2 = _heligrp addWaypoint [TGPOS, 0]; ///// adding waypoint to the created helipad - destination _wp2 setWaypointType "MOVE"; ///// setting waypoint type to move _wp2 setWaypointBehaviour "CARELESS"; ///// giving orders to ignore any enemy contact by acting careless _wp2 setWaypointStatements ["true", "(vehicle this) land 'GET OUT'"]; ///// giving a statement to get the heli in landing position for disembark sleep 10; ///// Wait 10 seconds for next script line so it won't trigger right before the heli takes off //wait for player to leave heli waitUntil {(getposATL _heli select 2) < 1}; ///// check if heli height on terrain is below 1m ( sleep command before makes sure this check won't _heli vehicleChat "Viel Glück, Soldat!"; ///// be completed on takeoff before // Heli says "Good luck, soldier!" while {_shooter in _heli} do { sleep 1 ///// while loop to wait for the requester to get out of the heli }; //wait for player to get out, then fly out of map and get deleted hint "Airtaxi One Zero Alpha meldet Rückkehr zur Basis."; ///// Hint - transport helicopter is returning to base (getting deleted in middle of nowhere :) ) _wp3 = _heligrp addWaypoint [[0,0,500], 50]; ///// adding waypoint on coords 0,0 height 500 - completion radius 50m _wp3 setWaypointType "MOVE"; ///// setting waypoint type to move _wp3 setWaypointBehaviour "CARELESS"; ///// giving orders to ignore any enemy contact by acting careless _wp3 setWaypointSpeed "FULL"; ///// Setting Heli speed to max possible _wp3 setWaypointStatements ["true", "deletevehicle (vehicle this)"]; ///// Giving a Statement to delete the heli upon target reach //Delete created helipads and return Eventhandler for Green Smoke Triggering after 3 minutes deletevehicle TZ; ///// delete the helipads deletevehicle _helipad; ///// delete the helipads hint "Ihr nächster CASEVAC steht in 3 Minuten zur Verfügung."; ///// Hint - next transport avaiable in 3 minutes sleep 180; ///// Wait 180 seconds - 3 minutes hint "CASEVAC Verfügbar."; ///// Hint - Transport avaiable _shooter addEventHandler ["fired",{_this execvm "smoke2.sqf"}]; ///// Return Eventhandler to player The Eventhandler is given by the init.sqf - and the waitUntil line was neccessary in order for the script to work for other players in multiplayer waitUntil {!isNull player}; player addEventHandler ["fired",{_this execVM "Smoke2.sqf"}]; So please take a look at this stuff and help me to improve it :) Thank you very much in advance, guys greetings - porky243 Share this post Link to post Share on other sites
bigalexe 1 Posted April 3, 2013 I've been trying to do the same thing or something similar for most of the day. I threw together a land navigation mostly for training purposes. The goal of the scenario was that your team spawns in random locations (on hard difficulty so not markers on the map) with flares, and compasses. In order to "win" the scenario you need to get back to base. You could either all walk back or if you found one another you could call for a heli extraction. I handled the finding eachother with some cascading triggers and some logic statements and was able to get a heli called up on the radio but landing became an issue. Here's what I ended up with after reading your script and messing with a few things... Put the following into the Init section of your transport trigger... LZ = "Land_helipadempty_F" createVehicle getPos Player; Then if you really want you can put a deletion parameter in once you take off. This line and this line alone creates an empty helipad where the player is standing when the trigger is set off. However it's on the player to make sure that's a clear area. The cool thing about this method is that you can actually waypoint a chopper to a player directly and that waypoint is permanently attached. So no matter where you are on the map the chopper will come get you. Note that I prefer to do my extractions and insertions with persistent vehicles. Share this post Link to post Share on other sites
Porky243 1 Posted April 3, 2013 (edited) First of all thanks for your reply. I didn't go the way through triggers and init sections since I realized the usability is kind of limited. I can handle all the stuff with just the script you see above. This makes sure I can easily attach this function into any mission I want without resetting Triggers everytime in the editor. And the init lines of units and trigger ingame are only shot once, while I can recall a script whenever I need to. With the basic script above every player is able to call a dynamic heli to get out of wherever he is and mark any location he want to get to. The script also handles invisible helipad creation so the heli will do his job no matter what terrain you call him in. I even thought of deleting the helipads at the script end so the game won't be filled with used helipads during a long mission with lots of teams. My helipads aren't put to the player position though. If you call a heli by throwing a smoke grenade, the script locates the grenade and puts a helipad on its center. And the helipad on your destination will be put in with a mouseclick on the map as soon as it opens the map for the player after entering the heli. Right after you clicked your destination and the helipad is created, the heli gets the coordinates you just clicked and creates a waypoint to fly you over there. I was struggling while I wrote this thread since I was in a rush. But my basic asking was if someone could check that script with multiplayer sessions in mind to see if there is anything to improve its reliability in mp games. I already know what I have to change to improve the script itself in some cases like Failure handling and stuff like that. But the core works perfectly, you hit a smoke, the heli comes in, you mount it and pick your destination, it will take off and bring you there, after that it will take off and everything gets deleted so it won't fill the game with ancient waste. Its even possible to take a whole team for transportation since the heli always keeps waiting for the requester to do the next step, so if he is the last one entering and leaving the heli, he can take his team with him. So the mechanics work perfectly for me, and I am even quite happy about what I did there. i just want to understand what makes the difference between sp and mp in this case. The mp guideline at the biki didn't help much to be honest. I will still improve the script since the smoke check was just one part i wanted to have in the script and suddenly I ended up trying to get it done properly. My future plans are - to copy the transportation module radio chatting - to start the whole thing via radio command - to make the smoke check work for something like heli is in range circling above, mark the landing zone for him to get down - add functions for flares since a green smoke grenade won't work during pitch black nights I think :) Edit says: wouldn't be an alive check done easily by putting the whole CAS script into a while alive loop with an else: exit with return the eventhandler to the requester? Edited April 3, 2013 by Porky243 Share this post Link to post Share on other sites
syafie1104 1 Posted June 11, 2014 hi Porky243. i test this script in my mission as exactly like the instruction, but nothing happen after heli is spawn... the heli dont move at all... hope u can help me... Share this post Link to post Share on other sites