Kenix Posted February 7, 2012 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. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Timiimit Posted February 7, 2012 Author 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) in game nickname: [GFL]TimiimiT
Castillo Posted February 7, 2012 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) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Timiimit Posted February 7, 2012 Author Posted February 7, 2012 isn't this the same? + not working! in game nickname: [GFL]TimiimiT
Castillo Posted February 7, 2012 Posted February 7, 2012 The bot is created and it runs forward. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Timiimit Posted February 7, 2012 Author Posted February 7, 2012 yes ut when it's close to elements it doesn't turn?!! in game nickname: [GFL]TimiimiT
Kenix Posted February 7, 2012 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. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Timiimit Posted February 8, 2012 Author 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? in game nickname: [GFL]TimiimiT
Evil-Cod3r Posted February 8, 2012 Posted February 8, 2012 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)
Timiimit Posted February 8, 2012 Author Posted February 8, 2012 no! It can't! in game nickname: [GFL]TimiimiT
Evil-Cod3r Posted February 8, 2012 Posted February 8, 2012 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)
Timiimit Posted February 8, 2012 Author Posted February 8, 2012 it can be deleted by anyone! in game nickname: [GFL]TimiimiT
Timiimit Posted February 8, 2012 Author Posted February 8, 2012 help with working script! in game nickname: [GFL]TimiimiT
GanJaRuleZ Posted February 8, 2012 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 ) My Projects! No one.
Timiimit Posted February 11, 2012 Author 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?!! in game nickname: [GFL]TimiimiT
JR10 Posted February 11, 2012 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. 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
Timiimit Posted February 16, 2012 Author Posted February 16, 2012 not working! in game nickname: [GFL]TimiimiT
Agon Posted February 16, 2012 Posted February 16, 2012 dude don't copy all the code... just try to understand it..
Timiimit Posted February 23, 2012 Author Posted February 23, 2012 I have!! but don't know how to fix it! in game nickname: [GFL]TimiimiT
Kenix Posted February 23, 2012 Posted February 23, 2012 Show your code. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
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