Jump to content

[Help] Nightstick Police Job


3B00DG4MER

Recommended Posts

I can barely understand what you mean, could you clarify what you mean a bit more?

Normal Script

if the player is in a Police Team when attack someone have 1 star or Above,the Attacked player will teleport to somewhere

(I have the jail map,Just give me the script i'll edit)

Link to comment
  
addEventHandler("onPlayerDamage",root,function(attacker,weapon) 
    if getTeamName(getPlayerTeam(attacker)) == "Police" and weapon == 3 and getPlayerWantedLevel(source)>=1 then 
        -- your stuff here 
    end 
end) 
  

Can you do it if the Police Attacked Him 3 Times Like GTA-AR server Or CIT or SAUR

Link to comment
(I have the jail map,Just give me the script i'll edit)

Sorry, we can't give you a ready-made script as you'll just copy & paste, therefore you'll learn nothing, we're here to help you out fixing or setting up the desired code, i'll just give you the functions and events you need:

Functions:

getPlayerWantedLevel 
setElementPosition 
getPlayerTeam 

Event(s):

onPlayerDamage

Link to comment
  
local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore 
  
local timer = false 
addEventHandler("onPlayerDamage",root,function(attacker,weapon) 
    if getTeamName(getPlayerTeam(attacker)) == "Police" and weapon == 3 and getPlayerWantedLevel(source)>=1 then 
        if timer then 
            resetTimer(timer) 
        end 
        setElementData(source,"times_attacked",getElementData(source,"times_attacked") and ,getElementData(source,"times_attacked")+1 or 1) 
        if not timer then 
            timer = setTimer(function() 
                if getElementData(source,"times_attacked") then 
                    removeElementData(source,"times_attacked") 
                end 
            end,cooldown*1000,1) 
        end 
        if getElementData(source,"times_attacked")>=3 then 
            if getElementData(source,"times_attacked") then 
                removeElementData(source,"times_attacked") 
            end 
            if timer then 
                killTimer(timer) 
                timer = false 
            end 
            -- your stuff here 
        end 
    end 
end) 
  

Edited by Guest
Link to comment
  
local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore 
  
local timer 
addEventHandler("onPlayerDamage",root,function(attacker,weapon) 
    if timer then 
        resetTimer(timer) 
    end 
    setElementData(source,"times_attacked",getElementData(source,"times_attacked") and ,getElementData(source,"times_attacked")+1 or 1) 
    timer = setTimer(function() 
        if getElementData(source,"times_attacked") then 
            removeElementData(source,"times_attacked") 
        end 
    end,cooldown*1000,1) 
    if getTeamName(getPlayerTeam(attacker)) == "Police" and weapon == 3 and getPlayerWantedLevel(source)>=1 and getElementData(source,"times_attacked")>=3 then 
        if getElementData(source,"times_attacked") then 
            removeElementData(source,"times_attacked") 
        end 
        if timer then 
            killTimer(timer) 
        end 
        -- your stuff here 
    end 
end) 
  

Thanks man

Link to comment
There were some bugs in the code. Copy it again, I updated it.

You do a bug when Update, i have fixed it

local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore 
  
local timer = false 
addEventHandler("onPlayerDamage",root,function(attacker,weapon) 
    if getTeamName(getPlayerTeam(attacker)) == "Police" and weapon == 3 and getPlayerWantedLevel(source)>=1 then 
        if timer then 
            resetTimer(timer) 
        end 
        setElementData(source,"times_attacked",getElementData(source,"times_attacked") and getElementData(source,"times_attacked")+1 or 1) 
        if not timer then 
            timer = setTimer( 
            function() 
                if getElementData(source,"times_attacked") then 
                    removeElementData(source,"times_attacked") 
                end 
            end,cooldown*1000,1) 
        end 
        if getElementData(source,"times_attacked")>=3 then 
            if getElementData(source,"times_attacked") then 
                removeElementData(source,"times_attacked") 
            end 
            if timer then 
                killTimer(timer) 
                timer = false 
            end 
            -- your stuff here 
            end 
            end 
          end) 

Link to comment
  
local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore 
  
local timer = false 
addEventHandler("onPlayerDamage",root,function(attacker,weapon) 
    if getTeamName(getPlayerTeam(attacker)) == "Police" and weapon == 3 and getPlayerWantedLevel(source)>=1 then 
        if timer then 
            resetTimer(timer) 
        end 
        setElementData(source,"times_attacked",getElementData(source,"times_attacked") and ,getElementData(source,"times_attacked")+1 or 1) 
        if not timer then 
            timer = setTimer(function() 
                if getElementData(source,"times_attacked") then 
                    removeElementData(source,"times_attacked") 
                end 
            end,cooldown*1000,1) 
        end 
        if getElementData(source,"times_attacked")>=3 then 
            if getElementData(source,"times_attacked") then 
                removeElementData(source,"times_attacked") 
            end 
            if timer then 
                killTimer(timer) 
                timer = false 
            end 
            -- your stuff here 
        end 
    end 
end) 
  

I have Problem fix it please

Attempt to compare Boolean with number

when i attack him 3 Times

Link to comment
local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore  
local timers = { } 
  
addEventHandler ( "onPlayerDamage", root, 
    function ( attacker, weapon ) 
        if ( isElement ( attacker ) and getElementType ( attacker ) == "player" ) then 
            if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Police" and weapon == 3 and getPlayerWantedLevel ( source ) >= 1 ) then 
                if ( timers [ source ] ) then 
                    resetTimer ( timers [ source ] ) 
                end 
                local times = ( tonumber ( getElementData ( source,"times_attacked" ) ) or 0 ) 
                setElementData ( source, "times_attacked", ( times + 1 ) ) 
  
                if ( not timers [ source ] ) then 
                    timers [ source ] = setTimer ( 
                        function ( ) 
                            if getElementData ( source,"times_attacked" ) then 
                                removeElementData ( source,"times_attacked" ) 
                                timers [ source ] = nil 
                            end 
                        end 
                        ,( cooldown * 1000 ), 1 
                    ) 
                end 
  
                if ( getElementData ( source, "times_attacked" ) >= 3 ) then 
                    if getElementData ( source,"times_attacked" ) then 
                        removeElementData ( source, "times_attacked" ) 
                    end 
                    if ( timers [ source ] ) then 
                        killTimer ( timers [ source ] ) 
                        timers [ source ] = nil 
                    end 
                end 
            end 
        end 
    end 
) 

Try it. I changed the timer part, since you were using a global variable, which means if another player was attacked, the timer for the other players would be the same, so you had to use a table.

Link to comment
local cooldown = 5 -- the amount of time after the attack combo resets if no damage is detected anymore  
local timers = { } 
  
addEventHandler ( "onPlayerDamage", root, 
    function ( attacker, weapon ) 
        if ( isElement ( attacker ) and getElementType ( attacker ) == "player" ) then 
            if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Police" and weapon == 3 and getPlayerWantedLevel ( source ) >= 1 ) then 
                if ( timers [ source ] ) then 
                    resetTimer ( timers [ source ] ) 
                end 
                local times = ( tonumber ( getElementData ( source,"times_attacked" ) ) or 0 ) 
                setElementData ( source, "times_attacked", ( times + 1 ) ) 
  
                if ( not timers [ source ] ) then 
                    timers [ source ] = setTimer ( 
                        function ( ) 
                            if getElementData ( source,"times_attacked" ) then 
                                removeElementData ( source,"times_attacked" ) 
                                timers [ source ] = nil 
                            end 
                        end 
                        ,( cooldown * 1000 ), 1 
                    ) 
                end 
  
                if ( getElementData ( source, "times_attacked" ) >= 3 ) then 
                    if getElementData ( source,"times_attacked" ) then 
                        removeElementData ( source, "times_attacked" ) 
                    end 
                    if ( timers [ source ] ) then 
                        killTimer ( timers [ source ] ) 
                        timers [ source ] = nil 
                    end 
                end 
            end 
        end 
    end 
) 

Try it. I changed the timer part, since you were using a global variable, which means if another player was attacked, the timer for the other players would be the same, so you had to use a table.

Thank you very much

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