Jump to content

[HELP]Taser


Best-Killer1

Recommended Posts

criminals can tass others players also all players can use the taser how i can make it work only for Cops ??

Code :

arresties = { } 
tased = { }
 
addEventHandler ( "onPlayerDamage", root, function ( cop, weapon, _, loss )
    -- arrest system
    if ( isElement ( cop ) and weapon and cop ~= source  ) then
       
        if ( getElementData ( cop, "SAEGEvents:IsPlayerInEvent" ) or getElementData ( source, "SAEGEvents:IsPlayerInEvent" ) ) then
            return
        end
   
        if ( cop == source ) then return end
        if ( getElementType ( cop ) == 'vehicle' ) then
            cop = getVehicleOccupant ( cop )
        end
        if ( not isElement ( cop ) or getElementType ( cop ) ~= 'player' ) then return end
        if ( not getPlayerTeam ( cop ) ) then
            return
        end
 
        if ( exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then
            if ( getElementData ( source, "isSpawnProtectionEnabled" ) == true ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player has spawn-protection enabled.", cop, 255, 0, 0 )
            end
           
            if ( getPlayerTeam ( source ) and getTeamName ( getPlayerTeam ( source ) ) == "Staff" ) then
                return exports['SAEGMessages']:sendClientMessage ( "You cannot arrest/tase on-duty staff.", cop, 255, 0, 0 )
            end
           
            if ( arresties[source] ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player is already arrested.", cop, 255, 0, 0 )
            end
            if ( getPlayerWantedLevel ( source ) >= 1 ) then
                if ( weapon == 3 ) then
                    -- Arrest
                    arrestPlayer ( source, cop )
                    exports['SAEGMessages']:sendClientMessage ( "You have arrested "..getPlayerName ( source )..", take him to a police station.", cop, 0, 255, 0 )
                    exports['SAEGMessages']:sendClientMessage ( getPlayerName ( cop ).." arrested you!", source, 255, 255, 0 )
                    setElementHealth ( source, getElementHealth ( source ) + loss )
                    setElementData ( source, "SAEGJobs:ArrestingOfficer", cop )
                   
                    addEventHandler ( "onPlayerQuit", source, onPlayerAttmemptArrestAvoid );
                elseif ( weapon == 23 ) then
                    -- Taze Player
                    if ( tased [ source ] ) then
                        return exports.SAEGMessages:sendClientMessage ( "This player is already tased", cop, 255, 255, 255 )
                    end
                   
                    local a = cop
                    local t = getPlayerTeam ( a )
                    if ( not t ) then return end
                    if ( getPlayerWantedLevel ( source ) == 0 ) then return end
                    if ( exports.SAEGPlayerFunctions:isTeamLaw ( getTeamName ( t ) ) and not getElementData ( source, "SAEGJobs:ArrestingOfficer" ) ) then
                        -- now we know:
                        -- source   -> wanted, not arrested
                        -- w        -> teaser
                        toggleAllControls ( source, false )
                        if ( isPedInVehicle ( source ) ) then
                            removePedFromVehicle ( source )
                        end
                        setPedAnimation(source, "CRACK", "crckdeth2", 4000, false, true, false)
                       
                        exports.SAEGMessages:sendClientMessage ( "You have tased ".. getPlayerName ( source ), a, 0, 255, 0 )
                        exports.SAEGMessages:sendClientMessage ( "You have been tased by "..getPlayerName ( a ), source, 255, 0, 0 )
                        tased [ source ] = true
                        setTimer ( function ( p, c )
                            if ( isElement ( p ) ) then
                                setPedAnimation ( p )
                                toggleAllControls ( p, true )
                                exports.SAEGMessages:sendClientMessage ( "You are no longer tased", p, 0, 255, 0 )
                                if ( isElement ( c ) ) then
                                    exports.SAEGMessages:sendClientMessage ( getPlayerName ( p ).." is now un-tased!", c, 255, 255, 0 )
                                end
                            end
                            tased [ p ] = false
                        end, 4000, 1, source, a )
                    end
                else
                    if ( isPedInVehicle ( cop ) ) then return end
                    exports['SAEGMessages']:sendClientMessage ( "Use a nightstick to arrest and a silenced pistol to tase", cop, 255, 255, 255 )
                end
            else
                local f = math.floor ( loss * 1.2)
                setElementHealth ( cop, getElementHealth ( cop ) - f )
                exports['SAEGMessages']:sendClientMessage ( "You've lost "..tostring ( f ).."% health for hurting an innocent player.", cop, 255, 255, 0 )
            end
        end 
    end
end )
 
function onPlayerAttmemptArrestAvoid ( )
    --outputChatBox ( getPlayerName ( source )..  " attempted to arrest avoid" )
    triggerEvent ( "saegpolice:onJailCopCrimals", getElementData ( source, "SAEGJobs:ArrestingOfficer" ) )
end
 
addCommandHandler ( "release", function ( p, _, p2 )
    if ( getPlayerTeam ( p ) and exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( p ) ) ) ) then
        if ( p2 ) then
            local c = getPlayerFromName ( p2 ) or exports['SAEGPlayerFunctions']:getPlayerFromNamePart ( p2 )
            if c then
                if ( arresties[c] ) then
                    if ( getElementData ( c, "SAEGJobs:ArrestingOfficer") == p ) then
                        exports['SAEGMessages']:sendClientMessage ( "You have released "..getPlayerName ( c ), p, 0, 255, 0)
                        exports['SAEGMessages']:sendClientMessage ( getPlayerName ( p ).." released you.", c, 0, 255, 0 )
                        releasePlayer ( c )
                        local arresties2 = { }
                        for i, v in pairs ( arresties ) do
                            if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == p ) then
                                table.insert ( arresties2, v )
                            end
                        end
                        triggerClientEvent ( root, "onPlayerEscapeCop", root, c, p, arresties2 )
                    else exports['SAEGMessages']:sendClientMessage ( "You're not "..getPlayerName ( c ).."'s arresting officer, you cannot release him.", p, 255, 255, 0 ) end
                else exports['SAEGMessages']:sendClientMessage ( getPlayerName ( c ).." isn't being arrested", p, 255, 255, 0 ) end
            else exports['SAEGMessages']:sendClientMessage ( p2.." doesn't exist. ", p, 255, 255, 0 ) end
        else exports['SAEGMessages']:sendClientMessage ( "Syntax error. /release [player]", p, 255, 255, 0 ) end
    else exports['SAEGMessages']:sendClientMessage ( "You're not a law officer.", p, 255, 255, 0 ) end
end )
 
