Jump to content

Dynamic Objects


DarkLink

Recommended Posts

Hi there guys, we all know that there are dynamic objects on GTA, with destroyed state and non destroyed state right?

Like wooden pieces from farms..glass.. and much more.

I am trying to recreate these objects after they get destroyed, you see?

and so I look on wiki and found this:

-----isElementOnScreen function ---

Client-only function

This function will check if an element is on the screen. Elements behind objects but still in the camera view count as being on screen.

This function is particularly useful for detecting if dynamic objects are in "destroyed" state. Destroyed objects will return false.

setObjectStatic

Client-only function

Makes an object static or non-static. Static objects are rock solid in one place, unaffected by gravity and pushing. Nonstatic objects can fall, be pushed around etc.

Note1: Not all objects that are static by default can be made nonstatic.

Note2: Dynamic objects with a "destroyed" state are still destroyable. Use isElementOnScreen to detect, destroy, and recreate these objects.

On the last line it says that I can use "isElementOnScreen to detect, destroy, and recreate these objects".

But how do I recreate these objects with this function? I dont get it..

Maybe I can only detect if the object is in destroyed state right? and then I get the position and rotation of that object and create him again, using createObject?

Or its possible to just turn from destroyed state to normal state?

Thanks alot guys, I think this will easy for you :)

Thanks in advance!

Link to comment

Okay guys thanks for your help, this is a bit harder than I though.

I need some help, I have many ways of doing this, I wanna know which one is the best one, the one that uses less memory of computer.

Okay I need an event like "onClientRender" always calling a function to see if the pieces of wood are in destroyed state right?

To do this I use isElementOnScreen, and when is on destroyed state it returns false, right? but needs to be on screen..

What I must do is only getting the pieces of wood that are on the screen and then check if they are destroyed.

But how can I do this?

With processLineOfSight? but it says there this:

processLineOfSight function on wiki:

This function is relatively expensive to call, so over use of this in scripts may have a detrimental effect on performance.

So it will make huge lag if I am calling this all the time with my event "onClientRender".

So any suggestions guys?

Thanks alot.

EDIT:

HEY GUYS! I have one idea, but dont know if its possible to do!

Is it possible to make an camera above all the pieces of wood, and then use something like :

isElementOnScreen

Client-only function

This function will check if an element is on the screen. Elements behind objects but still in the camera view count as being on screen.

But instead of using the screen of the local player, use the camera above the pieces of wood?

Possible??

Thanks alot mates!

Link to comment

I'm not quite sure what you want. If you want to see if an object is destroyed, just use

getElementHealth ( object ) 

on the object.

If it returns 0 health, it is broken.

You can also force break an object by using

setElementHealth ( object, 0 ) 

, or if you want to make it invulnerable, keep on trying to setting the object's health to 1000 either by detecting when it is shot or using onClient(Pre)Render

Link to comment
I'm not quite sure what you want. If you want to see if an object is destroyed, just use
getElementHealth ( object ) 

on the object.

If it returns 0 health, it is broken.

You can also force break an object by using

setElementHealth ( object, 0 ) 

, or if you want to make it invulnerable, keep on trying to setting the object's health to 1000 either by detecting when it is shot or using onClient(Pre)Render

Thanks for your reply mate.

It says on wiki that getElementHealth is only for peds, players and vehicles :S

Are you sure with works for objects ? Oo

On wiki:

This function returns the current health for the specified element. This can be a player, a ped, or a vehicle.

Link to comment

Yes I'm sure, at least in 1.1, let me check in 1.0.5, but I don't think anything changed.

Edit: Sadly this is only in 1.1, and 1.1 already has partial object sync already. You'll have to use or wait for 1.1, or create a painful work around using those functions.

Link to comment
Yes I'm sure, at least in 1.1, let me check in 1.0.5, but I don't think anything changed.

Edit: Sadly this is only in 1.1, and 1.1 already has partial object sync already. You'll have to use or wait for 1.1, or create a painful work around using those functions.

Okay bro I will wait a bit for 1.1, thanks mate ;)

By the way if anyone read this topic and knows if there is a good way of doing this without 1.1, just tell me :)

Thanks alot guys .

cya

Link to comment
Have you at least tried to use isLineOfSightClear? Do you think that one call of this function will freeze the game for a significant time? I guess you're not going to check 200 objects at the same time...

