Jump to content

How to make a Ped shoot at the same spot that I do...?


WiBox

Recommended Posts

Hey, I need to know how I can make an Ped shoot at the same spot as I do, 

addEventHandler( "onClientPlayerWeaponFire", root
    function ( hitElement, hitX, hitY, hitZ )
        --set ped shoot as the same hitElement, example: setPedShootOn( thePed, hitElement )
    end
)

I appreciate who'll help... Thanks.

Plus I need that Ped to follow me where ever I go, is that possible?

Link to comment

try using this function :

function setPedShootOn( ped , element )	
	local available_types = 
	{
		[ 'vehicle' ] = true ,
		[ 'ped' ] = true ,
		[ 'player' ] = true ,
	}
	if( isTimer( renderTimer ) ) then
		killTimer( renderTimer );
	end	
	if( isElement( ped ) and getElementType( ped ) == "ped" and  isElement( element ) and available_types[ getElementType( element ) ] ) then
		renderTimer = setTimer(
			function( )
				local px , py , pz = getElementPosition( ped );
				local posX , posY , posZ = getElementPosition( element );
				local rotZ = -math.deg( math.atan2( posX - px , posY - py ) );
				if( rotZ < 0 ) then
					rotZ = rotZ + 360;
				end
				setElementRotation( ped , 0 , 0 , rotZ , "default" , true );
				setPedAimTarget( ped , posX , posY , posZ );
				setPedControlState( ped , "fire" , not getPedControlState( ped , "fire" ) );
			end , 50 , 0
		);	
	end
	return false
end

-- by KillerX --

 

Edited by KillerX
  • Thanks 1
Link to comment

Thanks you mate, working

but about that verification code:

" and  isElement( element ) and available_types[ getElementType( element ) ] ) then "

I had to remove it so it work, it's something in available_types, but nvm I've fix that error in it, thanks.

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...