cacao

(help) colshape & object

Recommended Posts

Hi everyone!

have here server-side script

local col = createColCircle(170, -377, 15)
local object = createObject(737, 175, -377, 6)
print(isElementWithinColShape(object, col)) -- print false

 

Can anyone tell me, why i got false, when object IN colshape?

Object and colshape have same coordinates.

Edited by cacao

Share this post


Link to post

Wikia colshape created on the client does not collide with elements already existing at that location until they first move.

Share this post


Link to post

But i'm create colshape on the server and first i'm created the colshape before the object

Edited by cacao

Share this post


Link to post
local col = createColCircle(170, -377, 15)
local object = createObject(737, 175, -377, 6)
moveObject ( object, 100, 175, -378, 6 )
setTimer(function()
    print(isElementWithinColShape(object, col))
end, 500, 1, object)

I don't know if I did right, but try something like this, try using timers, since you have to move the element if they are at the same position when being created. So MTA can recognize when did the element hit the collision shape, so it can assign the isElementWithinColShape function to it, I guess. Try using something like I posted.

Share this post


Link to post
8 minutes ago, Dzsozi said:

local col = createColCircle(170, -377, 15)
local object = createObject(737, 175, -377, 6)
moveObject ( object, 100, 175, -378, 6 )
setTimer(function()
    print(isElementWithinColShape(object, col))
end, 500, 1, object)

I don't know if I did right, but try something like this, try using timers, since you have to move the element if they are at the same position when being created. So MTA can recognize when did the element hit the collision shape, so it can assign the isElementWithinColShape function to it, I guess. Try using something like I posted.

I tried it, but still false. :(

VrwbKdpUDpKOAX.jpg

Edited by cacao

Share this post


Link to post
5 minutes ago, Dzsozi said:

Did the object move?

Yes.Look:

Before

GrqvQpVHDoNPmz.jpg

After

MAjbvqRUDnvWAe.jpg

 

Result

52avGlJHXL4nA0.jpg

Edited by cacao

Share this post


Link to post

Maybe try creating the object outside of the colshape and then move it inside the colshape using moveobject and use a timer to print the text, see if it works.

Share this post


Link to post

It works, but it strange.

Look, i switch createObject and colCircle and it's true, but it is strange..

gmvbLWjUD7qyma.jpg

I need to create in colshape objects and later check them counts..

Edited by cacao
  • Like 1

Share this post


Link to post

You can move the colshape before you check the object though:

local col = createColCircle(2306.687, -1658.936, 14.386)
local object = createObject(737, 2306.687, -1658.936, 14.386)

addCommandHandler("c",
    function()
        local x,y,z = getElementPosition(col)
        setElementPosition(col,x,y,z+1)
        setElementPosition(col,x,y,z)
        print(isElementWithinColShape(object, col))
    end
)

I don't really know why it doesn't work normally, MTA is weird.

Edited by Tails

Share this post


Link to post
1 hour ago, cacao said:

It works, but it strange.

Look, i switch createObject and colCircle and it's true, but it is strange..

gmvbLWjUD7qyma.jpg

I need to create in colshape objects and later check them counts..

May I ask which Editor you use? I like the linter better than my N++, is this Sublime Text perhaps?

Share this post


Link to post
34 minutes ago, ViRuZGamiing said:

May I ask which Editor you use? I like the linter better than my N++, is this Sublime Text perhaps?

Atom (https://atom.io)

UI Theme: Atom Material

Theme: Apathy

Packages: linter, linter-lua, language-lua

Edited by cacao
  • Like 1

Share this post


Link to post

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.