Jump to content

Ближайшая больница


Recommended Posts

Хочу замутить респавн в ближайшей больнице.

Можно ли как нибудь

выставить столбик координат например

(больницы)

x1, y1, z1 --сантос

x2, y2, z2 -- фиерро

x3, y3, z3 -- вентурас

при смерти определяется ближайшая из них к мертвому игроку

и

repeat until spawnPlayer ( player, xyz, 90.0, skin, 0, 0) 

заранее спс

Link to comment
local hospitalSpawns = 
{ 
    { x, y, z }, 
    { x, y, z }, 
    { x, y, z } 
} 
  
local myX, myY, myZ = getElementPosition( player ) 
local mySp, myDis   = 1, 99999 
  
for i, sp in ipairs( hospitalSpawns ) do 
    local dis = getDistanceBetweenPoints3D( sp[ 1 ], sp[ 2 ], sp[ 3 ], myX, myY, myZ ) 
    if dis < myDis then 
        myDis = dis 
        mySp  = i 
    end 
end 
  
spawnPlayer( player, hospitalSpawns[ mySp ][ 1 ], hospitalSpawns[ mySp ][ 2 ], hospitalSpawns[ mySp ][ 3 ], 90.0, skin, 0, 0 ) 

Link to comment

Вот вставил в свой модифицированый плей

И в дебаге ругается на строку 26

26: attempt to compare boolean with number

    function spawn(player) 
        if not isElement(player) then return end 
        repeat until spawnPlayer ( player, -1971.608+math.random(-2,2), 137.871+math.random(-2,2), 27.6876, 90.0, math.random(312), 0, 0) 
        fadeCamera(player, true) 
        setCameraTarget(player, player) 
        showChat(player, true) 
    end 
  
local hospitalSpawns = 
{ 
    { 2027.77, -1420.52, 15.99, }, 
    { 1180.85, -1325.57, 12.58, }, 
    { 1244.437, 331.2261, 18.5547, }, 
    { -2199.719, -2308.075, 29.6181, }, 
    { -2670.285, 616.4364, 13.4531, }, 
    { -316.3832, 1056.045, 18.7344, }, 
    { -1514.823, 2527.119, 54.7443, }, 
    { 1578.446, 1770.682, 9.8358, } 
} 
  
local myX, myY, myZ = getElementPosition( player ) 
local mySp, myDis   = 1, 99999 
     
for i, sp in ipairs( hospitalSpawns ) do 
    local dis = getDistanceBetweenPoints3D( sp[ 1 ], sp[ 2 ], sp[ 3 ], myX, myY, myZ ) 
    if dis < myDis then 
        myDis = dis 
        mySp  = i 
    end 
end  
  
  function respawn(player, skin) 
     if not isElement(player) then return end 
     repeat until spawnPlayer ( player, hospitalSpawns[ mySp ][ 1 ], hospitalSpawns[ mySp ][ 2 ], hospitalSpawns[ mySp ][ 3 ], 90.0, skin, 0, 0 ) 
      fadeCamera(player, true) 
     setCameraTarget(player, player) 
     showChat(player, true) 
  end 
   
  
      
    addEventHandler("onPlayerJoin", root, 
        function() 
            spawn(source) 
        end 
    ) 
  
--addEventHandler("onPlayerWasted", root, 
    --function() 
        --setTimer(respawn, 1800, 1, source, getElementModel(source)) 
    --end 
--) 
  
   addEventHandler("onPlayerWasted", root, 
        function() 
            resetMapInfo() 
            for i,player in ipairs(getElementsByType("player")) do 
                respawn(source) 
                                 
            end 
        end 
    )    
  
function isValidSkin( thePlayer, command, specifiedSkin )  -- Define the function 
    if ( specifiedSkin ) then -- If skin specified 
        local allSkins = getValidPedModels ( ) -- Get valid skin IDs 
        local result = false -- Define result, it is currently false 
        for key, skin in ipairs( allSkins ) do -- Check all skins 
            if skin == tonumber( specifiedSkin ) then -- If skin equals specified one, it is valid 
                result = skin -- So set it as result 
                break --stop looping through a table after we found the skin 
            end 
        end 
        if ( result ) then -- If we got results 
            outputChatBox( tostring( skin ) .. " is a valid skin ID.", thePlayer, 0, 255, 0 ) -- It is valid, output it 
        else -- If we didn't get results 
            outputChatBox( specifiedSkin .. " is not a valid skin ID.", thePlayer, 0, 255, 0 ) -- No result, it is not valid 
        end 
    else -- If no skin specified 
        outputChatBox( "Please specify a skin ID to check!", thePlayer, 255, 0, 0 ) -- Tell it to the player 
    end 
end 
addCommandHandler("checkskin",isValidSkin) -- bind 'checkskin' command to 'isValidSkin' function 
  
