lua sa-mp draw line

6jorn_

Member
Joined
Jun 4, 2018
Messages
13
Reaction score
0
Location
Netherlands
is it possible to draw a line from your own coordinates to the other player?

i have something like this now. 

before this I write give the id of myself and the other player so that it can draw a line from coordinate XY to XY but it doesnt work.

Code:
function gfx(arg,posX,posY)
 if #arg > 0 then
id = tonumber(arg)
result, ped = sampGetCharHandleBySampPlayerId(id)
if result then
myX, myY, myZ = getCharCoordinates(ped)
while true do
renderDrawLine(myX, myY, posX,posY, 2.0, 0xFF0000)
wait ( 0 ) 
end
end
end
end
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
You have to translate 3d coords into 2d coords, look up for worldToScreen functions on the internet, i bet theyre mostly on C++ but it's not hard to make em work on lua i guess
 

6jorn_

Member
Joined
Jun 4, 2018
Messages
13
Reaction score
0
Location
Netherlands
Already tried that before still shows no line
Code:
function gfx(arg,posX,posY,posZ)
	if #arg > 0 then
		id = tonumber(arg)
		result, ped = sampGetCharHandleBySampPlayerId(id)
		if result then
			myX, myY, myZ = getCharCoordinates(ped)
			local pedX, pedY = convert3DCoordsToScreen(posX,posY,posZ)
            local meX, meY = convert3DCoordsToScreen(myX, myY, myZ)    
			while result do
				renderDrawLine(pedX ,pedY ,meX, meY, 2, 0xFF00FF00)
				wait ( 0 ) 
			end
		end
	end
end
 

6jorn_

Member
Joined
Jun 4, 2018
Messages
13
Reaction score
0
Location
Netherlands
DavidRO99 said:
Wait, ill pull this out of my old LUA cheat.

I got it man its working but it only shows it for like 1 second. & I need something that keeps refresehing the coordinates of the given id or will that lag my game? I just have to type /find (playerId) now to refresh the coordinates

Code:
--info
 meposX, meposY, meposZ = getCharCoordinates(PLAYER_PED)
--_, getId = sampGetPlayerIdByCharHandle(PLAYER_PED)


local GET_COORDS_X, GET_COORDS_Y = convert3DCoordsToScreen(posX, posY, posZ)
local GET_COORDS_me_X, GET_COORDS_me_Y = convert3DCoordsToScreen(meposX, meposY, meposZ)  

for i = 1,60 do
renderDrawLine(GET_COORDS_X, GET_COORDS_Y ,GET_COORDS_me_X, GET_COORDS_me_Y, 2, 0xFF00FF00)
end
 

DavidRO99

Active member
Joined
Nov 5, 2017
Messages
60
Reaction score
8
Make a while loop and put wait(0) at the top so it draws constantly.
 

_=Gigant=_

Well-known member
Joined
Mar 21, 2017
Messages
353
Reaction score
16
ItsYaBoii32 said:
is it possible to draw a line from your own coordinates to the other player?

i have something like this now. 

before this I write give the id of myself and the other player so that it can draw a line from coordinate XY to XY but it doesnt work.

Code:
function gfx(arg,posX,posY)
 if #arg > 0 then
id = tonumber(arg)
result, ped = sampGetCharHandleBySampPlayerId(id)
if result then
myX, myY, myZ = getCharCoordinates(ped)
while true do
renderDrawLine(myX, myY, posX,posY, 2.0, 0xFF0000)
wait ( 0 ) 
end
end
end
end

if imgui.Button('Tracers') then
lua_thread.create(function()
wait (0)
  for id= 0, 1000 do
   local result = sampIsPlayerConnected(id) 
  local _, other_player = sampGetCharHandleBySampPlayerId(id)
  local PedPosX, PedPosY, PedPosZ = getCharCoordinates(other_player)   
  local meposX, meposY, meposZ = getCharCoordinates(PLAYER_PED)
  local GET_COORDS_X, GET_COORDS_Y = convert3DCoordsToScreen(PedPosX, PedPosY, PedPosZ)
  local GET_COORDS_me_X, GET_COORDS_me_Y = convert3DCoordsToScreen(meposX, meposY, meposZ)   
  renderDrawLine(GET_COORDS_X, GET_COORDS_Y, GET_COORDS_me_X, GET_COORDS_me_Y, 2, 0xFF00FF00)
end            
end)
end
 

6jorn_

Member
Joined
Jun 4, 2018
Messages
13
Reaction score
0
Location
Netherlands
Code:
function gfx()

	--info
	meposX, meposY, meposZ = getCharCoordinates(PLAYER_PED)
	--_, getId = sampGetPlayerIdByCharHandle(PLAYER_PED)
	
	
	local GET_COORDS_X, GET_COORDS_Y = convert3DCoordsToScreen(posX, posY, posZ)
	local GET_COORDS_me_X, GET_COORDS_me_Y = convert3DCoordsToScreen(meposX, meposY, meposZ)  
	
	while true do
		renderDrawLine(GET_COORDS_X, GET_COORDS_Y ,GET_COORDS_me_X, GET_COORDS_me_Y, 2, 0xFF00FF00)
		wait ( 0 ) <---- giving c callback error?
	end	
	
end





moonloader.log



Code:
[13:01:56.551288] (error)	PlayerFinder: ...ckstar Games\GTA San Andreas\moonloader\playerFinder.lua:61: attempt to yield across C-call boundary
stack traceback:
	[C]: in function 'wait'
	...ckstar Games\GTA San Andreas\moonloader\playerFinder.lua:61: in function 'gfx'
	...ckstar Games\GTA San Andreas\moonloader\playerFinder.lua:23: in function <...ckstar Games\GTA San Andreas\moonloader\playerFinder.lua:16>
 
Top