SA-MP Forums Archive
Object Help! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Object Help! (/showthread.php?tid=404048)



Object Help! - megamind2067 - 01.01.2013

ok this is what I want to do with a certain object.

Код:
if(GetObjectPos(elevator) == 0.0.0 );(for example)
{
DestroyObject(elevator);
}
So if the object is at location 0.0.0 destroy the object.

How do I do it ? Can some one give me the correct code.


Re: Object Help! - DaRk_RaiN - 01.01.2013

Use the floats like
pawn Код:
new Float:x, Float:y, Float:z;
 GetObjectPos(elevator,x, y, z);
Then for the check
pawn Код:
if(GetObjectPos(elevator,x, y, z))
{
//bla bla
}



Re: Object Help! - megamind2067 - 01.01.2013

Код:
new Float:x, Float:y, Float:z;
if(GetObjectPos(elevator,x, y, z) == 1567.4233398438, -1634.6782226563, 18.896639823914);
Ok this is what I have ^ , But these are the error I get.

Код:
warning 206: redundant test: constant expression is non-zero
error 036: empty statement
both of those errors and warnings are on the same line:
Код:
if(GetObjectPos(elevator,x, y, z) == 1567.4233398438, -1634.6782226563, 18.896639823914);



Re: Object Help! - megamind2067 - 01.01.2013

anyone?? Help please!


Re: Object Help! - Vince - 01.01.2013

Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
Then for the check
pawn Код:
if(GetObjectPos(elevator,x, y, z))
{
//bla bla
}
What kind of stupid response is this? This just checks if the object exists. Not if it is one specified position. The right way to do it is:
pawn Код:
new Float:x, Float:y, Float:z;
GetObjectPos(elevator,x, y, z);

if(x == 1567.4233398438 && y == -1634.6782226563 && z = 18.896639823914)
{
    // do stuff
}
Although floats are not very accurate values due to the way they are being saved, so even if the location is off by 0.0001, this statement will return false. So to circumvent this, you might use GetDistanceBetweenPoints.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
pawn Код:
new Float:x, Float:y, Float:z;
GetObjectPos(elevator,x, y, z);

if(GetDistanceBetweenPoints(x, y, z, 1567.4233398438, -1634.6782226563, 18.896639823914) < 3.0)
{
    // do stuff
}