veronapl Posted August 28, 2009 Share Posted August 28, 2009 Hi. Sorry, i'm not speak English I'm write script; ped fire m4 in player (ped kill player). This im me code: local plr = getLocalPlayer(); local PEDEK function greetingHandler ( ped ) PEDEK = ped outputChatBox ( "działa" ) setPedControlState( PEDEK, "fire", true) addEventHandler( "onClientRender", getRootElement(), firenow) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) function firenow() local x, y, z = getElementPosition( plr ) local pedx, pedy, pedz = getElementPosition ( PEDEK ) newangle = ( 360 - math.deg ( math.atan2 ( ( x - pedx ), ( y - pedy ) ) ) ) % 360 setPedAimTarget ( PEDEK, x, y, z ) setPedRotation(PEDEK,newangle) setPedCameraRotation ( PEDEK, newangle) setPedLookAt ( PEDEK, x, y, z) end This is me problem/bug - video: http://www.youtube.com/watch?v=QIyNEFr0mtg Ped not can kill player. Ped not fire in player. Rotation ped (only legs) is ok. Pleas help me! Sorry very very bad English. Polish: Ped sie obraca, ale on i tak strzela w złym kierunku, obraca lufew strone 0 stopni. Ped ma zabic gracza, a on strzela w dziwnym kierunku i nie chce wycelowac we mnie. Link to comment
Slothman Posted August 28, 2009 Share Posted August 28, 2009 I experienced a similar issue when scripting an ai bot, try spawning the bot, then giving it a weapon and ammo afterwards (using a timer) Link to comment
veronapl Posted August 28, 2009 Author Share Posted August 28, 2009 Sorry, I do not understand. Very pleas reapir code. Problem is bad aim weapon, bad torso rotation. Ammo is ok. Link to comment
50p Posted August 28, 2009 Share Posted August 28, 2009 I experienced a similar issue when scripting an ai bot, try spawning the bot, then giving it a weapon and ammo afterwards (using a timer) From the Polish part, I understand that the problem is not related to the gun itself but the ped rotation. He's trying to say the ped is not facing the player but in different directions. @veronapl, Try my peds resource which you can download here: https://community.multitheftauto.com/index.php?p= ... ils&id=234 My peds were simply following me, but to make them follow you, you also need to calculate the angle in which they need to go, so I think that resource will help you. Watch the video presentation here: You may also use setPedAimTarget to make them aim at you which I think would be the best choice for you. Link to comment
Slothman Posted August 28, 2009 Share Posted August 28, 2009 i think he's saying that the ped isnt hurting the player, thats certainly what the vid shows. Link to comment
50p Posted August 28, 2009 Share Posted August 28, 2009 i think he's saying that the ped isnt hurting the player, thats certainly what the vid shows. Maybe that too, but mainly: Problem is bad aim weapon, bad torso rotation. Link to comment
veronapl Posted August 28, 2009 Author Share Posted August 28, 2009 50p, sorry Your script unfortunately not help me This is video: http://www.youtube.com/watch?v=kJc9qJWzj7Q This is me script + Your code. Rotation is bad local plr = getLocalPlayer(); local PEDEK function greetingHandler ( ped ) PEDEK = ped outputChatBox ( "działa" ) addEventHandler( "onClientRender", getRootElement(), firenow) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) function firenow() local x, y, z = getElementPosition( plr ); local X, Y = 0, 0; local px, py, pz = getElementPosition( PEDEK ); X = math.abs( x - px ); Y = math.abs( y - py ); faceMe = math.deg( math.atan2( Y , X ) ); --faceMe = ( 360 - math.deg ( math.atan2 ( ( px - x ), ( py - y ) ) ) ) % 360 if ( x >= px ) and ( y > py ) then -- north-east faceMe = 90 - faceMe elseif ( x <= px ) and ( y > py ) then -- north-west faceMe = 270 + faceMe elseif ( x >= px ) and ( y <= py ) then -- south-east faceMe = 90 + faceMe elseif ( x < px ) and ( y <= py ) then -- south-west faceMe = 270 - faceMe end --guiSetText( label, tostring( faceMe ) ); setPedRotation( PEDEK, faceMe ); setPedLookAt( PEDEK, x, y, z + .5 ); setPedAimTarget ( PEDEK, x, y, z ) setPedControlState( PEDEK, "fire", true) end Very pleas, help. PS My ped is bodyguard, in my house. Link to comment
50p Posted August 28, 2009 Share Posted August 28, 2009 It seems that it's MTA's bug. I just tested my peds script, I gave them weapons (/giveweapon ) and they weren't aiming in the correct direction but they were walking in my direction between the shots. Like sniper rifle, when reloading you can walk a bit before the next shot. I made them aim my head and sometimes I did get hit but most of the time they missed me, even when I was standing still. Link to comment
veronapl Posted August 28, 2009 Author Share Posted August 28, 2009 Is it hard to do something? Repair? Other code? I very need bodyguard Link to comment
karloz Posted August 29, 2009 Share Posted August 29, 2009 check if this works: -- absolute angle XY-plane relative to world (from origin to target) function getAngle2D(originx, originy, targetx, targety) dx = targetx - originx dy = targety - originy angle = math.deg(math.atan2(dx,dy)) -- at this point we have an angle in range 0,180 and -0,-180 -- where values -0,-180 are values 0,180 in game -- and values 180,0 are 180,360 in game -- next 2 lines fix angle to be 0,360 correlative with MTA angles angle = - angle if(angle<0) then angle = 360.0 + angle end return angle end there is a similar function in wiki but i cant find it Directly in your code: function firenow() local x, y, z = getElementPosition( plr ) local X, Y = 0, 0 local px, py, pz = getElementPosition( PEDEK ) X = math.abs( x - px ) Y = math.abs( y - py ) faceMe = -math.deg( math.atan2( Y , X ) ) if(faceMe<0) then faceMe = 360.0 + faceMe end --guiSetText( label, tostring( faceMe ) ) setPedRotation( PEDEK, faceMe ) setPedLookAt( PEDEK, x, y, z + .5 ) setPedAimTarget ( PEDEK, x, y, z ) setPedControlState( PEDEK, "fire", true) end i havent tested Link to comment
veronapl Posted August 29, 2009 Author Share Posted August 29, 2009 Sorry, Your code not repair script. This is next Video: https://www.youtube.com/watch?v=MF7OZOg191I Link to comment
Gamesnert Posted August 29, 2009 Share Posted August 29, 2009 The script from the second video seems to be almost perfect. Only 1 problem: He just rotates in the opposite direction. So I think this will pretty much solve your problem: local plr = getLocalPlayer(); local PEDEK function greetingHandler ( ped ) PEDEK = ped outputChatBox ( "działa" ) addEventHandler( "onClientRender", getRootElement(), firenow) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", getRootElement(), greetingHandler ) function firenow() local x, y, z = getElementPosition( plr ); local X, Y = 0, 0; local px, py, pz = getElementPosition( PEDEK ); X = math.abs( x - px ); Y = math.abs( y - py ); faceMe = math.deg( math.atan2( Y , X ) ); --faceMe = ( 360 - math.deg ( math.atan2 ( ( px - x ), ( py - y ) ) ) ) % 360 if ( x >= px ) and ( y > py ) then -- north-east faceMe = 90 - faceMe elseif ( x <= px ) and ( y > py ) then -- north-west faceMe = 270 + faceMe elseif ( x >= px ) and ( y <= py ) then -- south-east faceMe = 90 + faceMe elseif ( x < px ) and ( y <= py ) then -- south-west faceMe = 270 - faceMe end --guiSetText( label, tostring( faceMe ) ); setPedRotation( PEDEK, 360-faceMe ); -- 360-rotation makes the ped rotation exactly opposite; which appears to be just what you need setPedLookAt( PEDEK, x, y, z + .5 ); setPedAimTarget ( PEDEK, x, y, z ) setPedControlState( PEDEK, "fire", true) end Link to comment
veronapl Posted August 29, 2009 Author Share Posted August 29, 2009 Gamesnert, not repair script Rotation Legs is ok, rotation torso is bad Why? 4nd video https://www.youtube.com/watch?v=sh5xOVBF93I Link to comment
50p Posted August 29, 2009 Share Posted August 29, 2009 Gamesnert, not repair script Rotation Legs is ok, rotation torso is bad Why? 4nd video https://www.youtube.com/watch?v=sh5xOVBF93I It seems that it's MTA's bug. I just tested my peds script, I gave them weapons (/giveweapon ) and they weren't aiming in the correct direction but they were walking in my direction between the shots. Like sniper rifle, when reloading you can walk a bit before the next shot. I made them aim my head and sometimes I did get hit but most of the time they missed me, even when I was standing still. Link to comment
vovo4ka Posted September 13, 2009 Share Posted September 13, 2009 I'm copypasted this code and have this: https://www.youtube.com/watch?v=3y44sQ-8ew4 Ped doesn't fire Link to comment
50p Posted September 13, 2009 Share Posted September 13, 2009 I'm copypasted this code and have this:https://www.youtube.com/watch?v=3y44sQ-8ew4 Ped doesn't fire She shakes because that's the animation for shooting. That usually happens when ped has no ammo. Link to comment
vovo4ka Posted September 13, 2009 Share Posted September 13, 2009 That usually happens when ped has no ammo. Yes))) Previously I gave weapons at the start but now every second by timer and she shooting Thx! 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