Jump to content

Requested Ped functions.


subenji99

Recommended Posts

We were playing with ped functions on my test server today and some functions were missing that we could really have used.

1. allow Weapon functions for peds.

I found it incredible that "setPedWeaponSlot" exists, but weapon functions such as "giveWeapon" only work on players! i assume this is actually an oversight, or there is another method i overlooked.

2. setPedRotateAt

This is what I expected "setPedLookAt" to do,but that only moves the ped's head - not particularly useful. I ended up attempting some complex vector maths to work out the rotation angle to get a created ped to face my player - and failed.

While the ultimate ped functions I would like would be to set a ped's "task", even just the simple primary and/or secondary if complex tasks are not possible, these few functions would help out quite a bit for anyone coding with peds in my opinion.

Link to comment

2. setPedRotateAt

This is what I expected "setPedLookAt" to do,but that only moves the ped's head - not particularly useful. I ended up attempting some complex vector maths to work out the rotation angle to get a created ped to face my player - and failed.

You could use arctan for getting the angle. Something like this I guess, if I mess up, don't blame me, technically I've not learned this in school yet. :P (tan alpha was a/b right?)

  
local x1, y1,_ = getElementPosition(thePlayer) 
local x2,y2,_ = getElementPosition(thePed) 
local xdist, ydist = = x1 - x2, y1 - y2 
local theRot = math.atan(xdist/ydist)   
setPedRotation(thePed, theRot) 
  

Now if someone finds something wrong, please correct me :)

Link to comment

heres a bit of code i ripped off of an old script by erorr404. this sounds like what you need.

local targetx, targety, targetz = getElementPosition ( yourtarget ) 
local pedx, pedy, pedz = getElementPosition ( theped ) 
newangle = ( 360 - math.deg ( math.atan2 ( ( targetx - pedx ), ( targety - pedy ) ) ) ) % 360 

as far as i know, its witchcraft, so dont ask me to explain how it works, but it does :wink:

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