bamby12 Posted February 7, 2011 Share Posted February 7, 2011 is it possible to make a ped face a player using setPedRotation? what im trying to do is make a ped spawn in front of a player then face him. Link to comment
Discord Moderators Zango Posted February 7, 2011 Discord Moderators Share Posted February 7, 2011 https://wiki.multitheftauto.com/wiki/FindRotation Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 https://wiki.multitheftauto.com/wiki/FindRotation This should work, thanks. EDIT: ok im trying to createped with a timer and make the ped face the player, heres the code i used. function peds() local x, y, z = getElementPosition ( source ) local target = createPed(math.random(0,150), x+5, y, z) if not target then outputChatBox("Invalid player", player) end local x,y,z = getElementPosition(target) local tx,ty,tz = getElementPosition(player) setPedRotation(target, findRotation(x,y,tx,ty) ) end i get 2 errors, bad argument @ getelementposition and attempt to perform arithmetic on local 'x' a nil value any help appreciated guys. Link to comment
Aibo Posted February 7, 2011 Share Posted February 7, 2011 both your errors are caused by invalid source variable. (and why are you using source AND player variable?) where is the code that calls this function? Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 function enterVehicle ( theVehicle, seat, jacked ) outputChatBox ( "You sit in the car and suddenly feel extremely drunk!", source ) end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) function peds() local x, y, z = getElementPosition ( source ) local target = createPed(math.random(0,150), x+5, y, z) if not target then outputChatBox("Invalid player", player) end local x,y,z = getElementPosition(target) local tx,ty,tz = getElementPosition(player) setPedRotation(target, findRotation(x,y,tx,ty) ) end thats the full code. Link to comment
Aibo Posted February 7, 2011 Share Posted February 7, 2011 well that part has nothing to do with peds() function. it cant be the full code, since peds() function is never called in this code, so you cant possibly have those errors shown. Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 Ok you got me this is the full code: function enterVehicle ( theVehicle, seat, jacked ) outputChatBox ( "You sit in the car and suddenly feel extremely drunk!", source ) cheesetime = setTimer(peds, 2000) --add effects after, this is what i tried to delete seeing as you dont need it. end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) function peds() local x, y, z = getElementPosition ( source ) local target = createPed(math.random(0,150), x+5, y, z) if not target then outputChatBox("Invalid player", player) end local x,y,z = getElementPosition(target) local tx,ty,tz = getElementPosition(player) setPedRotation(target, findRotation(x,y,tx,ty) ) end Link to comment
Castillo Posted February 7, 2011 Share Posted February 7, 2011 function enterVehicle ( theVehicle, seat, jacked ) outputChatBox ( "You sit in the car and suddenly feel extremely drunk!", source ) cheesetime = setTimer(peds, 2000,0,source) --add effects after, this is what i tried to delete seeing as you dont need it. end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) function peds(player) local x, y, z = getElementPosition ( player ) local target = createPed(math.random(0,150), x+5, y, z) if not target then outputChatBox("Invalid player", player) end local x,y,z = getElementPosition(target) local tx,ty,tz = getElementPosition(player) setPedRotation(target, findRotation(x,y,tx,ty) ) end Should work. Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 still get the same errors on line 9. and 10. Link to comment
Castillo Posted February 7, 2011 Share Posted February 7, 2011 copy the last code, i've found a error and edited it. Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 Thanks that worked kind of, the peds spawn but they dont face me, error: attempt to call global 'findRotation' Link to comment
Aibo Posted February 7, 2011 Share Posted February 7, 2011 well findRotation is not a built-in MTA function, you need to add it to your script to use it. Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 i dont understand Aiboforcen? Link to comment
Aibo Posted February 7, 2011 Share Posted February 7, 2011 add this function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end to your script Link to comment
bamby12 Posted February 7, 2011 Author Share Posted February 7, 2011 Works thank you!! one more question, do i use animations to make the peds walk? EDIT: https://community.multitheftauto.com/index.php?p= ... ls&id=1319 - would have been just as good but thanks for your help guys. 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