Jump to content

is it possible...


Timiimit

Recommended Posts

local scan_radius = 10 
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
addEventHandler( 'onClientRender',root, 
    function( ) 
        local rot 
        local bx,by,bz = getPedBonePosition( localPlayer,8 ) 
        rot = ( rot or 0 ) + 1 
        if rot > 360 then rot = 0 end 
        local nx,ny = getPointFromDistanceRotation( bx,by,scan_radius,rot ) 
        local hit = processLineOfSight( bx,by,bz,nx,ny,bz,  
            true, -- checkBuildings 
            false, -- checkVehicles 
            false, -- checkPlayers 
            false, -- checkObjects 
            false, -- checkDummies 
            false, -- seeThroughStuff 
            false, -- ignoreSomeObjectsForCamera 
            false, -- shootThroughStuff 
            nil, -- ignoredElement 
            false -- includeWorldModelInformation 
        ) 
        if not hit then 
            -- ... 
        end  
    end 
) 

Code updated.

Try it.

Link to comment

not working!

tried:

  
local scan_radius = 10 
local ped 
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
addCommandHandler( "botON", 
function() 
    ped = createPed( 312, 1989, -2190, 14, 180, 0, 180 ) 
    setPedAnimation( bot, "ped", "run_player" ) 
addEventHandler( 'onClientRender',root, 
    function( ) 
        local rot 
        local bx,by,bz = getPedBonePosition( bot,8 ) 
        rot = ( rot or 0 ) + 1 
        if rot > 360 then rot = 0 end 
        local nx,ny = getPointFromDistanceRotation( bx,by,scan_radius,rot ) 
        local hit = processLineOfSight( bx,by,bz,nx,ny,bz, 
            true, -- checkBuildings 
            false, -- checkVehicles 
            false, -- checkPlayers 
            false, -- checkObjects 
            false, -- checkDummies 
            false, -- seeThroughStuff 
            false, -- ignoreSomeObjectsForCamera 
            false, -- shootThroughStuff 
            nil, -- ignoredElement 
            false -- includeWorldModelInformation 
        )  
    end 
) 
end) 
  

Link to comment
local scan_radius = 10 
local ped 
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
addCommandHandler( "botON", 
function() 
    ped = createPed( 312, 1989, -2190, 14, 180, 0, 180 ) 
    setPedAnimation( ped, "ped", "run_player" ) 
addEventHandler( 'onClientRender',root, 
    function( ) 
        local rot 
        local bx,by,bz = getPedBonePosition( ped,8 ) 
        rot = ( rot or 0 ) + 1 
        if rot > 360 then rot = 0 end 
        local nx,ny = getPointFromDistanceRotation( bx,by,scan_radius,rot ) 
        local hit = processLineOfSight( bx,by,bz,nx,ny,bz, 
            true, -- checkBuildings 
            false, -- checkVehicles 
            false, -- checkPlayers 
            false, -- checkObjects 
            false, -- checkDummies 
            false, -- seeThroughStuff 
            false, -- ignoreSomeObjectsForCamera 
            false, -- shootThroughStuff 
            nil, -- ignoredElement 
            false -- includeWorldModelInformation 
        ) 
    end 
) 
end) 

Link to comment
local scan_radius = 10 
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
addEventHandler( 'onClientRender',root, 
    function( ) 
        local rot 
        local bx,by,bz = getPedBonePosition( localPlayer,8 ) 
        rot = ( rot or 0 ) + 1 
        if rot > 360 then rot = 0 end 
        local nx,ny = getPointFromDistanceRotation( bx,by,scan_radius,rot ) 
        local hit = processLineOfSight( bx,by,bz,nx,ny,bz,  
            true, -- checkBuildings 
            false, -- checkVehicles 
            false, -- checkPlayers 
            false, -- checkObjects 
            false, -- checkDummies 
            false, -- seeThroughStuff 
            false, -- ignoreSomeObjectsForCamera 
            false, -- shootThroughStuff 
            nil, -- ignoredElement 
            false -- includeWorldModelInformation 
        ) 
        if not hit then 
            dxDrawText( 'not hit',200,200 ) 
        end  
    end 
) 

This code for localPlayer just for test...

:/

If it working change for ped.

Added:if line not hit then draw text 'not hit'.

If you start something, you should start small.

Link to comment

ok! This is what i have:

  
    botPed = null 
  
function createBot() 
  if (botPed == null ) then 
    botPed = createPed( 312, 1989, -2190, 14, 180, 0, 180 ) 
    outputConsole("Bot is in game!") 
  else 
    outputConsole("Bot already exists.") 
  end 
