Jump to content

WARNING: headshot\headshot_s.lua:2: Bad argument @ 'getElementType' [Expected element at argument 1, got nil]


Recommended Posts

function MakePlayerHeadshot( attacker, weapon, bodypart, loss )
    if getElementType ( attacker ) == "ped" then
        if bodypart == 9 then
            triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss )
            setPedHeadless ( source, true )
            killPed( source, attacker, weapon, bodypart )
            setTimer( BackUp, 900, 1, source )
        end
    end
end

function MakeHeadshot( source, attacker, weapon, loss )
    triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss )
    killPed( source, attacker, weapon, 9 )
    setPedHeadless ( source, true )
    setTimer( BackUp, 900, 1, source )
end

function BackUp( source )    
    if getElementType ( source ) == "player" then
        setPedHeadless ( source, false )
    end
end

function outputHeadshotIcon (killer, weapon, bodypart)
    if bodypart == 9 then
        cancelEvent()
        exports.killmessages:outputMessage (
        {getPlayerName(killer),{"padding",width=3},{"icon",id=weapon},{"padding",width=3},{"icon",id=256},{"padding",width=3},{"color",r=r1,g=g1,b=b1},getPlayerName(source) }, getRootElement(),r2,g2,b2)                 
    end
end
addEvent ( "onServerHeadshot", true )
addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot )
addEventHandler( "onPlayerKillMessage", getRootElement(), outputHeadshotIcon )
addEventHandler( "onServerHeadshot", getRootElement(), MakeHeadshot )

 

Edited by CodyJ(L)
Added proper format (Hurts my eyes)
Link to comment
  • Moderators

Try checking the attacker parameter first:

function MakePlayerHeadshot( attacker, weapon, bodypart, loss )
    if attacker and getElementType ( attacker ) == "ped" then
        if bodypart == 9 then
            triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss )
            setPedHeadless ( source, true )
            killPed( source, attacker, weapon, bodypart )
            setTimer( BackUp, 900, 1, source )
        end
    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...