function arrestPlayer ( crim, cop )
    showCursor ( crim, true )
    arresties[crim] = true
    toggleControl ( crim, 'right', false )
    toggleControl ( crim, 'left', false )
    toggleControl ( crim, 'forwards', false )
    toggleControl ( crim, 'backwards', false )
    toggleControl ( crim, 'jump', false )
    toggleControl ( crim, 'sprint', false )
    toggleControl ( crim, 'walk', false )
    toggleControl ( crim, 'fire', false )
    onTimer ( crim, cop )
    triggerClientEvent ( root, "onPlayerStartArrested", root, crim, cop )
end
 
function onTimer ( crim, cop )
    if ( isElement ( crim ) and isElement ( cop ) ) then
        if ( not getPlayerTeam ( cop ) or not exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then return releasePlayer ( crim ) end
        if ( not arresties[crim] ) then return  end
        local cx, cy, cz = getElementPosition ( crim )
        local px, py, pz = getElementPosition ( cop )
        local rot = findRotation ( cx, cy, px, py )
        setPedRotation ( crim, rot )
        setCameraTarget ( crim, crim )
        local dist = getDistanceBetweenPoints3D ( cx, cy, cz, px, py, pz )
        if ( isPedInVehicle ( cop ) ) then
            if ( not isPedInVehicle ( crim ) ) then
                warpPedIntoVehicle ( crim, getPedOccupiedVehicle ( cop ), 1 )
            end
        else
            if ( isPedInVehicle ( crim ) ) then
                removePedFromVehicle ( crim )
            end
        end
        if ( not isPedInVehicle ( crim ) ) then
            if ( dist >= 20 ) then
                setElementPosition ( crim, px +1, py+1, pz )
            elseif ( dist >= 15 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 10 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 7 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 2 ) then
                setControlState ( crim, 'walk', true )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            else
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", false )
            end
        end
       
        crim.interior = cop.interior;
        crim.dimension = cop.dimension
       
        setTimer ( onTimer, 500, 1, crim, cop )
    else
        arresties[crim] = false
        if ( not isElement ( cop ) and isElement ( crim ) ) then
            releasePlayer ( crim )
            exports['SAEGMessages']:sendClientMessage ( "Your arresting officer has quit, therefore, you've been released.", crim, 0, 255, 0 )
        end
    end
end
 
function findRotation(x1,y1,x2,y2)
    local t = -math.deg(math.atan2(x2-x1,y2-y1))
    if t < 0 then t = t + 360 end;
    return t;
end
 
function releasePlayer ( p )
    toggleAllControls ( p, true )
    setControlState ( p, 'walk', false )
    setControlState ( p, 'jump', false )
    setControlState ( p, 'sprint', false )
    setControlState ( p, "forwards", true )
    setElementData ( p, "SAEGJobs:ArrestingOfficer", nil )
    arresties[p] = nil
    showCursor ( p, false )
    removeEventHandler ( "onPlayerQuit", p, onPlayerAttmemptArrestAvoid );
end
 
 
function onJailCopCriminals( )
    for v, _ in pairs ( arresties ) do
        if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == source ) then
           
            releasePlayer ( v )
            local time = math.floor ( ( getElementData ( v, "WantedPoints" ) * 2 ) or 50 )
            local orgTime = time
            local vip = getElementData ( v, "VIP" )
            if ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 4 ) then
                time = time - ( time * 0.5 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 50% less jail time due to diamond VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 3  ) then
                time = time - ( time * 0.25 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 25% less jail time due to gold VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 2 ) then
                time = time - ( time * 0.15 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 15% less jail time due to silver VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 1 ) then
                time = time - ( time * 0.05 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 5% less jail time due to bronze VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            end
           
            local time = math.floor ( time )
           
            givePlayerMoney ( source, math.floor ( orgTime*2 ) )
            exports['SAEGMessages']:sendClientMessage ( "You were paid $"..math.floor ( orgTime*2 ).." for arresting "..getPlayerName ( v ).."!", source, 0, 255, 0 )
            exports['SAEGPolice']:jailPlayer ( v, time, false, source, "Police Arrest" )
            updateJobColumn ( getAccountName ( getPlayerAccount ( source ) ), "Arrests", "AddOne" )
        end
    end
end
 
addEvent ( "saegpolice:onJailCopCrimals", true )
addEventHandler ( "saegpolice:onJailCopCrimals", root, onJailCopCriminals )
 
  • Like 1
Link to comment
  • 2 weeks later...
  • 1 month later...
criminals can tass others players also all players can use the taser how i can make it work only for Cops ??

Code :

arresties = { } 
tased = { }
 
addEventHandler ( "onPlayerDamage", root, function ( cop, weapon, _, loss )
    -- arrest system
    if ( isElement ( cop ) and weapon and cop ~= source  ) then
       
        if ( getElementData ( cop, "SAEGEvents:IsPlayerInEvent" ) or getElementData ( source, "SAEGEvents:IsPlayerInEvent" ) ) then
            return
        end
   
        if ( cop == source ) then return end
        if ( getElementType ( cop ) == 'vehicle' ) then
            cop = getVehicleOccupant ( cop )
        end
        if ( not isElement ( cop ) or getElementType ( cop ) ~= 'player' ) then return end
        if ( not getPlayerTeam ( cop ) ) then
            return
        end
 
        if ( exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then
            if ( getElementData ( source, "isSpawnProtectionEnabled" ) == true ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player has spawn-protection enabled.", cop, 255, 0, 0 )
            end
           
            if ( getPlayerTeam ( source ) and getTeamName ( getPlayerTeam ( source ) ) == "Staff" ) then
                return exports['SAEGMessages']:sendClientMessage ( "You cannot arrest/tase on-duty staff.", cop, 255, 0, 0 )
            end
           
            if ( arresties[source] ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player is already arrested.", cop, 255, 0, 0 )
            end
            if ( getPlayerWantedLevel ( source ) >= 1 ) then
                if ( weapon == 3 ) then
                    -- Arrest
                    arrestPlayer ( source, cop )
                    exports['SAEGMessages']:sendClientMessage ( "You have arrested "..getPlayerName ( source )..", take him to a police station.", cop, 0, 255, 0 )
                    exports['SAEGMessages']:sendClientMessage ( getPlayerName ( cop ).." arrested you!", source, 255, 255, 0 )
                    setElementHealth ( source, getElementHealth ( source ) + loss )
                    setElementData ( source, "SAEGJobs:ArrestingOfficer", cop )
                   
                    addEventHandler ( "onPlayerQuit", source, onPlayerAttmemptArrestAvoid );
                elseif ( weapon == 23 ) then
                    -- Taze Player
                    if ( tased [ source ] ) then
                        return exports.SAEGMessages:sendClientMessage ( "This player is already tased", cop, 255, 255, 255 )
                    end
                   
                    local a = cop
                    local t = getPlayerTeam ( a )
                    if ( not t ) then return end
                    if ( getPlayerWantedLevel ( source ) == 0 ) then return end
                    if ( exports.SAEGPlayerFunctions:isTeamLaw ( getTeamName ( t ) ) and not getElementData ( source, "SAEGJobs:ArrestingOfficer" ) ) then
                        -- now we know:
                        -- source   -> wanted, not arrested
                        -- w        -> teaser
                        toggleAllControls ( source, false )
                        if ( isPedInVehicle ( source ) ) then
                            removePedFromVehicle ( source )
                        end
                        setPedAnimation(source, "CRACK", "crckdeth2", 4000, false, true, false)
                       
                        exports.SAEGMessages:sendClientMessage ( "You have tased ".. getPlayerName ( source ), a, 0, 255, 0 )
                        exports.SAEGMessages:sendClientMessage ( "You have been tased by "..getPlayerName ( a ), source, 255, 0, 0 )
                        tased [ source ] = true
                        setTimer ( function ( p, c )
                            if ( isElement ( p ) ) then
                                setPedAnimation ( p )
                                toggleAllControls ( p, true )
                                exports.SAEGMessages:sendClientMessage ( "You are no longer tased", p, 0, 255, 0 )
                                if ( isElement ( c ) ) then
                                    exports.SAEGMessages:sendClientMessage ( getPlayerName ( p ).." is now un-tased!", c, 255, 255, 0 )
                                end
                            end
                            tased [ p ] = false
                        end, 4000, 1, source, a )
                    end
                else
                    if ( isPedInVehicle ( cop ) ) then return end
                    exports['SAEGMessages']:sendClientMessage ( "Use a nightstick to arrest and a silenced pistol to tase", cop, 255, 255, 255 )
                end
            else
                local f = math.floor ( loss * 1.2)
                setElementHealth ( cop, getElementHealth ( cop ) - f )
                exports['SAEGMessages']:sendClientMessage ( "You've lost "..tostring ( f ).."% health for hurting an innocent player.", cop, 255, 255, 0 )
            end
        end 
    end
end )
 
function onPlayerAttmemptArrestAvoid ( )
    --outputChatBox ( getPlayerName ( source )..  " attempted to arrest avoid" )
    triggerEvent ( "saegpolice:onJailCopCrimals", getElementData ( source, "SAEGJobs:ArrestingOfficer" ) )
end
 
addCommandHandler ( "release", function ( p, _, p2 )
    if ( getPlayerTeam ( p ) and exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( p ) ) ) ) then
        if ( p2 ) then
            local c = getPlayerFromName ( p2 ) or exports['SAEGPlayerFunctions']:getPlayerFromNamePart ( p2 )
            if c then
                if ( arresties[c] ) then
                    if ( getElementData ( c, "SAEGJobs:ArrestingOfficer") == p ) then
                        exports['SAEGMessages']:sendClientMessage ( "You have released "..getPlayerName ( c ), p, 0, 255, 0)
                        exports['SAEGMessages']:sendClientMessage ( getPlayerName ( p ).." released you.", c, 0, 255, 0 )
                        releasePlayer ( c )
                        local arresties2 = { }
                        for i, v in pairs ( arresties ) do
                            if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == p ) then
                                table.insert ( arresties2, v )
                            end
                        end
                        triggerClientEvent ( root, "onPlayerEscapeCop", root, c, p, arresties2 )
                    else exports['SAEGMessages']:sendClientMessage ( "You're not "..getPlayerName ( c ).."'s arresting officer, you cannot release him.", p, 255, 255, 0 ) end
                else exports['SAEGMessages']:sendClientMessage ( getPlayerName ( c ).." isn't being arrested", p, 255, 255, 0 ) end
            else exports['SAEGMessages']:sendClientMessage ( p2.." doesn't exist. ", p, 255, 255, 0 ) end
        else exports['SAEGMessages']:sendClientMessage ( "Syntax error. /release [player]", p, 255, 255, 0 ) end
    else exports['SAEGMessages']:sendClientMessage ( "You're not a law officer.", p, 255, 255, 0 ) end
end )
 
function arrestPlayer ( crim, cop )
    showCursor ( crim, true )
    arresties[crim] = true
    toggleControl ( crim, 'right', false )
    toggleControl ( crim, 'left', false )
    toggleControl ( crim, 'forwards', false )
    toggleControl ( crim, 'backwards', false )
    toggleControl ( crim, 'jump', false )
    toggleControl ( crim, 'sprint', false )
    toggleControl ( crim, 'walk', false )
    toggleControl ( crim, 'fire', false )
    onTimer ( crim, cop )
    triggerClientEvent ( root, "onPlayerStartArrested", root, crim, cop )
end
 
function onTimer ( crim, cop )
    if ( isElement ( crim ) and isElement ( cop ) ) then
        if ( not getPlayerTeam ( cop ) or not exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then return releasePlayer ( crim ) end
        if ( not arresties[crim] ) then return  end
        local cx, cy, cz = getElementPosition ( crim )
        local px, py, pz = getElementPosition ( cop )
        local rot = findRotation ( cx, cy, px, py )
        setPedRotation ( crim, rot )
        setCameraTarget ( crim, crim )
        local dist = getDistanceBetweenPoints3D ( cx, cy, cz, px, py, pz )
        if ( isPedInVehicle ( cop ) ) then
            if ( not isPedInVehicle ( crim ) ) then
                warpPedIntoVehicle ( crim, getPedOccupiedVehicle ( cop ), 1 )
            end
        else
            if ( isPedInVehicle ( crim ) ) then
                removePedFromVehicle ( crim )
            end
        end
        if ( not isPedInVehicle ( crim ) ) then
            if ( dist >= 20 ) then
                setElementPosition ( crim, px +1, py+1, pz )
            elseif ( dist >= 15 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 10 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 7 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 2 ) then
                setControlState ( crim, 'walk', true )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            else
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", false )
            end
        end
       
        crim.interior = cop.interior;
        crim.dimension = cop.dimension
       
        setTimer ( onTimer, 500, 1, crim, cop )
    else
        arresties[crim] = false
        if ( not isElement ( cop ) and isElement ( crim ) ) then
            releasePlayer ( crim )
            exports['SAEGMessages']:sendClientMessage ( "Your arresting officer has quit, therefore, you've been released.", crim, 0, 255, 0 )
        end
    end
end
 
function findRotation(x1,y1,x2,y2)
    local t = -math.deg(math.atan2(x2-x1,y2-y1))
    if t < 0 then t = t + 360 end;
    return t;
end
 
function releasePlayer ( p )
    toggleAllControls ( p, true )
    setControlState ( p, 'walk', false )
    setControlState ( p, 'jump', false )
    setControlState ( p, 'sprint', false )
    setControlState ( p, "forwards", true )
    setElementData ( p, "SAEGJobs:ArrestingOfficer", nil )
    arresties[p] = nil
    showCursor ( p, false )
    removeEventHandler ( "onPlayerQuit", p, onPlayerAttmemptArrestAvoid );
end
 
 
function onJailCopCriminals( )
    for v, _ in pairs ( arresties ) do
        if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == source ) then
           
            releasePlayer ( v )
            local time = math.floor ( ( getElementData ( v, "WantedPoints" ) * 2 ) or 50 )
            local orgTime = time
            local vip = getElementData ( v, "VIP" )
            if ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 4 ) then
                time = time - ( time * 0.5 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 50% less jail time due to diamond VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 3  ) then
                time = time - ( time * 0.25 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 25% less jail time due to gold VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 2 ) then
                time = time - ( time * 0.15 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 15% less jail time due to silver VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 1 ) then
                time = time - ( time * 0.05 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 5% less jail time due to bronze VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            end
           
            local time = math.floor ( time )
           
            givePlayerMoney ( source, math.floor ( orgTime*2 ) )
            exports['SAEGMessages']:sendClientMessage ( "You were paid $"..math.floor ( orgTime*2 ).." for arresting "..getPlayerName ( v ).."!", source, 0, 255, 0 )
            exports['SAEGPolice']:jailPlayer ( v, time, false, source, "Police Arrest" )
            updateJobColumn ( getAccountName ( getPlayerAccount ( source ) ), "Arrests", "AddOne" )
        end
    end
end
 
Link to comment
criminals can tass others players also all players can use the taser how i can make it work only for Cops ??

Code :

arresties = { } 
tased = { }
 
addEventHandler ( "onPlayerDamage", root, function ( cop, weapon, _, loss )
    -- arrest system
    if ( isElement ( cop ) and weapon and cop ~= source  ) then
       
        if ( getElementData ( cop, "SAEGEvents:IsPlayerInEvent" ) or getElementData ( source, "SAEGEvents:IsPlayerInEvent" ) ) then
            return
        end
    NG Game Mode -- s;) -->
        if ( cop == source ) then return end
        if ( getElementType ( cop ) == 'vehicle' ) then
            cop = getVehicleOccupant ( cop )
        end
        if ( not isElement ( cop ) or getElementType ( cop ) ~= 'player' ) then return end
        if ( not getPlayerTeam ( cop ) ) then
            return
        end
 
        if ( exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then
            if ( getElementData ( source, "isSpawnProtectionEnabled" ) == true ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player has spawn-protection enabled.", cop, 255, 0, 0 )
            end
           
            if ( getPlayerTeam ( source ) and getTeamName ( getPlayerTeam ( source ) ) == "Staff" ) then
                return exports['SAEGMessages']:sendClientMessage ( "You cannot arrest/tase on-duty staff.", cop, 255, 0, 0 )
            end
           
            if ( arresties[source] ) then
                return exports['SAEGMessages']:sendClientMessage ( "This player is already arrested.", cop, 255, 0, 0 )
            end
            if ( getPlayerWantedLevel ( source ) >= 1 ) then
                if ( weapon == 3 ) then
                    -- Arrest
                    arrestPlayer ( source, cop )
                    exports['SAEGMessages']:sendClientMessage ( "You have arrested "..getPlayerName ( source )..", take him to a police station.", cop, 0, 255, 0 )
                    exports['SAEGMessages']:sendClientMessage ( getPlayerName ( cop ).." arrested you!", source, 255, 255, 0 )
                    setElementHealth ( source, getElementHealth ( source ) + loss )
                    setElementData ( source, "SAEGJobs:ArrestingOfficer", cop )
                   
                    addEventHandler ( "onPlayerQuit", source, onPlayerAttmemptArrestAvoid );
                elseif ( weapon == 23 ) then
                    -- Taze Player
                    if ( tased [ source ] ) then
                        return exports.SAEGMessages:sendClientMessage ( "This player is already tased", cop, 255, 255, 255 )
                    end
                   
                    local a = cop
                    local t = getPlayerTeam ( a )
                    if ( not t ) then return end
                    if ( getPlayerWantedLevel ( source ) == 0 ) then return end
                    if ( exports.SAEGPlayerFunctions:isTeamLaw ( getTeamName ( t ) ) and not getElementData ( source, "SAEGJobs:ArrestingOfficer" ) ) then
                        -- now we know:
                        -- source   -> wanted, not arrested
                        -- w        -> teaser
                        toggleAllControls ( source, false )
                        if ( isPedInVehicle ( source ) ) then
                            removePedFromVehicle ( source )
                        end
                        setPedAnimation(source, "CRACK", "crckdeth2", 4000, false, true, false)
                       
                        exports.SAEGMessages:sendClientMessage ( "You have tased ".. getPlayerName ( source ), a, 0, 255, 0 )
                        exports.SAEGMessages:sendClientMessage ( "You have been tased by "..getPlayerName ( a ), source, 255, 0, 0 )
                        tased [ source ] = true
                        setTimer ( function ( p, c )
                            if ( isElement ( p ) ) then
                                setPedAnimation ( p )
                                toggleAllControls ( p, true )
                                exports.SAEGMessages:sendClientMessage ( "You are no longer tased", p, 0, 255, 0 )
                                if ( isElement ( c ) ) then
                                    exports.SAEGMessages:sendClientMessage ( getPlayerName ( p ).." is now un-tased!", c, 255, 255, 0 )
                                end
                            end
                            tased [ p ] = false
                        end, 4000, 1, source, a )
                    end
                else
                    if ( isPedInVehicle ( cop ) ) then return end
                    exports['SAEGMessages']:sendClientMessage ( "Use a nightstick to arrest and a silenced pistol to tase", cop, 255, 255, 255 )
                end
            else
                local f = math.floor ( loss * 1.2)
                setElementHealth ( cop, getElementHealth ( cop ) - f )
                exports['SAEGMessages']:sendClientMessage ( "You've lost "..tostring ( f ).."% health for hurting an innocent player.", cop, 255, 255, 0 )
            end
        end 
    end
end )
 
function onPlayerAttmemptArrestAvoid ( )
    --outputChatBox ( getPlayerName ( source )..  " attempted to arrest avoid" )
    triggerEvent ( "saegpolice:onJailCopCrimals", getElementData ( source, "SAEGJobs:ArrestingOfficer" ) )
end
 
addCommandHandler ( "release", function ( p, _, p2 )
    if ( getPlayerTeam ( p ) and exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( p ) ) ) ) then
        if ( p2 ) then
            local c = getPlayerFromName ( p2 ) or exports['SAEGPlayerFunctions']:getPlayerFromNamePart ( p2 )
            if c then
                if ( arresties[c] ) then
                    if ( getElementData ( c, "SAEGJobs:ArrestingOfficer") == p ) then
                        exports['SAEGMessages']:sendClientMessage ( "You have released "..getPlayerName ( c ), p, 0, 255, 0)
                        exports['SAEGMessages']:sendClientMessage ( getPlayerName ( p ).." released you.", c, 0, 255, 0 )
                        releasePlayer ( c )
                        local arresties2 = { }
                        for i, v in pairs ( arresties ) do
                            if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == p ) then
                                table.insert ( arresties2, v )
                            end
                        end
                        triggerClientEvent ( root, "onPlayerEscapeCop", root, c, p, arresties2 )
                    else exports['SAEGMessages']:sendClientMessage ( "You're not "..getPlayerName ( c ).."'s arresting officer, you cannot release him.", p, 255, 255, 0 ) end
                else exports['SAEGMessages']:sendClientMessage ( getPlayerName ( c ).." isn't being arrested", p, 255, 255, 0 ) end
            else exports['SAEGMessages']:sendClientMessage ( p2.." doesn't exist. ", p, 255, 255, 0 ) end
        else exports['SAEGMessages']:sendClientMessage ( "Syntax error. /release [player]", p, 255, 255, 0 ) end
    else exports['SAEGMessages']:sendClientMessage ( "You're not a law officer.", p, 255, 255, 0 ) end
