Jump to content

[HELP]Visão_Ped


Recommended Posts

  • Other Languages Moderators

Acho que não existe uma função nativa para isso. Pois precisaria de uma câmera para processar algo que está "vendo" ou não. E como todos nós sabemos, os Peds não possuem câmera, somente os jogadores.

Mas é possível calcular algo assim com algumas gambiarras, obtendo a rotação e posição do Ped e fazendo vários cálculos com a posição do objeto para que ele seja considerado "visível pelo Ped".

--------------------

Se o Ped estiver mirando em algo, você pode obter esse elemento com getPedTarget.

  • Thanks 1
Link to comment

Bom, Tentei utilizar getPedTarget Porém não foi útil, Então até que estava Dando uma olhada nas funções do SlothBot até que encontrei isLineOfSightClear

function onPedRender() 
local ped = getElementsByType ( "ped" ) 
    for theKey, thePed in ipairs(ped) do    
        if getElementData(thePed, "shoot") then 
            cancelEvent() 
            local x ,y, z = getElementPosition(thePed) 
            local sx, sy, sz = getElementPosition(localPlayer) 
            local Dist = getDistanceBetweenPoints3D (x, y, z, sx, sy, sz) 
			if(isLineOfSightClear(x, y, z, sx, sy, sz, true, false, false, false, false, false)) then 
            givePedWeapon(thePed, 31, 5000, true) 
            setPedControlState(thePed, "fire", true) 
            setPedAimTarget(thePed, sx, sy, sz) 
			StartBot ()
			else
            setPedControlState(thePed, "fire", false) 
       end 
     end 
     end 
   end  
addEventHandler("onClientPedDamage", root, onPedRender)

function StartBot ()
if isEventHandlerAdded("onClientRender", getRootElement(), onPedRender) then return end
addEventHandler("onClientRender", root, onPedRender) 
end

function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
	if 
		type( sEventName ) == 'string' and 
		isElement( pElementAttachedTo ) and 
		type( func ) == 'function' 
	then
		local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
		if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
			for i, v in ipairs( aAttachedFunctions ) do
				if v == func then
					return true
				end
			end
		end
	end

	return false
end

***CÓDIGO PARA QUE TALVEZ OUTRA PESSOA PRECISE***

Edited by danilin
Erro Ortográfico
Link to comment
  • Other Languages Moderators
8 hours ago, VazErn said:

Desculpe estar deixando minha resposta como usuário do fórum bem atrasada, sou muito ocupado.

Recomendo utilizar o recurso Slothbot.

Ele já usou isso, xD

Veja:

On 13/12/2018 at 19:12, danilin said:

Então até que estava Dando uma olhada nas funções do SlothBot até que encontrei isLineOfSightClear

 

  • Thanks 1
  • Haha 1
Link to comment

Eu cheguei a usar vazern só que quando algum ped e ativado perto de um slothbot o slothbot ataca o ped.
EX: No caso eu fiz um cenário com vários ped ai os slothbot mata apenas um desses ped e depois não ataca. Mas  isso me incomodou pois tava ficando 1 ped morto ai decidir não usar

  • Confused 1
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...