Jump to content
七龙的秘密基地
Search In
  • More options...
Find results that contain...
Find results in...

[ARMA3]自制控制巡航导弹脚本


elstp_gf@foxmail.com

501 views

 Share

Quote

游戏中只能用控制终端才能发射,发射了不能控制,那如果我要控制导弹呢?接下来教大家怎么做~!

1.首先在ext中定义并编写一个对话框:

Control1_BG中的text指定了一个1.paa,这个是对话框的背景图片,可以自己把png转为paa,注意有分辨率要求否则会半透明。

Control1_BUT中的的onButtonClick 中写入 "[0,nil] call DESTINY_fnc_Launch;closeDialog 0;",当按钮被单机调用从CAS上发射,并且关闭当前对话框。

class DESTINY_Launch_Missile
{
	idd = 669988;
	
	class Controls
	{
		class Control1_BG
		{
			type = 0;
			idc = 0;
			x = -0.17499955;
			y = -0.42499949;
			w = 1.35000044;
			h = 1.80000063;
			style = 48;
			text = "1.paa";
			colorBackground[] = {0,0,0,0};
			colorText[] = {1,1,1,1};
			font = "PuristaMedium";
			sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
			moving = true;
			
		};

		class Control1_BUT
		{
			type = 16;
			idc = -1;
			x = 0.66500013;
			y = 0.76500016;
			w = 0.35000002;
			h = 0.12500003;
			style = 2;
			text = "启动";
			animTextureDefault = "#(argb,8,8,3)color(1,1,1,1)";
			animTextureDisabled = "#(argb,8,8,3)color(0.2,0.2,0.2,1)";
			animTextureFocused = "#(argb,8,8,3)color(1,1,1,1)";
			animTextureNormal = "#(argb,8,8,3)color(1,1,1,1)";
			animTextureOver = "#(argb,8,8,3)color(1,1,1,1)";
			animTexturePressed = "#(argb,8,8,3)color(1,1,1,1)";
			color[] = {1,1,1,1};
			color2[] = {0.502,0.6,1,1};
			colorBackground[] = {0,0,0,0};
			colorBackground2[] = {0, 0, 0, 0};
			colorBackgroundFocused[] = {0,0,0,0};
			colorDisabled[] = {0.2,0.2,0.2,1};
			colorFocused[] = {1,0.7131,0,1};
			font = "PuristaMedium";
			size = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 2);
			sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
			soundClick[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundClick",0.09,1.0};
			soundEnter[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEnter",0.09,1.0};
			soundEscape[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEscape",0.09,1.0};
			soundPush[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundPush",0.09,1.0};
			textureNoShortcut = "";
			onButtonClick = "[0,nil]call DESTINY_fnc_Launch;closeDialog 0;";
			class HitZone
			{
				top = 0;
				right = 0;
				bottom = 0;
				left = 0;
				
			};
			class ShortcutPos
			{
				top = 0;
				left = 0;
				w = 0;
				h = 0;
				
			};
			class TextPos
			{
				top = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) - (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)) / 2;
				right = 0.005;
				bottom = 0;
				left = 0.25 * (((safezoneW / safezoneH) min 1.2) / 40);
				
			};
			
		};
		
	};
	
};

2.接下来定义定义和编写在游戏中导弹视角的HUD:

Control618624017里text使用到了2.paa,是用来显示瞄准的图片,可以自己换

class RscTitles {
	class DESTINY_HUD_MISS
	{
		idd = 98100;
		duration = 4;
		fadeIn = 0;
		fadeOut = 0;
		name = "DESTINY_HUD_MISS";
		onLoad = "uiNamespace setVariable ['DESTINY_HUD_MISS',_this select 0]";
		
		class ControlsBackground
		{
			class Control618624017
			{
				type = 0;
				idc = 0;
				x = 0.00000016;
				y = -0.0749998;
				w = 1.00000025;
				h = 1.15000022;
				style = 48;
				text = "2.paa";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
				
			};
			class ControlSpeed
			{
				type = 0;
				idc = 98101;
				x = 0.30000012;
				y = 0.82500011;
				w = 1;
				h = 0.05000004;
				style = 0;
				text = "速度:";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.5);
				
			};
			class ControlPerspective
			{
				type = 0;
				idc = 98102;
				x = 0.30000012;
				y = 0.97500012;
				w = 1;
				h = 0.05000004;
				style = 0;
				text = "视角:";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.5);
				
			};
			class ControlMode
			{
				type = 0;
				idc = 98103;
				x = 0.30000012;
				y = 0.90000011;
				w = 1;
				h = 0.05000004;
				style = 0;
				text = "模式:";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.5);
				
			};
			class ControlRadar
			{
				type = 0;
				idc = 98105;
				x = 0.30000012;
				y = 1.11424053;
				w = 1;
				h = 0.05000004;
				style = 0;
				text = "范围:";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.5);
				
			};
			class ControlDistance
			{
				type = 0;
				idc = 98104;
				x = 0.30000012;
				y = 1.05000012;
				w = 1;
				h = 0.05000004;
				style = 0;
				text = "高度:";
				colorBackground[] = {0,0,0,0};
				colorText[] = {1,1,1,1};
				font = "PuristaMedium";
				sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.5);
				
			};
			
		};
		
	};
}