end )
 
function arrestPlayer ( crim, cop )
    showCursor ( crim, true )
    arresties[crim] = true
    toggleControl ( crim, 'right', false )
    toggleControl ( crim, 'left', false )
    toggleControl ( crim, 'forwards', false )
    toggleControl ( crim, 'backwards', false )
    toggleControl ( crim, 'jump', false )
    toggleControl ( crim, 'sprint', false )
    toggleControl ( crim, 'walk', false )
    toggleControl ( crim, 'fire', false )
    onTimer ( crim, cop )
    triggerClientEvent ( root, "onPlayerStartArrested", root, crim, cop )
end
 
function onTimer ( crim, cop )
    if ( isElement ( crim ) and isElement ( cop ) ) then
        if ( not getPlayerTeam ( cop ) or not exports['SAEGPlayerFunctions']:isTeamLaw ( getTeamName ( getPlayerTeam ( cop ) ) ) ) then return releasePlayer ( crim ) end
        if ( not arresties[crim] ) then return  end
        local cx, cy, cz = getElementPosition ( crim )
        local px, py, pz = getElementPosition ( cop )
        local rot = findRotation ( cx, cy, px, py )
        setPedRotation ( crim, rot )
        setCameraTarget ( crim, crim )
        local dist = getDistanceBetweenPoints3D ( cx, cy, cz, px, py, pz )
        if ( isPedInVehicle ( cop ) ) then
            if ( not isPedInVehicle ( crim ) ) then
                warpPedIntoVehicle ( crim, getPedOccupiedVehicle ( cop ), 1 )
            end
        else
            if ( isPedInVehicle ( crim ) ) then
                removePedFromVehicle ( crim )
            end
        end
        if ( not isPedInVehicle ( crim ) ) then
            if ( dist >= 20 ) then
                setElementPosition ( crim, px +1, py+1, pz )
            elseif ( dist >= 15 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 10 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', true )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 7 ) then
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', true )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            elseif ( dist >= 2 ) then
                setControlState ( crim, 'walk', true )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", true )
            else
                setControlState ( crim, 'walk', false )
                setControlState ( crim, 'jump', false )
                setControlState ( crim, 'sprint', false )
                setControlState ( crim, "forwards", false )
            end
        end
       
        crim.interior = cop.interior;
        crim.dimension = cop.dimension
       
        setTimer ( onTimer, 500, 1, crim, cop )
    else
        arresties[crim] = false
        if ( not isElement ( cop ) and isElement ( crim ) ) then
            releasePlayer ( crim )
            exports['SAEGMessages']:sendClientMessage ( "Your arresting officer has quit, therefore, you've been released.", crim, 0, 255, 0 )
        end
    end
end
 
function findRotation(x1,y1,x2,y2)
    local t = -math.deg(math.atan2(x2-x1,y2-y1))
    if t < 0 then t = t + 360 end;
    return t;
end
 
function releasePlayer ( p )
    toggleAllControls ( p, true )
    setControlState ( p, 'walk', false )
    setControlState ( p, 'jump', false )
    setControlState ( p, 'sprint', false )
    setControlState ( p, "forwards", true )
    setElementData ( p, "SAEGJobs:ArrestingOfficer", nil )
    arresties[p] = nil
    showCursor ( p, false )
    removeEventHandler ( "onPlayerQuit", p, onPlayerAttmemptArrestAvoid );
end
 
 
function onJailCopCriminals( )
    for v, _ in pairs ( arresties ) do
        if ( getElementData ( v, "SAEGJobs:ArrestingOfficer" ) == source ) then
           
            releasePlayer ( v )
            local time = math.floor ( ( getElementData ( v, "WantedPoints" ) * 2 ) or 50 )
            local orgTime = time
            local vip = getElementData ( v, "VIP" )
            if ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 4 ) then
                time = time - ( time * 0.5 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 50% less jail time due to diamond VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 3  ) then
                time = time - ( time * 0.25 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 25% less jail time due to gold VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 2 ) then
                time = time - ( time * 0.15 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 15% less jail time due to silver VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            elseif ( exports.SAEGVIP:getVipLevelFromName ( vip ) == 1 ) then
                time = time - ( time * 0.05 )
                exports.SAEGMessages:sendClientMessage ( "You're serving 5% less jail time due to bronze VIP! (Original time: "..orgTime.." seconds)", v, 0, 255, 0 )
            end
           
            local time = math.floor ( time )
           
            givePlayerMoney ( source, math.floor ( orgTime*2 ) )
            exports['SAEGMessages']:sendClientMessage ( "You were paid $"..math.floor ( orgTime*2 ).." for arresting "..getPlayerName ( v ).."!", source, 0, 255, 0 )
            exports['SAEGPolice']:jailPlayer ( v, time, false, source, "Police Arrest" )
            updateJobColumn ( getAccountName ( getPlayerAccount ( source ) ), "Arrests", "AddOne" )
        end
    end
end
 
Link to comment
  • Moderators

Line 17..............

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

............ Ask him yourself, it is his script. -__-"

Link to comment
Line 17..............

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

..................................................................................................................................

............ Ask him yourself, it is his script. -__-"

Thanks You :P i don't need him for ask him i want know just where is the problem :) you told me Line 17

And Now It's Fixed

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