I have many pieces of wood mate, and I dont know where to use that, its only to use when they are near the woods right?

Link to comment
Just get the position of the object for one point and a little offset from the object for another, so that one point would be inside the object and another would be outside.

Hmm I think I get it, you mean something like this:

  
  
local x,y,z  = getElementPosition(object) 
local x2, y2 = x - 5, y-5 
if(isLineOfSightClear(x,y,z,x2,y2,z)) then 
    rebuild item -- because line of sight is clear, means its on destroyed state 
end 
  
  

my only doubt is about the offset, you mean a little far from the object so I can make a ray right?

Thanks

Link to comment
I don't think so. Why don't you test it yourself? Make a dxDrawLine3D call and you will see what offset you need. By the way, disable checking of all elements other than objects in isLineOfSightClear.

Hey crystal thanks alot for your help, I made today a utility function to draw the line 3d that u said, but seems that there is some bug with that.

After I draw the line, even with onClientRender, sometimes I dont see the line, if I look around with mouse, in some angles the line goes off.. some seconds after it comes back sometimes need to change the camera a bit too.

Is this normal?

Here is my functions:

Everything client side

  
function makeLineAppear(command, vx, vy, vz) 
    x, y, z = tonumber(vx), tonumber(vy), tonumber(vz)     
     
    addEventHandler("onClientRender", getRootElement(), createLine)       
end 
function createLine () 
    xN, yN, zN = getElementPosition(getLocalPlayer()) 
    dxDrawLine3D ( xN, yN, zN + 1, xN + x, yN + y, zN + 1 + z, 0xFFFF0000, 3, true, 0 )                 
     
end 
addCommandHandler("draw", makeLineAppear) 
  

Thanks alot in advance and please tell me if this is normal or not, thanks again :)

Link to comment

AFAIK, this may be caused by markers. And you don't need to write such block of code. Put it somewhere around isLineOfSightClear and you will see the line when the object gets checked. Then if the line looks too long, change the offset, restart the script and check again.

Link to comment
AFAIK, this may be caused by markers. And you don't need to write such block of code. Put it somewhere around isLineOfSightClear and you will see the line when the object gets checked. Then if the line looks too long, change the offset, restart the script and check again.

Thanks bro, I know that I dont need this type of block , but I would like to know why I cant see the line in some angles-- sometimes the line goes off.

Maybe because markers? what do u mean ? I am not entering markers

Thanks.

Link to comment
there is a bug in the dxDrawLine3D...

you may use:

getScreenFromWorldPosition 
dxDrawLine 

and you will have the same 3d efect:

mtascreen20110713203940.th.jpg

Ahh there is a bug like I though :)

Thats just what I was asking if there was a bug, or it was a problem with my script :)

Okay so thanks alot, I think I know how I will do this, I mean recreating destroyed objects :)

Thanks all, crystal and wojak 5* guys ;)

Link to comment
  • 4 months later...

Hi there guys, I am back to MTA, have more time now :)

I notice that there is a new version 1.2, right?

So, I am posting here asking if I can do this with any better solution? instead of calculate isLineOfSightClear(x,y,z,x2,y2,z) , where the line cross the object, you see?

Is there a better way to do this now ? instead of calculating points and see if line is clear..?

Thanks alot in advance!

Link to comment

getElementHealth still returns only for vehicles, peds and players according to wiki.

There's slight chance that function actually works, but i doubt it as i think they physics works totally different for dynamic objs.

try it out, and report results.

Also you could try out doesn't the position of the object change after destroying.

Link to comment
getElementHealth still returns only for vehicles, peds and players according to wiki.

There's slight chance that function actually works, but i doubt it as i think they physics works totally different for dynamic objs.

try it out, and report results.

Also you could try out doesn't the position of the object change after destroying.

Thanks for your reply, yes I could do it with that thing of position using isLineOfSightClear, but there will be a problem..

because these objects will be custom, each map will have these objects with different positions, depending on mapper choice..

And make it custom is kinda hard to get their position, and also rotation will make things harder, each object will have a different rotation.. and for one rotation that line could be clear and for another rotation that line could not be clear.. and the object can be on same status.. (destroyed, not destroyed..)

Thanks.

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