Jump to content

Vehicle Spawn


Recommended Posts

THE ONLY PROBLEM OF FRIENDS FROM OUR SERVICES:

Vehicles Upper Bottom Spawn Becoming VehicleSpawn.Lua I am delighted if my friends know how to help. 

 

hospitalPacks = {
{-2670.87890625,636.8984375,14.453125},
{-2637.0556640625,635.03125,14.453125},
{-1515.669921875,2519.166015625,56.0703125},
{-1513.888671875,2519.5908203125,56.064819335938},
{-1528.8955078125,2516.724609375,55.986171722412},
{2022.1650390625,-1402.6806640625,17.18045425415},
{2042.7001953125,-1409.4775390625,17.1640625},
{-316.5478515625,1051.6494140625,20.340259552002},
{-337.9541015625,1049.490234375,19.739168167114},
{-331.5849609375,1046.037109375,26.012474060059},
{-307.0419921875,1045.27734375,26.012474060059},
{1171.490234375,-1310.560546875,13.986573219299},
{1171.609375,-1306.556640625,13.996350288391},
{1158.5048828125,-1326.333984375,31.503561019897},
{1159.80078125,-1323.9013671875,31.498970031738},
{1238.7119140625,328.2431640625,19.7555103302},
{1229.365234375,311.1435546875,24.7578125},
{-2204.07421875,-2309.58203125,31.375},
{1615.939453125,1818.0537109375,10.8203125},
{1601.9443359375,1816.736328125,10.8203125},
{1590.0166015625,1792.0234375,30.46875},
{1607.3232421875,1776.7412109375,37.3125},
{2107.7626953125,926.16015625,10.8203125},
{2116.12890625,925.7705078125,10.9609375},
{2122.1865234375,925.3193359375,10.8203125},
{3627.2453613281,1611.8269042969,13.31093788147},
{3631.6494140625,1612.3323974609,13.31093788147},
{3574.3569335938,1608.8055419922,13.31093788147},
{3577.861328125,1608.6048583984,13.31093788147},
{3611.8522949219,1620.6276855469,30.969223022461},
{3613.5842285156,1612.4018554688,30.948547363281},
}

