Jump to content

Guys please help with police cuffing the criminal


jingzhi

Recommended Posts

local teamLaw = { 
    ["Police"] = true, 
    ["Speed Enforcement"] = true 
    } 
  
function arrest(arrester,nightstick) 
    if arrester then     
        if getElementType(arrester) == "player" then     
            local Team = getPlayerTeam(arrester) 
            local TeamName = Team and getTeamName(Team) 
            if(teamLaw[TeamName]) then 
                if nightstick == 3 then 
                    outputChatBox("weapon value correct")         
                    if getPlayerWantedLevel(source) > 0 then           
                        setTimer(criminalarrested,100,0,arrester,source) 
                    end 
                end         
            end 
        end 
    end 
end 
            
addEventHandler("onPlayerDamage",getRootElement(),arrest) 
  
function criminalarrested(arrester,criminal) 
    local copx, copy, copz = getElementPosition (arrester) 
    local prisonerx, prisonery, prisonerz = getElementPosition (criminal) 
    local copangle = (360 - math.deg (math.atan2 ((copx - prisonerx) / (copy - prisonery)))) % 360 
    setElementRotation(criminal,_,_,copangle) 
    setCameraTarget(criminal, arrester) 
    local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) 
        if dist < 2 then 
        setControlState(criminal,"forwards", false) 
        setControlState(criminal,"sprint", false ) 
        else 
        setControlState(criminal,"forwards", true) 
        setControlState(criminal"sprint", true ) 
        end 
end 

Hey guys im trying to make a police arresting system that if cop hit with wanted people with nightstick the wanted should be cuffed and follow the police, but this doesn't work, in the debugscript it says " :46: bad argument #2 to atan2(number expected, got no value)"

Link to comment
in the debugscript it says " :46: bad argument #2 to atan2(number expected, got no value)
Too bad you didn't include that line, or edited the apparent error message, since it looks like it originates from line 28, not 46.

http://www.lua.org/manual/5.1/manual.ht ... math.atan2

math.atan2 has two arguments, not just one.

math.atan2 ((copx - prisonerx) / (copy - prisonery)) --extract of line 28 

I have deleted some part of the scripts before i post it here, i will try out your fix later, thank you :)

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