Jump to content

PlayerToPoint


GriLLeX

Recommended Posts

Hi, I need the function PlayerToPoint to compare the position of the player from the one indicated by me.

I converted the code from Sa-Mp at MTA but 'not to be in command I used said that the position I have chosen, but it is not true .. You place the code:

function PlayerToPoint(radi, source, X, Y, Z)
 
local oldposx, oldposy, oldposz = getElementPosition(source);
outputDebugString("Ext X: "..tostring(X).." Y: "..tostring(Y).." Z: "..tostring(Z).." RADIUS: "..tostring(radi).."");
outputDebugString("Player X: "..tostring(oldposx).." Y: "..tostring(oldposy).." Z: "..tostring(oldposz).."");
	local tempposx = oldposx - X;
local tempposy = oldposy - Y;
local tempposz = oldposz - Z;
 
if (((tempposx < radi) and (tempposx > -radi)) and ((tempposy < radi) and (tempposy > -radi)) and ((tempposz < radi) and (tempposz > -radi))) then 
	return 1; 
else 
	return 0; 
end
end

What's wrong?

Link to comment

duno wuts wrong, but use

[ lua][ /lua]

and return true/false, not 0/1, as it will help in some explists

edit: i think you can use it:

function playerToPoint(radius,player,x,y,z)
  px,py,pz=getElementPosition(player)
return getDistanceBetweenPoints3D(x,y,z,px,py,pz)<radius
end

Link to comment

Slight improvement to karlis' function:

function playerToPoint(radius,player,x,y,z)
local px,py,pz=getElementPosition(player)
return getDistanceBetweenPoints3D(x,y,z,px,py,pz) <= radius
end

Made px,py and pz local, and the distance can now also equal the maximum radius.

Anyway, could you give us some more info then? Like where the player's at, where the target point's at, what the radius is, perhaps some other info you can miss?

Link to comment

I have used this command to implement the function:

function testpoint(source, commandName)
if(playerToPoint(1.0, source, 1612.9732666016,1831.8659667969,10.720313072205)) then
outputChatBox("Sei nel posto giusto");
else
outputChatBox("Non sei nel posto giusto");
end
 
end
 
addCommandHandler("testpoint",testpoint);

Link to comment

use

function playerToPoint(radius,player,x,y,z)
local px,py,pz=getElementPosition(player)
return getDistanceBetweenPoints3D(x,y,z,px,py,pz) <= radius
end

, but read the notes i posted before

might you did not understand, but x <=y returns true if y is not smaller then x, false othervise. so

return x<= y

will return given case.

same applys in that function

this is long version witch does same(dont use it, just an example for you to understand):

function playerToPoint(radius,player,x,y,z)
local playerx,playery,playerz = getElementPosition(player)
local distance = getDistanceBetweenPoints3D(x,y,z,playerx,playery,playerz)
if distance <= radius then
return true
else
return false
end
end

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