Kenix Posted February 7, 2012 Share Posted February 7, 2012 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
Timiimit Posted February 7, 2012 Author Share Posted February 7, 2012 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
Castillo Posted February 7, 2012 Share Posted February 7, 2012 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
Timiimit Posted February 7, 2012 Author Share Posted February 7, 2012 isn't this the same? + not working! Link to comment
Castillo Posted February 7, 2012 Share Posted February 7, 2012 The bot is created and it runs forward. Link to comment
Timiimit Posted February 7, 2012 Author Share Posted February 7, 2012 yes ut when it's close to elements it doesn't turn?!! Link to comment
Kenix Posted February 7, 2012 Share Posted February 7, 2012 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
Timiimit Posted February 8, 2012 Author Share Posted February 8, 2012 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
Evil-Cod3r Posted February 8, 2012 Share Posted February 8, 2012 now it can delete by admin or Modrator Only Link to comment
Timiimit Posted February 8, 2012 Author Share Posted February 8, 2012 it can be deleted by anyone! Link to comment
Timiimit Posted February 8, 2012 Author Share Posted February 8, 2012 help with working script! Link to comment
GanJaRuleZ Posted February 8, 2012 Share Posted February 8, 2012 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
Timiimit Posted February 11, 2012 Author Share Posted February 11, 2012 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?!! Link to comment
JR10 Posted February 11, 2012 Share Posted February 11, 2012 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
Agon Posted February 16, 2012 Share Posted February 16, 2012 dude don't copy all the code... just try to understand it.. Link to comment
Timiimit Posted February 23, 2012 Author Share Posted February 23, 2012 I have!! but don't know how to fix it! 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