Jump to content
Sign in to follow this  
Freddan962

Need help with a script!

Recommended Posts

Oh thank god this might be the help I need.

Since Freddan seems to have his problem solved maybe i can abuse this thread to get help with a script instead.

I'd open my own thread for this, but i don't have the permission yet.

So basically I wrote a script for arma 3 that checks if a player throws a green smoke grenade. If done it will spawn a helicopter in random position around player ( values are modifiable ) to pick him up and fly him to a destination picked by mapclick.

Now I fought with my lack of scripting skills until I made it work. Tried it out and its a dream according to the fact I wrote it by my own two left hands. ( Though I looked at different similar scripts to get where I want to)

Tried it out in multiplayer with some friends on a player server since we don't have a dedicated one yet.

After adding

waitUntil {!isNull player};
player addEventHandler ["fired",{_this execVM "Smoke2.sqf"}];

to the mission init.sqf it does work if any player throws a smokegrenade and works for that player. Unfortunately it somehow gets messed up at times. But this mp scripting rules got me quite confused and I ended up googling for hours. I know this script still needs some basic tweaking and changes. But for now it does its job (aside the fact that in mp games the heli sometimes just won't take off and stuff) so I hope to find some help from those scripting gods.

So here is the code - I am german but I rewrote the commend parts so you guys know whats going on, I even added comments on almost every line for those who are even less into scripting than I am, so maybe it helps in understanding rough basics. I noticed most of the useful scripts have rarely comments explaining how they work, so I thought my script may help some guys.

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 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

I appreciate any help - may it be tips on making it better or any kind of mp related advise. At first i thought I'll have to use local variables since global variables would interfere with each other when mutliple players trigger the script simultaneously, until I found out even globals are different on any machine.

So Thank you Guys very much in advance :)

Greetings - Porky 243

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  

×