Jump to content

Arrest script


Gtagasje

Recommended Posts

Hi,

My friend have a made a arrest script, but it shows the following error: ERROR:line 20: Bad argument @ 'addEventHandler' [ Expected element at argument 2, got nill ].

And this is the script:

  
function arrest(hitElement, weapon) 
  
    local weap = getWeaponNameFromID(3) 
    local playerTeam = getPlayerTeam(source) 
        if ( playerTeam == "Police" )       then 
            if ( getPlayerWantedLevel(hitElement) == "1" ) or ( getPlayerWantedLevel(hitElement) == "2" ) or ( getPlayerWantedLevel(hitElement) == "3" ) or ( getPlayerWantedLevel(hitElement) == "5" ) or ( getPlayerWantedLevel(hitElement) == "6" )      then  
                if ( weap )     then 
                    local arrestMarker = createMarker(1542.39966, -1675.01782, 13.55443, "cylinder", 2.5, 255, 255, 0, source) 
                    toggleAllControls( hitElement, false ) 
                    ax, ay, az = getElementPosition ( hitElement ) 
                    cx, cy, cz = getElementPosition ( source ) 
                    d = getDistanceBetweenPoints3D(ax, ay, az, cx, cy, cz) 
                        if ( d > 10 )   then 
                            setElementPosition( hitElement, cx-5, cy, cz ) 
                        end 
                end 
            end 
        end 
end 
addEventHandler( "onMarkerHit", arrestMarker, mhit ) 
addEventHandler( "onPlayerDamage", root, arrest) 
  
function mhit(hitElement) 
  
    if ( getPlayerTeam(source) ~= "Police" ) then  
     
     
        if ( getPlayerWantedLevel(hitElement) == "1" ) or ( getPlayerWantedLevel(hitElement) == "2" ) or ( getPlayerWantedLevel(hitElement) == "3" ) or ( getPlayerWantedLevel(hitElement) == "5" ) or ( getPlayerWantedLevel(hitElement) == "6" )      then  
             
            setElementInterior(hitElement, 6) 
            setElementPosition(hitElement, 264.74969, 77.49036, 1001.03906) 
             
        else 
             
             
        end 
    end 
end 
  

we already have a wanted script on command.

Link to comment

It clearly says that value of second argument of addEventHandler is nil, what means that arrestMarker doesn't exist. That's because you try to attach the handler to the element before that element is created. So move that line below the line which creates arrestMarker element.

Link to comment
  
  
function arrest(attacker, weapon) 
 if attacker then 
    local weap = getWeaponNameFromID(3) 
    local playerTeam = getPlayerTeam(attacker) 
     
     if ( getPlayerTeam(attacker)== getTeamFromName("Police") ) then 
      
            if ( getPlayerWantedLevel(source) == "1" ) or ( getPlayerWantedLevel(source) == "2" ) or ( getPlayerWantedLevel(source) == "3" ) or ( getPlayerWantedLevel(source) == "5" ) or ( getPlayerWantedLevel(source) == "6" )      then 
                if ( weapon )  then 
                    if ( weapon == weap )  then 
                    local arrestMarker = createMarker(1542.39966, -1675.01782, 13.55443, "cylinder", 2.5, 255, 255, 0, source) 
                    toggleAllControls( source, false ) 
                    ax, ay, az = getElementPosition ( attacker) 
                    cx, cy, cz = getElementPosition ( source ) 
                    d = getDistanceBetweenPoints3D(ax, ay, az, cx, cy, cz) 
                        if ( d > 10 )   then 
                            setElementPosition( source, cx-5, cy, cz ) 
                        end 
                    end 
                end 
            end 
     end 
end 
end 
addEventHandler( "onPlayerDamage", root, arrest) 
  
function mhit(hitElement) 
  
  
    
    
        if ( getPlayerWantedLevel(hitElement) == "1" ) or ( getPlayerWantedLevel(hitElement) == "2" ) or ( getPlayerWantedLevel(hitElement) == "3" ) or ( getPlayerWantedLevel(hitElement) == "5" ) or ( getPlayerWantedLevel(hitElement) == "6" )      then 
            
            setElementInterior(hitElement, 6) 
            setElementPosition(hitElement, 264.74969, 77.49036, 1001.03906) 
            
        else 
            
            
        end 
end 
 addEventHandler( "onMarkerHit", arrestMarker, mhit ) 
  

Try This

Link to comment

1. getPlayerWantedLevel() returns integer. and you're trying to compare it with string.

2. == 1 or == 2 or == 3 or ... really? what about > 0?

3. addEventHandler must be called when both marker AND handler function exist

function arrest(hitElement, weapon) 
    local weap = getWeaponNameFromID(3) 
    local playerTeam = getPlayerTeam(source) 
    if ( playerTeam == "Police" ) then 
        if ( getPlayerWantedLevel(hitElement) > 0 ) then  
            if ( weap ) then 
                arrestMarker = createMarker(1542.39966, -1675.01782, 13.55443, "cylinder", 2.5, 255, 255, 0, source) 
                addEventHandler( "onMarkerHit", arrestMarker, mhit) 
                toggleAllControls( hitElement, false ) 
                local ax, ay, az = getElementPosition ( hitElement ) 
                local cx, cy, cz = getElementPosition ( source ) 
                local d = getDistanceBetweenPoints3D(ax, ay, az, cx, cy, cz) 
                if ( d > 10 ) then 
                    setElementPosition( hitElement, cx-5, cy, cz ) 
                end 
            end 
        end 
    end 
end 
addEventHandler( "onPlayerDamage", root, arrest) 
  
function mhit(hitElement) 
    if ( getPlayerTeam(source) ~= "Police" ) then 
        if ( getPlayerWantedLevel(hitElement) > 0 ) then 
            setElementInterior(hitElement, 6) 
            setElementPosition(hitElement, 264.74969, 77.49036, 1001.03906) 
        end 
    end 
end 

Link to comment

Try this.

function arrest(attacker, weapon, bodypart, loss) 
    local playerTeam = getPlayerTeam(source) 
    if (playerTeam == "Police") then 
        if (getPlayerWantedLevel(source) > 0) then 
            if (weapon == 3) then 
                local ax, ay, az = getElementPosition(attacker) 
                local cx, cy, cz = getElementPosition(source) 
                local d = getDistanceBetweenPoints3D(ax, ay, az, cx, cy, cz) 
                arrestMarker = createMarker(1542.39966, -1675.01782, 13.55443, "cylinder", 2.5, 255, 255, 0, source) 
                toggleAllControls(source, false) 
                addEventHandler("onMarkerHit", arrestMarker, mhit) 
  
                if (d > 10) then 
                    setElementPosition(attacker, cx - 5, cy, cz) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onPlayerDamage", root, arrest) 
  
function mhit(hitElement, matchingDimension) 
    if getElementType(hitElement) == "player" then 
        local playerTeam = getPlayerTeam(hitElement) 
        if (playerTeam == "Police") then 
            if (getPlayerWantedLevel(hitElement) > 0) then 
                setElementInterior(hitElement, 6) 
                setElementPosition(hitElement, 264.74969, 77.49036, 1001.03906) 
            end 
        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...