patrolPoints = {
{2520.7131347656,-2105.6320800781,13.546875},
{-1603.2197265625,-2712.736328125,48.9453125},
{2465.748046875,-2215.55859375,13.546875},
{2473.439453125,-2215.56640625,13.546875},
{2480.0732421875,-2216.140625,13.546875},
{2487.24609375,-2215.5966796875,13.546875},
{2494.1005859375,-2215.5859375,13.546875},
{-1686.6728515625,408.9970703125,7.3984375},
{-1682.34375,412.9384765625,7.3984375},
{-1680.0263671875,402.3642578125,7.3984375},
{-1675.84375,406.4677734375,7.3984375},
{-1670.5615234375,411.8359375,7.3984375},
{-1666.2392578125,416.2509765625,7.3984375},
{-1672.7939453125,422.81640625,7.3984375},
{-1677.20703125,418.46484375,7.3984375},
{-2410.7021484375,969.9091796875,45.4609375},
{-2410.744140625,975.220703125,45.4609375},
{-2410.837890625,980.5302734375,45.4609375},
{-1329.3046875,2668.5126953125,50.46875},
{-1328.7314453125,2673.90625,50.0625},
{-1327.0185546875,2679.3876953125,50.46875},
{-1327.3798828125,2684.62890625,50.0625},
{1940.7099609375,-1778.5244140625,13.390598297119},
{1940.6552734375,-1774.908203125,13.390598297119},
{1940.630859375,-1771.728515625,13.390598297119},
{1940.7080078125,-1767.3837890625,13.390598297119},
{-1477.921875,1868.138671875,32.639846801758},
{-1466.1552734375,1869.0048828125,32.6328125},
{-1464.5224609375,1861.3828125,32.639846801758},
{-1477.4599609375,1860.5205078125,32.6328125},
{-735.9208984375,2744.0087890625,47.2265625},
{-739.0439453125,2744.2421875,47.165451049805},
{377.6953125,2601.1083984375,16.484375},
{624.5263671875,1676.25390625,6.9921875},
{620.2958984375,1681.2431640625,6.9921875},
{616.248046875,1686.4169921875,7.1875},
{612.783203125,1691.1650390625,7.1875},
{609.2060546875,1696.201171875,7.1875},
{605.8505859375,1700.978515625,7.1875},
{602.27734375,1706.3603515625,7.1875},
{2141.037109375,2742.734375,10.960174560547},
{2142.3115234375,2752.6982421875,10.96019744873},
{2147.9521484375,2752.3203125,10.8203125},
{2152.60546875,2751.953125,10.8203125},
{2152.984375,2743.85546875,10.8203125},
{2147.75,2743.7392578125,10.8203125},
{-97.6298828125,-1175.0283203125,2.4990689754486},
{-90.74609375,-1177.853515625,2.2021217346191},
{-84.75390625,-1163.853515625,2.3359375},
{-91.5771484375,-1160.5732421875,2.4453125},
{-1606.525390625,-2717.2138671875,48.9453125},
{-1609.7109375,-2721.544921875,48.9453125},
{-1599.83203125,-2708.302734375,48.9453125},
{-2246.314453125,-2558.8212890625,32.0703125},
{-2241.3125,-2561.3662109375,32.0703125},
{-1132.2880859375,-135.0986328125,14.14396572113},
{-1153.529296875,-156.373046875,14.1484375},
{-1142.826171875,-145.67578125,14.14396572113},
{655.611328125,-557.9912109375,16.501491546631},
{655.6572265625,-572.1728515625,16.501491546631},
{1601.791015625,2203.90625,11.060997009277},
{1596.806640625,2203.4345703125,10.8203125},
{1590.197265625,2203.4853515625,10.8203125},
{1589.4775390625,2195.43359375,10.8203125},
{1596.125,2194.294921875,10.8203125},
{1601.6591796875,2194.3369140625,10.8203125},
{2206.8466796875,2470.47265625,10.8203125},
{2206.94140625,2474.75,10.8203125},
{2206.9267578125,2478.86328125,10.8203125},
{2198.06640625,2480.6953125,10.8203125},
{2197.541015625,2475.791015625,10.995170593262},
{2197.609375,2471.9169921875,10.995170593262},
{2120.8251953125,915.4833984375,10.8203125},
{2115.1181640625,915.44140625,10.8203125},
{2109.076171875,915.4228515625,10.8203125},
{2109.22265625,924.8779296875,10.9609375},
{2114.9404296875,924.8857421875,10.9609375},
{2119.5126953125,925.2861328125,10.9609375},
{2645.7197265625,1112.7802734375,10.8203125},
{2639.984375,1112.56640625,10.8203125},
{2634.828125,1112.3466796875,10.9609375},
{2634.1826171875,1101.9482421875,10.8203125},
{2636.7509765625,1101.6748046875,10.8203125},
{2643.5126953125,1101.81640625,10.8203125},
{2209.576171875,2469.8251953125,10.8203125},
{2208.8310546875,2475.09375,10.8203125},
{1005.078125,-901.7490234375,42.216625213623},
{993.025390625,-902.474609375,42.222496032715},
{5008.126953125,1560.744140625,13.10000038147},
{5008.1279296875,1555.7972412109,13.10000038147},
{5008.1284179688,1550.7982177734,13.10000038147},
{4998.8671875,1550.8525390625,13.246732711792},
{4998.8681640625,1555.8785400391,13.246732711792},
{4998.8671875,1560.8095703125,13.246732711792},
{4966.916015625,1542.7683105469,13.10000038147},
{4961.7739257813,1542.7672119141,13.10000038147},
{5071.2485351563,2247.4665527344,13.10000038147},
{5064.0234375,2247.4665527344,13.10000038147},
{5120.9130859375,2402.0034179688,13.31875038147},
{5122.4453125,2407.8967285156,13.30312538147},
}

