Is player near object -
zaibaslr2 - 06.10.2014
Hey guys,
I need some help about objects and coordinates.
How can I check if a player is near object?
I can't use IsPlayerInRangeOfPoint, because the object is flat and big.
Well, image explains everything:
That is my object:
It's quite big and has asymmetric shape.
Thanks for any help.
Re: Is player near object -
Rudy_ - 06.10.2014
Then try like this?
i don't know any other way
Re: Is player near object -
GiamPy. - 06.10.2014
https://sampforum.blast.hk/showthread.php?tid=427810
Re: Is player near object -
zaibaslr2 - 06.10.2014
Quote:
Originally Posted by GiamPy.
|
Yeah I tried that, but there's one problem - it allows you to detect X and Y only, but the object is 3D, so it has Z coordinate too..
Re: Is player near object -
davve95 - 06.10.2014
It would be nice if there were some function like GetObjectPatternPos..
Idk if it's even possible...
Edit: I deleted what I wrote before as it woulden't work..
Re: Is player near object -
Pottus - 06.10.2014
I don't think your going to get much luck with this to be honest it can work with simple primitive shapes spheres, cubes, rectangles not so much with an oddball shaped object like what you have however you could use a rectangular area but there will be loss of precision.
Re: Is player near object -
Anzipane - 06.10.2014
You could check if a player is in a certain rectangular prism, for example. Here's a drawing I made:
Re: Is player near object -
zaibaslr2 - 06.10.2014
Thanks,
But what if I change object's rotation?
Re: Is player near object -
Pottus - 06.10.2014
Quote:
Originally Posted by zaibaslr2
Thanks,
But what if I change object's rotation?
|
There is a way to do that maybe someone else has a better idea but you could translate the players position based on the rotation of the object then do an area check then could just use the streamer to check.
pawn Код:
IsPointInDynamicArea(areaid, Float:x, Float:y, Float:z);
This can translate your players position back to a 0,0,0 orientation in correlation of your object basically you give the inverse rotational values of the object as the translation.
Credit: Stylock
pawn Код:
stock AttachPoint(Float:offx, Float:offy, Float:offz, Float:offrx, Float:offry, Float:offrz, Float:px, Float:py, Float:pz, Float:prx, Float:pry, Float:prz, &Float:RetX, &Float:RetY, &Float:RetZ, &Float:RetRX, &Float:RetRY, &Float:RetRZ, sync_rotation = 1)
{
new
Float:g_sin[3],
Float:g_cos[3],
Float:off_x,
Float:off_y,
Float:off_z;
EDIT_FloatEulerFix(prx, pry, prz);
off_x = offx - px; // static offset
off_y = offy - py; // static offset
off_z = offz - pz; // static offset
// Calculate the new position
EDIT_FloatConvertValue(prx, pry, prz, g_sin, g_cos);
RetX = px + off_x * g_cos[1] * g_cos[2] - off_x * g_sin[0] * g_sin[1] * g_sin[2] - off_y * g_cos[0] * g_sin[2] + off_z * g_sin[1] * g_cos[2] + off_z * g_sin[0] * g_cos[1] * g_sin[2];
RetY = py + off_x * g_cos[1] * g_sin[2] + off_x * g_sin[0] * g_sin[1] * g_cos[2] + off_y * g_cos[0] * g_cos[2] + off_z * g_sin[1] * g_sin[2] - off_z * g_sin[0] * g_cos[1] * g_cos[2];
RetZ = pz - off_x * g_cos[0] * g_sin[1] + off_y * g_sin[0] + off_z * g_cos[0] * g_cos[1];
if (sync_rotation)
{
// Calculate the new rotation
EDIT_FloatConvertValue(asin(g_cos[0] * g_cos[1]), atan2(g_sin[0], g_cos[0] * g_sin[1]) + offrz, atan2(g_cos[1] * g_cos[2] * g_sin[0] - g_sin[1] * g_sin[2], g_cos[2] * g_sin[1] - g_cos[1] * g_sin[0] * -g_sin[2]), g_sin, g_cos);
EDIT_FloatConvertValue(asin(g_cos[0] * g_sin[1]), atan2(g_cos[0] * g_cos[1], g_sin[0]), atan2(g_cos[2] * g_sin[0] * g_sin[1] - g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
EDIT_FloatConvertValue(atan2(g_sin[0], g_cos[0] * g_cos[1]) + offrx, asin(g_cos[0] * g_sin[1]), atan2(g_cos[2] * g_sin[0] * g_sin[1] + g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] - g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
RetRX = asin(g_cos[1] * g_sin[0]);
RetRY = atan2(g_sin[1], g_cos[0] * g_cos[1]) + offry;
RetRZ = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]);
}
}
stock EDIT_FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3])
{
sin[0] = floatsin(rot_x, degrees);
sin[1] = floatsin(rot_y, degrees);
sin[2] = floatsin(rot_z, degrees);
cos[0] = floatcos(rot_x, degrees);
cos[1] = floatcos(rot_y, degrees);
cos[2] = floatcos(rot_z, degrees);
return 1;
}
/*
* Fixes a bug that causes objects to not rotate
* correctly when rotating on the Z axis only.
*/
stock EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
&& (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
{
rot_y = 0.00000002;
}
return 1;
}
stock EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
EDIT_FloatRemainder(rot_x, 360.0);
EDIT_FloatRemainder(rot_y, 360.0);
EDIT_FloatRemainder(rot_z, 360.0);
return 1;
}
stock EDIT_FloatRemainder(&Float:remainder, Float:value)
{
if(remainder >= value)
{
while(remainder >= value)
{
remainder = remainder - value;
}
}
else if(remainder < 0.0)
{
while(remainder < 0.0)
{
remainder = remainder + value;
}
}
return 1;
}
Re: Is player near object -
zaibaslr2 - 06.10.2014
Quote:
Originally Posted by Pottus
There is a way to do that maybe someone else has a better idea but you could translate the players position based on the rotation of the object then do an area check then could just use the streamer to check.
pawn Код:
IsPointInDynamicArea(areaid, Float:x, Float:y, Float:z);
This can translate your players position back to a 0,0,0 orientation in correlation of your object basically you give the inverse rotational values of the object as the translation.
Credit: Stylock
pawn Код:
stock AttachPoint(Float:offx, Float:offy, Float:offz, Float:offrx, Float:offry, Float:offrz, Float:px, Float:py, Float:pz, Float:prx, Float:pry, Float:prz, &Float:RetX, &Float:RetY, &Float:RetZ, &Float:RetRX, &Float:RetRY, &Float:RetRZ, sync_rotation = 1) { new Float:g_sin[3], Float:g_cos[3], Float:off_x, Float:off_y, Float:off_z;
EDIT_FloatEulerFix(prx, pry, prz);
off_x = offx - px; // static offset off_y = offy - py; // static offset off_z = offz - pz; // static offset
// Calculate the new position EDIT_FloatConvertValue(prx, pry, prz, g_sin, g_cos); RetX = px + off_x * g_cos[1] * g_cos[2] - off_x * g_sin[0] * g_sin[1] * g_sin[2] - off_y * g_cos[0] * g_sin[2] + off_z * g_sin[1] * g_cos[2] + off_z * g_sin[0] * g_cos[1] * g_sin[2]; RetY = py + off_x * g_cos[1] * g_sin[2] + off_x * g_sin[0] * g_sin[1] * g_cos[2] + off_y * g_cos[0] * g_cos[2] + off_z * g_sin[1] * g_sin[2] - off_z * g_sin[0] * g_cos[1] * g_cos[2]; RetZ = pz - off_x * g_cos[0] * g_sin[1] + off_y * g_sin[0] + off_z * g_cos[0] * g_cos[1];
if (sync_rotation) { // Calculate the new rotation EDIT_FloatConvertValue(asin(g_cos[0] * g_cos[1]), atan2(g_sin[0], g_cos[0] * g_sin[1]) + offrz, atan2(g_cos[1] * g_cos[2] * g_sin[0] - g_sin[1] * g_sin[2], g_cos[2] * g_sin[1] - g_cos[1] * g_sin[0] * -g_sin[2]), g_sin, g_cos); EDIT_FloatConvertValue(asin(g_cos[0] * g_sin[1]), atan2(g_cos[0] * g_cos[1], g_sin[0]), atan2(g_cos[2] * g_sin[0] * g_sin[1] - g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos); EDIT_FloatConvertValue(atan2(g_sin[0], g_cos[0] * g_cos[1]) + offrx, asin(g_cos[0] * g_sin[1]), atan2(g_cos[2] * g_sin[0] * g_sin[1] + g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] - g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
RetRX = asin(g_cos[1] * g_sin[0]); RetRY = atan2(g_sin[1], g_cos[0] * g_cos[1]) + offry; RetRZ = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]); } }
stock EDIT_FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3]) { sin[0] = floatsin(rot_x, degrees); sin[1] = floatsin(rot_y, degrees); sin[2] = floatsin(rot_z, degrees); cos[0] = floatcos(rot_x, degrees); cos[1] = floatcos(rot_y, degrees); cos[2] = floatcos(rot_z, degrees); return 1; }
/* * Fixes a bug that causes objects to not rotate * correctly when rotating on the Z axis only. */ stock EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z) { EDIT_FloatGetRemainder(rot_x, rot_y, rot_z); if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0)) && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0))) { rot_y = 0.00000002; } return 1; }
stock EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z) { EDIT_FloatRemainder(rot_x, 360.0); EDIT_FloatRemainder(rot_y, 360.0); EDIT_FloatRemainder(rot_z, 360.0); return 1; }
stock EDIT_FloatRemainder(&Float:remainder, Float:value) { if(remainder >= value) { while(remainder >= value) { remainder = remainder - value; } } else if(remainder < 0.0) { while(remainder < 0.0) { remainder = remainder + value; } } return 1; }
|
Thank you!