function setDoingDriveby ( ) 
        -- we check if local player isn't currently doing a gang driveby 
        if not isPedDoingGangDriveby ( getLocalPlayer () ) then 
                -- if he got driveby mode off, turn it on 
                setPedWeaponSlot ( getLocalPlayer (), 4 ) 
                setPedDoingGangDriveby ( getLocalPlayer (), true ) 
        else 
                -- otherwise, turn it off 
                setPedWeaponSlot ( getLocalPlayer (), 0 ) 
                setPedDoingGangDriveby ( getLocalPlayer (), false ) 
        end 
end 
addCommandHandler ( "driveby", setDoingDriveby ) 

Link to comment

Надо ипользовать код не просто в любом месте, а либо в каком-то евенте, либо функции и чтобы игрок "player" был определен. Судя по всему проблема тут:

local myX, myY, myZ = getElementPosition( player ) 

Неверное значение "player"

Link to comment

Вот отделил скрипт респавна.

local hospitalSpawns = 
{ 
    { 2027.77, -1420.52, 15.99, }, 
    { 1180.85, -1325.57, 12.58, }, 
    { 1244.437, 331.2261, 18.5547, }, 
    { -2199.719, -2308.075, 29.6181, }, 
    { -2670.285, 616.4364, 13.4531, }, 
    { -316.3832, 1056.045, 18.7344, }, 
    { -1514.823, 2527.119, 54.7443, }, 
    { 1578.446, 1770.682, 9.8358, } 
} 
  
local myX, myY, myZ = getElementPosition( player ) 
local mySp, myDis   = 1, 99999 
  
for i, sp in ipairs( hospitalSpawns ) do 
    local dis = getDistanceBetweenPoints3D( sp[ 1 ], sp[ 2 ], sp[ 3 ], myX, myY, myZ ) 
    if dis < myDis then 
        myDis = dis 
        mySp  = i 
    end 
end 
  
function respawn(player, skin) 
     if not isElement(player) then return end 
     repeat until spawnPlayer ( player, hospitalSpawns[ mySp ][ 1 ], hospitalSpawns[ mySp ][ 2 ], hospitalSpawns[ mySp ][ 3 ], 90.0, skin, 0, 0 ) 
      fadeCamera(player, true) 
     setCameraTarget(player, player) 
     showChat(player, true) 
  end 
    
   addEventHandler("onPlayerWasted", root, 
        function() 
            resetMapInfo() 
            for i,player in ipairs( getElementModel(source) ) do 
                respawn(source) 
            end 
        end 
    ) 

[15:53:31] WARNING: [my]\altern8_play\altern8_play_respawn_s.lua:13: Bad argument @ 'getElementPosition'

[15:53:31] WARNING: [my]\altern8_play\altern8_play_respawn_s.lua:17: Bad argument @ 'getDistanceBetweenPoints3D'

[15:53:31] ERROR: [my]\altern8_play\altern8_play_respawn_s.lua:18: attempt to compare boolean with number

Наверняка чтото я опять накосячил. После смерти камера летит вверх смотря на игрока, а респавн не происходит

Link to comment

Так будет правильнее...

local uTimers = { } 
  
local hospitalSpawns = 
{ 
    { 2027.77, -1420.52, 15.99, }, 
    { 1180.85, -1325.57, 12.58, }, 
    { 1244.437, 331.2261, 18.5547, }, 
    { -2199.719, -2308.075, 29.6181, }, 
    { -2670.285, 616.4364, 13.4531, }, 
    { -316.3832, 1056.045, 18.7344, }, 
    { -1514.823, 2527.119, 54.7443, }, 
    { 1578.446, 1770.682, 9.8358, } 
} 
   
function respawn( player, skin ) 
    if not isElement( player ) then  
        return 
    end 
    local myX, myY, myZ = getElementPosition( player ) 
    local mySp, myDis   = 1, 99999 
    for i, sp in ipairs( hospitalSpawns ) do 
        local dis = getDistanceBetweenPoints3D( sp[ 1 ], sp[ 2 ], sp[ 3 ], myX, myY, myZ ) 
        if dis < myDis then 
            myDis = dis 
            mySp  = i 
        end 
    end 
    repeat until spawnPlayer ( player, hospitalSpawns[ mySp ][ 1 ], hospitalSpawns[ mySp ][ 2 ], hospitalSpawns[ mySp ][ 3 ], 90.0, skin, 0, 0 ) 
    fadeCamera( player, true ) 
    setCameraTarget( player, player ) 
    showChat( player, true )  
end 
  
addEventHandler( "onPlayerWasted", root,     
    function( )  
        uTimers[ source ] = setTimer( respawn,1000,1,source,getElementModel( source ) ) 
    end 
)    
  
addEventHandler( 'onPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)    
    
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        resetMapInfo( ) 
        for i,player in pairs( getElementsByType 'player' ) do 
            respawn( player ) 
        end 
    end 
) 

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