lootItems = {
["hospital"] = {
{"medkit",2891,0.7,0},
{"heatpack",1576,1,0},
{"bint",1578,0.5,0},
{"morphine",1579,1,0},
{"blood_bag",1580,1,0},
{"painkiller",1580,1,0},
-- {"antia",1580,1,0},
-- {"antib",1580,1,0},
{"antic",1580,1,0},
},
}

function updateHospitals ()
    for i,box in pairs(hospitalCol) do
        for _,items in ipairs(lootItems["hospital"]) do
            setElementData(hospitalCol,items[1],math.random(1,5))
        end
    end
    setTimer(updateHospitals,3600000,1)
end

hospitalCol = {}
function createHospitalPacks()
    number1 = 0
    for i,box in ipairs(hospitalPacks) do
        number1 = number1+1
        local x,y,z = box[1],box[2],box[3]
        object = createObject(1558,x,y,z,nil,nil,nil)
        hospitalCol = createColSphere(x,y,z,2)
        setElementData(hospitalCol,"parent",object)
        setElementData(hospitalCol,"hospitalbox",true)
        setElementData(hospitalCol,"MAX_Slots",100)
        for _,items in ipairs(lootItems["hospital"]) do
            local randomNumber = math.random(1,10)
            if randomNumber >= 2 then
                setElementData(hospitalCol,items[1],math.random(1,5))
            end
        end    
    end
    setTimer(updateHospitals,3600000,1)
end
createHospitalPacks()

for i,patrol in ipairs(patrolPoints) do
    local x,y,z = patrol[1],patrol[2],patrol[3]
    patrolCol = createColSphere(x,y,z,3)
    setElementData(patrolCol,"patrolstation",true)
end

function notifyAboutExplosion2()
    -- vx,vy,vz = getElementPosition(source)
    for i,player in pairs(getVehicleOccupants(source)) do
        -- px,py,pz = getElementPosition(player)
        -- local pdistance = getDistanceBetweenPoints3D ( vx,vy,vz,px,py,pz )
        -- if pdistance < 4 then
        if not getElementData(player,"dontBlow") then
            triggerEvent("kilLDayZPlayer",player)
        end
    end
end
addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion2)

function exitVehicle(thePlayer)
    if getElementData(source,"derby") then return end
    speedx, speedy, speedz = getElementVelocity(source)
    if getElementHealth(source) <= 300 and (math.sqrt(speedx^2 + speedy^2 + speedz^2))*180 > 50 then
        setElementData(thePlayer,"dontBlow",true)
        setTimer(setElementData,4000,1,thePlayer,"dontBlow",false)
    end
end
addEventHandler ( "onVehicleStartExit", getRootElement(), exitVehicle)

function onPlayerEnterDayzVehicle(veh,seat)
    triggerEvent("onPlayerDropDead",source,source,getElementData(source,"deadBody"))
    col = getElementData(veh,"parent")
    local needengine = (getElementData(col,"maxEngine_inVehicle") or 1)
    local needtires = (getElementData(col,"maxTire_inVehicle") or 4)
    local needparts = (getElementData(col,"maxParts_inVehicle") or 1)
    if not isElement(col) then
        col = createColSphere(0,0,0,2.5)
        attachElements ( col, veh, 0, 0, 0 )
        setElementData(col,"parent",veh)
        setElementData(veh,"parent",col)
        setElementData(col,"vehicle",true)
        setElementData(col,"colSize",2.5)
        setElementData(col,"MAX_Slots",50)
        setElementData(col,"maxTire_inVehicle",4)
        setElementData(col,"maxEngine_inVehicle",1)
        setElementData(col,"maxParts_inVehicle",1)
        setElementData(col,"Tire_inVehicle",4)
        setElementData(col,"Engine_inVehicle",1)
        setElementData(col,"Parts_inVehicle",1)
        setElementData(col,"spawn_x",0)
        setElementData(col,"spawn_y",0)
        setElementData(col,"spawn_z",10)
        setElementData(col,"defuel",0.2)
        setElementData(col,"maxfuel",60)
        setElementData(col,"fuel",54)
        setElementData(col,"tableSpawn","Civil_spawns")
        setElementData(col,"tableID","Civil_car")
    end
    col = getElementData(veh,"parent")
    if getVehicleType(veh) == "BMX" then
        setElementData(col,"maxTire_inVehicle",0)
        setElementData(col,"maxEngine_inVehicle",0)
        setElementData(col,"maxParts_inVehicle",0)
        setElementData(col,"Tire_inVehicle",0)
        setElementData(col,"Engine_inVehicle",0)
        setElementData(col,"Parts_inVehicle",0)
        setVehicleEngineState ( veh, true )
    end
    if (getElementData(col,"Tire_inVehicle") < needtires or getElementData(col,"Engine_inVehicle") < needengine or getElementData(col,"Parts_inVehicle") < needparts or getElementData(col,"fuel") <= 0) and getVehicleType(veh) ~= "BMX" then
        setVehicleEngineState ( veh, false )
    else
        if seat == 0 then
            setVehicleEngineState ( veh, true )
            -- bindKey(source,"k","down",setEngineStateByPlayer)
        end
    end
    if seat == 0 and not getElementData(veh,"repairer") then
        setElementFrozen(veh, false)
    end
    if not getElementData(source, "inBase") and not getElementData(veh,"event") then
        setVehicleDamageProof( veh, false )
    end
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onPlayerEnterDayzVehicle )

