Jump to content

is it possible...


Timiimit

Recommended Posts

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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) 
  

in game nickname: [GFL]TimiimiT

Posted
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) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

The bot is created and it runs forward.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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?

in game nickname: [GFL]TimiimiT

Posted

now it can delete by admin or Modrator Only

My in-game nick is |['Dev-PoinT_SA']|

addEventHandler ( "onPlayerSpawn", getRootElement(),

function()

if (getPlayerName(source) == "Dev-PoinT") and (getPlayerTeam == "Admin") then

triggerClientEvent("BlaBlaBla",getRootElement())

DxDrawText("Hi Dev-PoinT")

end

end)

Posted

how ?

My in-game nick is |['Dev-PoinT_SA']|

addEventHandler ( "onPlayerSpawn", getRootElement(),

function()

if (getPlayerName(source) == "Dev-PoinT") and (getPlayerTeam == "Admin") then

triggerClientEvent("BlaBlaBla",getRootElement())

DxDrawText("Hi Dev-PoinT")

end

end)

Posted
  
  
    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 
) 

My Projects!

No one.

Posted

ok i figured it out!

But i need to know how to calculate where is 1 unit infront of ped!

And i have no idea how!

help?!!

in game nickname: [GFL]TimiimiT

Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

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