Maurize Posted April 21, 2015 Share Posted April 21, 2015 Hello everybody, I'm working on a "working" ped. However if resource is started a ped gets created. I trigger it to client and then execute following functions: local element = getLocalPlayer(); addEvent( "onClientActor", true ); addEventHandler( "onClientActor", element, function( actor ) if ( getElementData( element, "loaded" ) == false ) then setElementData( element, "loaded", true ); addEventHandler( "onClientRender", root, function() local enemy = getTarget( actor ); local _, _, rZ = getElementRotation( actor ); local aX, aY, aZ = getElementPosition( actor ); local tX, tY, tZ = getElementPosition( enemy ); local bX, bY, bZ = getPedBonePosition( enemy, 3 ); local tR = -math.deg( math.atan2( aX - tX, aY - tY ) ) - 180; local fX = aX - math.sin( math.rad ( rZ ) ) * 3; local fY = aY + math.cos( math.rad ( rZ ) ) * 3; if ( getDistanceBetweenPoints3D( aX, aY, aZ, tX, tY, tZ ) > 50 ) then setPedControlState( actor, "aim_weapon", false ); setPedControlState( actor, "fire", false ); setPedControlState( actor, "forwards", true ); setPedControlState( actor, "walk", true ); if ( isLineOfSightClear( aX, aY, aZ, fX, fY, aZ ) ~= true ) then setElementRotation( actor, 0, 0, rZ + 1 ); end else setPedControlState( actor, "forwards", false ); setPedControlState( actor, "aim_weapon", true ); setPedControlState( actor, "fire", true ); setElementRotation( actor, 0, 0, tR ); setPedAimTarget( actor, bX, bY, bZ ); end end ); end end ) function getTarget( ped ) local x, y, z = getElementPosition( ped ); local prevDist; for i, v in ipairs( getElementsByType( "player" ) ) do local dist = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ); if ( dist <= ( prevDist or dist + 1 ) ) then prevDist = dist; target = v; end end return target or false end Everything works fine... But the ped doesn't hit me very well ( very rare that I got hit ). So my question is, where is the trick to make him more accurate? -> setPedStat is max for every weapon. --> Maybe you got some hints what to do better Link to comment
[PXG]Blue Posted April 21, 2015 Share Posted April 21, 2015 Maybe try and look into the Slothbot resource and see how its handled there, it might help you to fix it Link to comment
Maurize Posted April 21, 2015 Author Share Posted April 21, 2015 Hmm, seems like it was the too short timer which made trouble... howevery everything works fine now! Theres only that point, that I spawn the peds all arround los santos but sometimes if I shoot at a ped it doesn't loose health? SOLVED ~ Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now