Jump to content

Управление ПЕДом


Recommended Posts

Привет всем. Делаю тут хотьбу для нпс, начитвашись поиска по форуму получился вот такой код:

сервер

  
function createMyPed ( source ) 
    local x,y,z = getElementPosition ( source ) 
    myped = createPed ( 1, x, y, z ) 
    setElementData (myped, "no", 1 ) 
    setTimer ( calculatePeds, 2000, 20, myped ) 
end 
addCommandHandler ("ao", createMyPed) 
  
function calculatePeds ( myped ) 
    local px, py, pz = getElementPosition( myped ) 
    local x, y, z = getPositionInfrontOfElement(myped, 1) 
    triggerClientEvent ( getElementSyncer ( myped ), "calculatePedSight", getElementSyncer ( myped ), px, py, pz, x, y, z ) 
end 
  
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 
  
function pedSightCalculatedS ( answer ) 
    if answer == 1 then 
         setPedAnimation(myped, "ped", "WALK_civi", -1, 1, 1, 0) 
    else 
        setPedAnimation ( myped ) 
        local rotation = math.random( 0, 360 ) 
        setElementRotation ( myped, 0,0, rotation ) 
    end 
end 
addEvent( "pedSightCalculated", true ) 
addEventHandler( "pedSightCalculated", getRootElement(), pedSightCalculatedS ) 
  

клиент

  
function calculatePedSightC ( px, py, pz, x, y, z ) 
    if ( isLineOfSightClear( px, py, pz, x, y, z ) == true ) then 
        outputChatBox ( "Открыто" ) 
        triggerServerEvent ( "pedSightCalculated", getLocalPlayer(), 1 )  
    else 
        outputChatBox ( "Закрыто" ) 
        triggerServerEvent ( "pedSightCalculated", getLocalPlayer(), 0 )  
    end 
end 
addEvent( "calculatePedSight", true ) 
addEventHandler( "calculatePedSight", getRootElement(), calculatePedSightC ) 
  

В итоге все вроде бы работает, но постоянно вылазиет "Закрыто" и, соответственно, нпс мой крутится, даже если перед ним ничего нет. Ну а если что то и есть, то он работает нормально, крутится пока не найдет свободное пространство, и, когда находит, пройдет один раз и снова начинает чередоваться "Закрыто", затем "Открыто". Может кто нить знает в чем проблема?

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