GriLLeX Posted April 24, 2010 Share Posted April 24, 2010 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
karlis Posted April 24, 2010 Share Posted April 24, 2010 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
GriLLeX Posted April 24, 2010 Author Share Posted April 24, 2010 I apologize for the syntax of the code, however I tried the code but go anyway. He says he is not the point ... Link to comment
Gamesnert Posted April 24, 2010 Share Posted April 24, 2010 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
GriLLeX Posted April 24, 2010 Author Share Posted April 24, 2010 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
karlis Posted April 25, 2010 Share Posted April 25, 2010 thanks gamesnert. heres few notes: 1) it is recommended to use player as first argument, it will improve compability then. 2)this detects is player in sphere of given radius, not in cube 3)if you want events when you enter the point use colshapes better Link to comment
GriLLeX Posted April 25, 2010 Author Share Posted April 25, 2010 Then, I'll explain: I need a function that checks whether the player is in a certain position if that position sends a message that is in place, otherwise sends the opposite. What should I use? Link to comment
karlis Posted April 25, 2010 Share Posted April 25, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now