3.编写发射功能:将文件命名为:fnc_Launch.sqf

#define DESTINY_HUD_speed ((uiNamespace getVariable "DESTINY_HUD_MISS") displayCtrl 98101)
#define DESTINY_HUD_HUD ((uiNamespace getVariable "DESTINY_HUD_MISS") displayCtrl 98102)
#define DESTINY_HUD_Mode ((uiNamespace getVariable "DESTINY_HUD_MISS") displayCtrl 98103)
#define DESTINY_HUD_Distance ((uiNamespace getVariable "DESTINY_HUD_MISS") displayCtrl 98104)
#define DESTINY_HUD_Radar ((uiNamespace getVariable "DESTINY_HUD_MISS") displayCtrl 98105)
closeDialog 669988;
DESTINY_Y = 0;
DESTINY_P = 0;
DESTINY_R = 0;
//注册键盘点击事件
DESTINY_fnc_setKeyDown = {
    _HE = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call DESTINY_fnc_keyListen;"];
    player setVariable["DESTINY_HE",_HE];
};
//创建摄像机
DESTINY_fnc_createCAM = {
    Destiny_cam = "camera" camCreate getPosASL (_this # 0);
    Destiny_cam cameraEffect ["External", "BACK"];
    Destiny_cam camSetTarget (_this # 1);
    Destiny_cam camSetRelPos (_this # 2);
    showCinemaBorder false;
    false setCamUseTI 0;
    Destiny_cam camCommit 0.1;
    cameraEffectEnableHUD true;
    if (_this # 3) then {
        call DESTINY_fnc_setKeyDown;
    };
};
//创建导弹
[_this # 0,_this # 1] spawn {
    _type = _this # 0;
    DESTINY_VLS_DAODAN = _this # 1;
    EXIT_SCRIPT = false;
    _pos = getPos player;
    cutText ["","BLACK OUT",0.5];
    _TypePos = [_pos # 0,_pos # 1,1000];
    if (_type == 2) then {
        _TypePos = [0,0,1000];
    };
    DESTINY_obj = "ammo_Missile_Cruise_01" createVehicle _TypePos;
    DESTINY_obj enableSimulation false;
    sleep 0.5;
	cutText ["","PLAIN"];
    switch _type do {
        case 0: { 
        CASobj = createVehicle ["B_Plane_CAS_01_dynamicLoadout_F", [_pos # 0,_pos # 1,1100], [], 100, "FLY"];
        DESTINY_pilot = [
            CASobj,
            [
                ["B_Fighter_Pilot_F","driver"]
            ]
        ] call BIS_fnc_initVehicleCrew;
        CASobj allowDamage false;
        _Pylon = ["pylons1","pylons2","pylons3","pylons8","pylons9","pylons10"];
        {
            CASobj setPylonLoadout [_x, "PylonRack_3Rnd_Missile_AGM_02_F",true]; 
        } forEach _Pylon;
        _CASpos = getPos CASobj;
        CASobj setPos [_CASpos # 0,_CASpos # 1,(_CASpos #2) + 2000];
        _vel = velocity CASobj;  
        _dir = direction CASobj;  
        _speed = 100; 
        CASobj setVelocity [  
        (_vel select 0) + (sin _dir * _speed),   
        (_vel select 1) + (cos _dir * _speed),   
        (_vel select 2) ];
            _XX = 60;
            _Y = 100;
            _Z = 10;
            DESTINY_obj attachTo [CASobj,[0,0,-1]];
            [DESTINY_obj,CASobj,[10,50,10],false] call DESTINY_fnc_createCAM;
            while {true} do {
                CASobj setVectorDirAndUp [
                    [ sin 0 * cos 0,cos 0 * cos 0,sin 0],
                    [[ sin 0,-sin 0,cos 0 * cos 0],-0] call BIS_fnc_rotateVector2D
                ];
                _lastTime = time;
                sleep 0.1;
                if (_XX != 30) then {
                    _XX = _XX - 1;
                };
                if (-2 < _Y) then {
                    _Y = _Y - 1;
                };
                if (_Z != 0) then {
                    _Z = _Z - 1;
                };
                if (-2 >= _Y) exitWith {
                    [Destiny_cam] spawn {
                        _j = -1;
                        while {true} do {
                            _j = _j - 0.1;
                            DESTINY_obj attachTo [CASobj,[0,0,_j]];
                            if (_j < -5) exitWith {
                                detach DESTINY_obj;
                                DESTINY_obj enableSimulation true;
                                call DESTINY_fnc_setKeyDown;
                            };
                        };
                    };
                };
                Destiny_cam camSetTarget CASobj;
                Destiny_cam camSetRelPos [_XX,_Y,_Z]; 
                Destiny_cam camcommit 5 * (time - _lastTime);
            };
        };
        case 1: { 
            DESTINY_obj enableSimulation true;
            [DESTINY_obj,DESTINY_obj,[0,-10,0],true] call DESTINY_fnc_createCAM;
        };
        case 2: { 
            _objUpVector = vectorUp DESTINY_VLS_DAODAN;
            _dirVector = vectorDir DESTINY_VLS_DAODAN;
            _oldPOS = getPosASL DESTINY_VLS_DAODAN;
            deleteVehicle DESTINY_VLS_DAODAN;
            DESTINY_obj setVectorDirAndUp [_dirVector,_objUpVector];
            DESTINY_obj setPosASL _oldPOS;
            DESTINY_obj enableSimulation true;
            [DESTINY_obj,DESTINY_obj,[10,50,10],false] call DESTINY_fnc_createCAM;
            sleep 3;
        };
        default {EXIT_SCRIPT=true;};
    };
    if (EXIT_SCRIPT) exitWith {};
    _lastpos = getPosASL DESTINY_obj;
    _dir = getDir DESTINY_obj;
    DESTINY_Radar = 4000;
  	 //绘制目标图标到敌军坐标
    _handlerID = addMissionEventHandler ["Draw3D", {
        {
            if (!(isPlayer _x) and (side _x) == east and (alive _x) and (DESTINY_obj distance _x) <= DESTINY_Radar) then {
                _M = format["%1 m",round (DESTINY_obj distance _x)];
                if ((vehicle _x) != _x) then {
                    drawIcon3D ["a3\ui_f\data\gui\Cfg\Hints\icon_text\n_unknown_ca.paa", [1,1,1,1], ASLToAGL getPosASL _x, 1, 1, 45, _M,0, 0.03, "TahomaB","center",true];
                }else{
                    drawIcon3D ["a3\ui_f\data\gui\Cfg\Cursors\scroll_gs.paa", [1,1,1,1], ASLToAGL getPosASL _x, 1, 1, 45,_M, 1, 0.03, "TahomaB","center",true];
                };
                
            };
        } forEach allUnits;
    }];
    [_type]spawn {
        _type = _this # 0;
        sleep 3;
        player setVariable["DESTINY_Perspective",[true,0]];
        switch _type do {
            case 0: {
                deleteVehicle CASobj;
            };
            case 2: {
                call DESTINY_fnc_setKeyDown;
            };
        };
        player setVariable["DESTINY_N",0];
    };
    while {!(isNull DESTINY_obj)} do {
        _Perspective = player getVariable ["DESTINY_Perspective",[false,-1]];
        if (_Perspective # 0) then {
            cutText ["","BLACK OUT"];
            _hide = switch (_Perspective # 1) do {
                case 0: {true};
                case 1: {false};
            };
            sleep 1;
            DESTINY_obj hideObject _hide;
            cutText ["","BLACK IN"];
            player setVariable["DESTINY_Perspective",[false,(_Perspective # 1)]];
        };
        _n = player getVariable ["DESTINY_N",8];
        _lastTime = time;
        _lastpos = getPosASL DESTINY_obj;
        _dir = getDir DESTINY_obj;
        sleep 0.01;
        Destiny_cam camSetTarget DESTINY_obj;
        Destiny_cam camSetRelPos (player getVariable ["DESTINY_POS",[0,-5,0]]);
        if(_n >= 0 && _n < 8) then{
		    true setCamUseTI _n;
        }else{
            false setCamUseTI 0;
        };
		_vel = velocity DESTINY_obj;
		_spd = (_vel distance [0,0,0]) max 1;
		_perspectiveText= switch (_Perspective # 1) do {
                case 0: {"第一人称"};
                case 1: {"第三人称"};
				default {"关闭"};
        };
		_modeText = switch _n do {
                case 0: {"白热"};
                case 1: {"黑热"};
				case 2: {"绿色"};
				case 3: {"深绿"};
				case 4: {"浅红"};
				case 5: {"深红"};
				case 6: {"暗红"};
				case 7: {"散热"};
				default {"关闭"};
        };
		_distancePOS = getPosASL DESTINY_obj;
		_meters = _distancePOS distance [_distancePOS # 0,_distancePOS # 1,0];
		cutRsc ["DESTINY_HUD_MISS","PLAIN"];
		DESTINY_HUD_speed ctrlSetText format["速度:                     %1 km/h",round _spd];
		DESTINY_HUD_HUD ctrlSetText format["视角:                     %1 (R)",_perspectiveText];
		DESTINY_HUD_Mode ctrlSetText format["模式:                     %1 (N)",_modeText];
		DESTINY_HUD_Distance ctrlSetText format["高度:                     %1 米",round _meters];
        DESTINY_HUD_Radar ctrlSetText format["雷达:                     %1 米 (F)",DESTINY_Radar];
        Destiny_cam camcommit 5 * (time - _lastTime);
    };
    player setVariable["DESTINY_N",8];
	Destiny_cam camSetPos [(_lastpos select 0) - 200*sin(_dir), (_lastpos select 1)-200*cos(_dir), (_lastpos select 2) + sin(45)*200];
	Destiny_cam camCommit 5;
	Destiny_cam camSetTarget _lastpos;
	_endTime = time + 5;
	while {time<_endtime} do {
        sleep 1
    };
  //当导弹爆炸后移除各种事件并销毁摄像机
    Destiny_cam cameraeffect ["terminate", "back"];
	camDestroy Destiny_cam;
    cutText ["","BLACK IN"];
    (findDisplay 46) displayRemoveEventHandler ["KeyDown",player getVariable["DESTINY_HE",0]];
    removeMissionEventHandler ["Draw3D",_handlerID];
};

3.编写键盘控制事件控制导弹转向:将文件命名位为:fnc_keyListen.sqf

#include "\a3\ui_f\hpp\definedikcodes.inc"
params['_d','_key','_shift_state','_control_state','_alt_state'];
private['_handled'];
_handled = false;
_n = player getVariable["DESTINY_N",-1];
//当ADSW按下,做相应的动作
switch (_key) do {
    case DIK_A:{
        if (DESTINY_Y == 0) then {
            DESTINY_Y = 360;
        };
         DESTINY_Y = DESTINY_Y - 1;
         _handled = true;
    };
    case DIK_D:{
        if (DESTINY_Y == 360) then {
            DESTINY_Y = 0;
        };
         DESTINY_Y = DESTINY_Y + 1;
          _handled = true;
    };
    case DIK_W:{
        if (DESTINY_P == 0) then {
            DESTINY_P = 360;
        };
         DESTINY_P = DESTINY_P - 1;
          _handled = true;
    };
    case DIK_S:{
        if (DESTINY_P == 360) then {
            DESTINY_P = 0;
        };
         DESTINY_P = DESTINY_P + 1;
          _handled = true;
    };
    case DIK_N:{
        _n = _n + 1;
        player setVariable["DESTINY_N",_n];
        if (_n == 8) then {
            player setVariable["DESTINY_N",-1];
        };
    };
    case DIK_F:{
        DESTINY_Radar = DESTINY_Radar + 1000;
        if (DESTINY_Radar == 11000) then {
            DESTINY_Radar = 4000;
        };
    };
    case DIK_R:{
        _Perspective = player getVariable ["DESTINY_Perspective",[false,-1]];
        _jc = _Perspective # 1;
        _jc = _jc + 1;
        if (_jc == 2) then {
            _jc = 0;
        };
        player setVariable ["DESTINY_Perspective",[true,_jc]];
    };
    
};
//将得到的数据计算并设置导弹的向量
DESTINY_obj setVectorDirAndUp [
	[ sin DESTINY_Y * cos DESTINY_P,cos DESTINY_Y * cos DESTINY_P,sin DESTINY_P],
	[[ sin DESTINY_R,-sin DESTINY_P,cos DESTINY_R * cos DESTINY_P],-DESTINY_Y] call BIS_fnc_rotateVector2D
];
_handled;

4.在ext中定义函数:

class CfgFunctions {
	class DESTINY {
		class destiny_studio{
			class DESTINY_fnc_Launch {file = "fnc_Launch.sqf的相对路径";};
			class DESTINY_fnc_keyListen {file = "fnc_keyListen.sqf的相对路径";};
		}
	}
}

5.在控制台中运行并测试,并点击发射:

_ok = createDialog "DESTINY_Launch_Missile";
if !(_ok) exitWith {
	hint "创建巡航导弹发射菜单失败!";
};

6.直接运行

//从CAS上发射控制导弹
[0,_projectile] call DESTINY_fnc_Launch;

//直接控制导弹
[1,_projectile] call DESTINY_fnc_Launch;

//控制指定的导弹 _projectile = 创建后的导弹
[2,_projectile] call DESTINY_fnc_Launch;

enjoy~

 Share

0 Comments


Recommended Comments

There are no comments to display.

×
×
  • Create New...