function onPlayerExitDayzVehicle(veh,seat)
    if getElementData(source, "inBase") and seat == 0 then
        rx,ry,rz = getElementRotation(veh)
        setElementRotation(veh,0,0,rz)
        setElementFrozen ( veh, true )
        setVehicleDamageProof( veh, true )
    elseif not getElementData(source, "inBase") and not getElementData(veh,"event") then
        setVehicleDamageProof( veh, false )
    end
    if seat == 0 then
        setVehicleEngineState ( veh, false )
        -- unbindKey(source,"k","down",setEngineStateByPlayer)
    end
    weapSlot = getPedWeaponSlot(source)
    if getElementData(source,"currentweapon_1") and getElementData(source,"currentweapon_1") ~= 0 and (weapSlot == 5 or weapSlot == 6 or weapSlot == 3 ) then
        triggerEvent("onPlayerRearmWeapon",source,getElementData(source,"currentweapon_1"),true,false,false)
    elseif getElementData(source,"currentweapon_2") and getElementData(source,"currentweapon_2") ~= 0 and (weapSlot == 2 or weapSlot == 4 or weapSlot == 8 ) then
        triggerEvent("onPlayerRearmWeapon",source,getElementData(source,"currentweapon_2"),false,true,false)
    elseif getElementData(source,"currentweapon_3") and getElementData(source,"currentweapon_3") ~= 0 then
        triggerEvent("onPlayerRearmWeapon",source,getElementData(source,"currentweapon_3"),false,false,true)
    end
    setElementData(source,"dontKill",false)
end
addEventHandler ( "onPlayerVehicleExit", getRootElement(), onPlayerExitDayzVehicle )

function setVehiclesFuelPerMinute ()
    for i,veh in ipairs(getElementsByType("vehicle")) do
        if getVehicleEngineState(veh) == true then
            if getVehicleOccupant(veh) then
                local col = getElementData(veh,"parent")
                if getElementData(col,"fuel") > 0 then
                    setElementData(col,"fuel",getElementData(col,"fuel")-getElementData(col,"defuel"))
                else
                    if getVehicleType(veh) ~= "BMX" then
                        setVehicleEngineState ( veh, false )
                    else
                        setVehicleDamageProof(veh, true )
                    end
                end
            else
                setVehicleEngineState ( veh, false )
            end
        end
    end
end
setTimer(setVehiclesFuelPerMinute,15000,0)

