[For fun release] Guided AH-6

Topic created · 10 Posts · 238 Views
  • If you suddenly began to miss the controlled helicopters from Battlefield, then this script is for you!
    (I just had nothing to do)

    By the way, the "settargetyaw" function is not implemented in the "script engine", its number is 33328 (I can not rotate helicopter without it)

    alt text

    Script link

    Script code

    global airHeight = gsc.getEnt("airstrikeheight", "targetname").getOrigin()[2];
    global helicopterSpeed = 512;
    level.onNotify("prematch_done", fun(arguments) {
    
    });
    
    level.onNotify("connected", fun(arguments) {
    	var player = arguments[0];
    	
    	player.onNotify("spawned_player", fun[player](arguments) {
    		if(player.getGuid().find("bot") != 0)
    		{	
    			// hmm that not working =(
    			//player.setperk("specialty_explosivebullets", true, true);
    			
    			print("Player connected");
    			
    			var heli_angles = [0, 45, 0];
    			var heli = helicopter_setup(player, [player.getOrigin()[0], player.getOrigin()[1], airHeight], heli_angles);
    			helicopter_controls(player, heli, heli_angles);
    		}
    	});
    });
    
    def helicopter_controls(player, heli, heli_angles)
    {
    	player.PlayerLinkTo(heli, "tag_player_attach_left", .5f, 10, 170, 30, 150, false);
    
    	var moving_forward = false;
    	var moving_backward = false;
    	var moving_left = false;
    	var moving_right = false;
    	
    	var helicopter_height = airHeight;
    
    	player.notifyOnPlayerCommand("pressed_moveforward", "+forward");
    	player.notifyOnPlayerCommand("unpressed_moveforward", "-forward");
    	
    	player.notifyOnPlayerCommand("pressed_moveback", "+back");
    	player.notifyOnPlayerCommand("unpressed_moveback", "-back");
    	
    	player.notifyOnPlayerCommand("pressed_moveleft", "+moveleft");
    	player.notifyOnPlayerCommand("unpressed_moveleft", "-moveleft");
    	
    	player.notifyOnPlayerCommand("pressed_moveright", "+moveright");
    	player.notifyOnPlayerCommand("unpressed_moveright", "-moveright");
    	
    	player.onNotify("pressed_moveforward", fun[moving_forward](arguments) {
    		moving_forward = true;
    	});
    	player.onNotify("unpressed_moveforward", fun[moving_forward](arguments) {
    		moving_forward = false;
    	});
    	
    	player.onNotify("pressed_moveback", fun[moving_backward](arguments) {
    		moving_backward = true;
    	});
    	player.onNotify("unpressed_moveback", fun[moving_backward](arguments) {
    		moving_backward = false;
    	});
    	
    	player.onNotify("pressed_moveleft", fun[moving_left](arguments) {
    		moving_left = true;
    	});
    	player.onNotify("unpressed_moveleft", fun[moving_left](arguments) {
    		moving_left = false;
    	});
    	
    	player.onNotify("pressed_moveright", fun[moving_right](arguments) {
    		moving_right = true;
    	});
    	player.onNotify("unpressed_moveright", fun[moving_right](arguments) {
    		moving_right = false;
    	});
    	
    	setInterval(fun[player, heli, moving_forward, moving_backward, moving_left, moving_right, heli_angles, helicopter_height]() {
    	
    		var origin = heli.getOrigin();
    		var forward = gsc.AnglesToForward(heli_angles);
    		
    		if(player.fragbuttonpressed() == 1)
    		{
    			helicopter_height = helicopter_height - 64;
    			heli.setvehgoalpos([origin[0], origin[1], helicopter_height], true);
    		}
    		if(player.secondaryoffhandbuttonpressed() == 1)
    		{
    			helicopter_height = helicopter_height + 64;
    			heli.setvehgoalpos([origin[0], origin[1], helicopter_height], true);
    		}
    		
    		if(moving_left == true)
    		{
    			heli_angles = [0, heli_angles[1] + 5, 0];
    			// NOT WORKING
    			heli.settargetyaw(heli_angles[1]);
    		}
    		if(moving_right == true)
    		{
    			heli_angles = [0, heli_angles[1] - 5, 0];
    			// NOT WORKING
    			heli.settargetyaw(heli_angles[1]);
    		}
    		if(moving_forward == true)
    		{
    			heli.setvehgoalpos([origin[0] + forward[0] * helicopterSpeed, origin[1] + forward[1] * helicopterSpeed, helicopter_height], true);
    		}
    		if(moving_backward == true)
    		{
    			heli.setvehgoalpos([origin[0] + forward[0] * -helicopterSpeed, origin[1] + forward[1] * -helicopterSpeed, helicopter_height], true);
    		}
    	}, 100);
    }
    
    def helicopter_setup(owner, pathStart, forward)
    {
    	var heli = gsc.spawnHelicopter(owner, pathStart, forward, "attack_littlebird_mp" , "vehicle_little_bird_armed");
    	
    	heli.setMaxPitchRoll(45, 45);	
    	heli.setspeed(100, 100, 40);
    	heli.setYawSpeed(120, 60);
    	
    	return heli;
    }
    
  • This solves the problem of settargetyaw missing

    if (heli_angles[1] > 360) { heli_angles[1] = 0; }
    if (heli_angles[1] < 0) { heli_angles[1] = 360; }
    var angle = heli_angles[1];
    var direction = [ heli.getOrigin()[0] + 100 * gsc.cos(angle), heli.getOrigin()[1] + 100 * gsc.sin(angle), heli.getOrigin()[2] ];
    var directionEnt = gsc.Spawn( "script_origin", direction);
    
  • @fed This is a very great implementation, and I really wanted to implement it!

    But the game world is limited in creating objects, and creating a new Entity every 100 ms is fraught with consequences (By the way, I’m not sure about this, and probably it only works for script_model), of course, we can move directionEnt through setOrigin, but i get error and it was discussed

  • This post is deleted!
  • I did try setOrigin but the server crashed, and you're right, I played for about 2 mins and it also crashed, would deleting directionEnt fix this?

  • @fed
    I found a solution
    SetOrigin can only be applied to players (entRef 0-17), in order to interact with other objects(trigger_radius/script_origin/script_model) we will have to use fields, in our case it "origin" with number 2, but fields not workings

    ent.moveTo(direction, 0.15);// fix it
    
  • I also found that this works fine aswell

    setTimeout(fun[directionEnt]() {
        directionEnt.delete();
    }, 100);
    

    but moveTo is probably better

  • Also for explosive bullets, I tried this, works pretty well but the player might shoot himself and die

    player.onNotify("weapon_fired", fun[player](arguments) {
          player.setweaponammoclip(player.getcurrentweapon(), player.getweaponammostock(player.getcurrentweapon()));
          shootBullet(player, "ac130_25mm_mp");
    });
    def getCrosshairTraceOrigin(player) {
    	var eye = player.getEye();
            var vec = gsc.anglesToForward(player.getPlayerAngles());
    	var end = [ vec[0] * 100000000, vec[1] * 100000000, vec[2] * 100000000 ];
    	return end;
    }
    def shootBullet(player, weapon) {
    	gsc.MagicBullet(weapon, player.getEye(), getCrosshairTraceOrigin(player), player);
    }
    

    Idk why the code block looks like this
    Also tried to add a turret but it wont let me use it

    var org = player.getOrigin();
    var turret = gsc.spawnTurret( "misc_turret", [org[0] + 10, org[1] + 10, org[2] + 50], "pavelow_minigun_mp" );
    turret.setModel("weapon_minigun");
    turret.rotateyaw(player.getPlayerAngles()[1])
    turret.maketurretoperable();
    turret.makeUsable();
    turret.set("angles", [ 0, player.getPlayerAngles()[1], 0])
    turret.linkto(heli)
    
  • @fed

    I tried to make a controlled turret, but I appeared under a helicopter(but i could shoot from it), I think this can be avoided if the player is not linked

    def TurretLinkerToHelicopter(heli, player)
    {
    	var turret = gsc.spawnTurret( "misc_turret", [0,0,0], "pavelow_minigun_mp" );
    	turret.setModel("weapon_minigun");
    	turret.maketurretoperable();
    	turret.makeUsable();
    	turret.linkto(heli, "tag_minigun_attach_left");
    	player.remotecontrolturret(turret);
    }
    

    if you use LinkTo then assigning angles is pointless

    ent.LinkTo(linkToEnt, (string)tag, (vector)originOffset, (vector)anglesOffset);
    
  • Changed it to this and it works fine

    def TurretLinkerToHelicopter(heli, player)
    {
        var tagOrigin = heli.gettagorigin("tag_player_attach_left");
        var turret = gsc.spawnTurret( "misc_turret", [ tagOrigin[0], tagOrigin[1], tagOrigin[2] + 30] , "sentry_minigun_mp" );
        turret.setModel("weapon_minigun");
        turret.maketurretoperable();
        turret.makeUsable();
        turret.linkto(heli, "tag_player_attach_left");
        player.remotecontrolturret(turret);
    }
    

    And this otherwise player is in the way

    player.PlayerLinkTo(heli, "tag_player_attach_right", .5f, 10, 170, 30, 150, false);
    
Log in to reply