end 
function deleteBot() 
  if (botPed ~= null) then 
    destroyElement( botPed ) 
    outputConsole("Bot has been deleted.") 
    botPed = null 
     
  else 
    outputConsole("No bot to remove.") 
  end 
end 
function smartBotON() 
   setPedAnimation( botPed, "ped", "run_player" ) 
   -- detection event 
   addEventHandler( "onClientRender", getRootElement(), detecting ) 
   -- detecting event 
   outputConsole( "Bot is now smart!" ) 
end 
function standBot() 
   setPedAnimation( botPed ) 
   outputConsole( "Bot is standing still." ) 
   removeEventHandler( "onClientRender", getRootElement(), detecting ) 
end 
function detecting( element, dim ) 
-- detection hit 
-- if hit must do "botHit()" 
end 
function botTurn() 
    if (botPed ~= null) then 
        outputDebugString("Bot turned in random direction.") 
        outputConsole("Bot turned in random direction.") 
        setPedRotation(botPed, getPedRotation(botPed) + math.random(90, 270)) 
    end 
end 
function botHit()    
   outputDebugString("Bot detected obsticale infront of it.") 
   outputConsole("Bot detected obsticale infront of it.") 
   botTurn() 
end 
addCommandHandler( "smart", smartBotON ) 
addCommandHandler( "stand", standBot ) 
addCommandHandler( "botON", createBot ) 
addCommandHandler( "botOFF", deleteBot ) 
  

I really hope no one will copy this code!

Is possible to delete topic?

Link to comment
  
  
    botPed = null 
  
function createBot() 
  if (botPed == null ) then 
    botPed = createPed( 312, 1989, -2190, 14, 180, 0, 180 ) 
    outputConsole("Bot is in game!") 
  else 
    outputConsole("Bot already exists.") 
  end 
end 
function deleteBot() 
  if (botPed ~= null) then 
    destroyElement( botPed ) 
    outputConsole("Bot has been deleted.") 
    botPed = null 
     
  else 
    outputConsole("No bot to remove.") 
  end 
end 
function smartBotON() 
   setPedAnimation( botPed, "ped", "run_player" ) 
   -- detection event 
   addEventHandler( "onClientRender", getRootElement(), detecting ) 
   -- detecting event 
   outputConsole( "Bot is now smart!" ) 
end 
function standBot() 
   setPedAnimation( botPed ) 
   outputConsole( "Bot is standing still." ) 
   removeEventHandler( "onClientRender", getRootElement(), detecting ) 
end 
function detecting( element, dim ) 
-- detection hit 
-- if hit must do "botHit()" 
end 
function botTurn() 
    if (botPed ~= null) then 
        outputDebugString("Bot turned in random direction.") 
        outputConsole("Bot turned in random direction.") 
        setPedRotation(botPed, getPedRotation(botPed) + math.random(90, 270)) 
    end 
end 
function botHit()    
   outputDebugString("Bot detected obsticale infront of it.") 
   outputConsole("Bot detected obsticale infront of it.") 
   botTurn() 
end 
addCommandHandler( "smart", smartBotON ) 
addCommandHandler( "stand", standBot ) 
addCommandHandler( "botON", createBot ) 
addCommandHandler( "botOFF", deleteBot ) 
  
local scan_radius = 10 
  
function getPointFromDistanceRotation(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  
addEventHandler( 'onClientRender',root, 
    function( ) 
        local rot 
        local bx,by,bz = getPedBonePosition( botPed,8 ) 
        rot = ( rot or 0 ) + 1 
        if rot > 360 then rot = 0 end 
        local nx,ny = getPointFromDistanceRotation( bx,by,scan_radius,rot ) 
        local hit = processLineOfSight( bx,by,bz,nx,ny,bz,  
            true, -- checkBuildings 
            false, -- checkVehicles 
            false, -- checkPlayers 
            false, -- checkObjects 
            false, -- checkDummies 
            false, -- seeThroughStuff 
            false, -- ignoreSomeObjectsForCamera 
            false, -- shootThroughStuff 
            nil, -- ignoredElement 
            false -- includeWorldModelInformation 
        ) 
        if not hit then 
            dxDrawText( 'not hit',200,200 ) 
        end  
    end 
) 

Link to comment

Use this function:

function getPositionInfrontOfElement ( element , meters ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( element ) 
    local _ , _ , rotation = getElementRotation ( element ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
    return posX , posY , posZ 
end 

Returns 3 values, containing the x,y,z position infront of the position you entered by the meters you specify above.

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