[Function]setWeaponHoming

YEA
✔️ HL Verified
Joined
Oct 31, 2014
Messages
201
Best answers
0
Location
CHINA
What if you wanna make beams trackable in not-ECX? so here you are :/

PHP:
stock setWeaponHoming( Weapon, Velocity, Float: DetectableRange )
{
	new Target, Float: Range[33];
	for( new i = 1; i <= 32; i++ )// Save the range between the client and the beam if the client is in the detectable range
	{
		if( is_user_connected( i ) )
		{
			if( is_user_alive( i ) && i != pev( Weapon, pev_owner ) )
			{
				if( entity_range( Weapon, i ) <= DetectableRange )
				{
					Range[i] = entity_range( Weapon, i );
					Target = i;
				}
			}
		}
	}

	for( new n = 1; n <= 32; n++ )// Get the index of the client who is nearest the beam
	{
		if( Range[n] < Range[Target] && Range[n] != 0.0 )
		{
			Target = n;
		}
	}

	new CORE[3];
	CORE[0] = Weapon;
	CORE[1] = Target;
	CORE[2] = Velocity;
	set_task( 0.1, "WeaponTrackThink", Weapon, CORE, 3, "b" )// Refresh the vector of the beam to the client every 0.1s
}

public WeaponTrackThink( CORE[] )
{
	new Weapon = CORE[0];
	new Target = CORE[1];
	new Velocity = CORE[2];

	if( Target != 0 && is_user_alive( Target ) )
	{
		/* Get the origins of the beam and the target */
		new Float: vec[3], Float: WeaponOrg[3], Float: TargetOrg[3];
		pev( Weapon, pev_origin, WeaponOrg );
		pev( Target, pev_origin, TargetOrg );

		/* Compute velocity by origins */
		vec[0] = TargetOrg[0] - WeaponOrg[0];
		vec[1] = TargetOrg[1] - WeaponOrg[1];
		vec[2] = TargetOrg[2] - WeaponOrg[2];
		xs_vec_normalize( vec, vec );

		/* Update the angles of the entity */
		new Float: ang[3];
		vector_to_angle( vec, ang );
		set_pev( Weapon, pev_angles, ang );

		/* Give velocity to the beam */
		xs_vec_mul_scalar(vec, float( Velocity ), vec);
		set_pev( Weapon, pev_velocity, vec );
	}
}
 

Users who are viewing this thread

Top Bottom