Jump to content

How to set a ped facing a player?


bamby12

Recommended Posts

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
  
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

Ok you got me :P 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
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

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...