Jump to content

1 error


Recommended Posts

Im have this script, and it have one error:

When player is killed, by car he is not respawn.

Im use DayZ gamemod.

Im try change:

addEventHandler("onClientPlayerSpawn", root, 

to

addEventHandler("spawnDayZPlayer", root, 

but this not, work.

local bodyparts = {2908, 2907, 2906, 2906, 2905, 2905} -- head, torso, hand x2, leg x2 
  
function onDamage(attacker) 
    if attacker and getElementType(attacker) == "vehicle" and getElementModel(attacker) == 532 and getElementAlpha(source) == 255 then 
        massacrePed(attacker, source) 
    end 
end 
addEventHandler("onClientPedDamage", root, onDamage) 
addEventHandler("onClientPlayerDamage", root, onDamage) 
  
addEventHandler("onClientPlayerSpawn", root, 
    function() 
        setElementAlpha(source, 255) 
        if source == localPlayer then setCameraTarget(source) end 
    end 
) 
  
function massacrePed(harvester, ped) 
    if harvester and getElementType(harvester) == "vehicle" and getElementModel(harvester) == 532 then 
        local vx, vy, _ = getElementVelocity(harvester) 
        outputChatBox("Velocity: " .. vx .. ", " .. vy) 
        if math.abs(vx) < 0.1 and math.abs(vy) < 0.1 then return end 
  
        -- checking if ped is attacked by front of combine harvester 
        local x, y, z = getElementPosition(ped) 
        local x2, y2, _ = getRotatedPosition(harvester, 0, 5.5, 0) -- also know as misc_b component 
        if getDistanceBetweenPoints2D(x, y, x2, y2) > 3.5 then return end 
        if ped == localPlayer then setCameraTarget(harvester) end 
        setElementAlpha(ped, 0) 
        setTimer(setElementHealth, 2000, 1, ped, 0) 
        fxAddBlood(x, y, z, 0, 0, 0, 5, 1) 
  
        local bodies = {} 
        for i, obj in pairs(bodyparts) do 
            setTimer( 
                function() 
                    local x, y, z = getVehicleComponentPosition(harvester, "misc_c") 
                    x, y, z = getRotatedPosition(harvester, x, y, z) 
                    local _, _, rz = getVehicleComponentRotation(harvester, "misc_c") 
                    local _, _, rz2 = getElementRotation(harvester) 
                    rz = rz - rz2 - 180 
                    x, y = getPointFromDistanceRotation(x, y, 3.4, rz) 
  
                    local o = createObject(obj, x, y, z) 
                    setElementRotation(o, math.random(1, 140), math.random(1, 140), math.random(1, 140)) 
                    table.insert(bodies, o) 
                    if i > 1 then 
                        setElementCollidableWith(o, bodies[i-1], false) 
                        setElementCollidableWith(bodies[i-1], o, false) 
                    end 
                    setTimer(setElementVelocity, 50, 1, o, -vx, -vy, math.random(0.01, 0.1)) 
                end, 50*i, 1) 
        end 
        local x, y, z = getRotatedPosition(harvester, -1.3, -3, 1.2) 
        fxAddBlood(x, y, z, 0, 0, 0, 5, 1) 
        playSFX("script", 152, 2, false) -- 'blood' sound 
        --playSFX3D("pain_a", 1, math.random(88, 130), x, y, z, false) -- woman scream 
        --playSFX3D("pain_a", 2, math.random(89, 100), x, y, z, false) -- man scream 
         
        setTimer( 
            function() 
                for i, obj in pairs(bodies) do destroyElement(obj) end 
            end, 10000, 1) 
    end 
end 
  
function getRotatedPosition(element, distX, distY, distZ) 
    if not element or not isElement(element) then return end 
    local matrix = getElementMatrix(element) 
    if not matrix then return end 
    local offX = distX * matrix[1][1] + distY * matrix[2][1] + distZ * matrix[3][1] + 1 * matrix[4][1] 
    local offY = distX * matrix[1][2] + distY * matrix[2][2] + distZ * matrix[3][2] + 1 * matrix[4][2] 
    local offZ = distX * matrix[1][3] + distY * matrix[2][3] + distZ * matrix[3][3] + 1 * matrix[4][3] 
    return offX, offY, offZ 
end 
  
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 
  
-- rotating misc_c 
addEventHandler("onClientPlayerVehicleEnter", root, 
    function(veh) 
        if source == localPlayer and getElementModel(veh) == 532 then 
            addEventHandler("onClientRender", root, updateMiscc) 
        end 
    end 
) 
  
addEventHandler("onClientVehicleStartExit", root, 
    function(player) 
        if player == localPlayer and getElementModel(source) == 532 then 
            removeEventHandler("onClientRender", root, updateMiscc) 
        end 
    end 
) 
  
function updateMiscc() 
    if isCursorShowing() or isConsoleActive() or isChatBoxInputActive() then return end 
    if getKeyState("num_2") then 
        local veh = getPedOccupiedVehicle(localPlayer) 
        local rx, ry, rz = getVehicleComponentRotation(veh, "misc_c") 
        if rz + 0.5 < 90 then 
            setVehicleComponentRotation(veh, "misc_c", rx, ry, rz+0.2) 
        end 
        playSFX("genrl", 131, 27, false) 
    end 
    if getKeyState("num_8") then 
        local veh = getPedOccupiedVehicle(localPlayer) 
        local rx, ry, rz = getVehicleComponentRotation(veh, "misc_c") 
        if rz - 0.5 > 0 then 
            setVehicleComponentRotation(veh, "misc_c", rx, ry, rz-0.2) 
        end 
        playSFX("genrl", 131, 27, false) 
    end 
end 
  
-- DEBUG 
--[[local validskins = getValidPedModels() 
for i=1, 30 do 
    local x, y = getPointFromDistanceRotation(50, 0, 30, 360 * (i/30)) 
    createPed(validskins[math.random(1, #validskins)], x, y, 4) 
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...