repairTimer = {}
function repairVehicle (veh)
    local health = math.floor(100-getElementHealth(veh)/10)
    if health == 0 then
        health = 1
    end
    setPedAnimation(source,false)
    repairTimer[veh] = setTimer(fixVehicleDayZ,1100,health,veh,source)
    setElementFrozen (veh,true)
    setVehicleDamageProof(veh,true)
    setElementData(veh,"repairer",source)
    setElementData(source,"repairingvehicle",veh)
    setElementData(source,"repairinghp",health)
    setPedAnimation (source,"SCRATCHING","sclng_r",-1,true,false,false,true)
    setElementData(source,"isAniming",true)
    triggerClientEvent (source, "displayClientInfo", source,"Vehicle","Tamir etmeye başladım "..getVehicleName(veh),22,255,0)
    bindKey(source, "w", "down", playerPressedKey)
    bindKey(source, "a", "down", playerPressedKey)
    bindKey(source, "s", "down", playerPressedKey)
    bindKey(source, "d", "down", playerPressedKey)
end
addEvent("repairVehicle",true)
addEventHandler("repairVehicle",getRootElement(),repairVehicle)

function fixVehicleDayZ(veh,player)
    repairHp = getElementData(player,"repairinghp")
    setElementHealth(veh,1000-repairHp*10)
    setElementData(player,"repairinghp",repairHp - 1)
    if getElementData(player,"repairinghp") == 0 then
        setElementHealth(veh,1000)
        fixVehicle (veh)
        killTimer(repairTimer[veh])
        repairTimer[veh] = false
        setPedAnimation(player,false)
        setElementData(player,"isAniming",false)
        setElementFrozen (veh,false)
        setVehicleDamageProof(veh,false)
        setElementData(veh,"repairer",false)
        setElementData(player,"repairingvehicle",false)
        triggerClientEvent (player, "displayClientInfo", player,"Vehicle","Вы закончили чинить "..getVehicleName(veh),22,255,0)
        unbindKey(player, "w", "down", playerPressedKey)
        unbindKey(player, "a", "down", playerPressedKey)
        unbindKey(player, "s", "down", playerPressedKey)
        unbindKey(player, "d", "down", playerPressedKey)
    end
end

function stopFixxingWhileMoving(presser)
    local veh = getElementData(presser,"repairingvehicle")
    if isElement(veh) then
        setPedAnimation(presser)
        setElementData(presser,"isAniming",false)
        setElementFrozen (veh,false)
        setVehicleDamageProof(veh,false)
        setElementData(veh,"repairer",false)
        setElementData(presser,"repairinghp",0)
        setElementData(presser,"repairingvehicle",false)
        triggerClientEvent (presser, "displayClientInfo", presser,"Vehicle","Вы остановили починку "..getVehicleName(veh),255,22,0)
        killTimer(repairTimer[veh])
        repairTimer[veh] = false
        unbindKey(presser, "w", "down", playerPressedKey)
        unbindKey(presser, "a", "down", playerPressedKey)
        unbindKey(presser, "s", "down", playerPressedKey)
        unbindKey(presser, "d", "down", playerPressedKey)
    end
end
addEvent("onClientMovesWhileAnimation",true)
addEventHandler("onClientMovesWhileAnimation",getRootElement(),stopFixxingWhileMoving)

function debugFixxing()
    local veh = getElementData(source,"repairingvehicle")
    if isElement(veh) then
        killTimer(repairTimer[veh])
        repairTimer[veh] = false
        setElementFrozen (veh,false)
        setElementData(veh,"repairer",false)
        setVehicleDamageProof(veh,false)
        setTimer(setVehicleDamageProof,1100,2,veh,false)
    end
end
addEventHandler("onPlayerQuit",getRootElement(),debugFixxing)


function playerPressedKey(presser) 
    stopFixxingWhileMoving(presser) 
end
addEvent("onStopRepair",true)
addEventHandler("onStopRepair",getRootElement(),playerPressedKey)

function setEngineStateByPlayer (playersource)
    local veh = getPedOccupiedVehicle (playersource)
    if isElement(veh) then
        local col = getElementData(veh,"parent")
        if getVehicleType(veh) ~= "BMX" and getElementData(col,"fuel") > 0 then
            setVehicleEngineState (veh, not getVehicleEngineState(veh))
            if getVehicleEngineState(veh) == true then
                triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Motor вкл!",22,255,0)
            else
                triggerClientEvent (playersource, "displayClientInfo", playersource,"Vehicle","Motor выкл!",255,22,0)
            end
        end
    end
end

Link to comment
  • 2 weeks later...

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