Jump to content

Police ban [Help]


Price.

Recommended Posts

so there's this part of script which I'm able to kick people from police team with.. like with time /kick and when the time is over he can take the job again but when only the time is over, I have that but which I can't do is:

I can't connect this command to the police job, so when I kick someone he is still being able to get the job

--[[ Police chiefs can ban from law at unlimited time ]]-- 
function add_law_ban(police_chief, cmd, bad_officer) 
    -- Check if an officer to kick was provided 
    if not bad_officer then  
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return  
    end 
     
    -- Check if the provided cop account exist 
    local cop_to_ban = getAccount(bad_officer) 
    local cop_to_ban_plr = getAccountPlayer(cop_to_ban) 
    if not cop_to_ban then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return  
    end 
     
    -- Notify the cop if online 
    if cop_to_ban_plr then 
        exports.GTWtopbar:dm("You have been kicked from the force by: "..getPlayerName(police_chief), cop_to_ban_plr, 255, 0, 0) 
         
        -- Reset job and team if online 
        setPlayerTeam(cop_to_ban_plr, getTeamFromName("Unemployed")) 
        setPlayerNametagColor(cop_to_ban_plr, 255, 255, 0) 
        setElementData(cop_to_ban_plr, "admin",false) 
        local skinID = exports.GTWclothes:getBoughtSkin(cop_to_ban_plr) 
        setElementModel(cop_to_ban_plr, skinID) 
        setElementData(cop_to_ban_plr, "Occupation", "") 
    end 
     
    -- Notify the police chief issuing the command 
    outputChatBox("Police: "..bad_officer.." was kicked from the police job", police_chief, 255, 100, 0) 
             
    -- Save ban to database 
    dbExec(db_pc, "INSERT INTO bans VALUES (NULL,?)", bad_officer) 
    banned_cops_data[bad_officer] = true 
end 
addCommandHandler("banfromlaw", add_law_ban) 
addCommandHandler("lawban", add_law_ban) 
  

No errors, just can't connect it . thanks in advance.

Link to comment

It would be better to use account data rather than using a database.

--[[ Police chiefs can ban from law at unlimited time ]]-- 
function add_law_ban(police_chief, cmd, bad_officer) 
    -- Check if an officer to kick was provided 
    if not bad_officer then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Check if the provided cop account exist 
    local cop_to_ban = getAccount(bad_officer) 
    local cop_to_ban_plr = getAccountPlayer(cop_to_ban) 
    if not cop_to_ban then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Notify the cop if online 
    if cop_to_ban_plr then 
        exports.GTWtopbar:dm("You have been kicked from the force by: "..getPlayerName(police_chief), cop_to_ban_plr, 255, 0, 0) 
        
        -- Reset job and team if online 
        setPlayerTeam(cop_to_ban_plr, getTeamFromName("Unemployed")) 
        setPlayerNametagColor(cop_to_ban_plr, 255, 255, 0) 
        setElementData(cop_to_ban_plr, "admin",false) 
        local skinID = exports.GTWclothes:getBoughtSkin(cop_to_ban_plr) 
        setElementModel(cop_to_ban_plr, skinID) 
        setElementData(cop_to_ban_plr, "Occupation", "") 
         
        local ac = getPlayerAccount ( cop_to_ban_plr ); 
        if ( not isGuestAccount ( cop_to_ban_plr ) ) then  
            setAccountData ( ac, "lockedFromPolice", getTickCount ( ) + 5*60*1000 ); 
        end  
    end 
    
    -- Notify the police chief issuing the command 
    outputChatBox("Police: "..bad_officer.." was kicked from the police job", police_chief, 255, 100, 0) 
  
end 
addCommandHandler("banfromlaw", add_law_ban) 
addCommandHandler("lawban", add_law_ban) 
  

When the player goes to the job, you can check the "lockedFromPolice" account data which will either return false/nil or an integer. If it's an integer, check to see if getTickCount is smaller than the value and if it is then that means they are still blocked from the job.

Link to comment

Account data creates useless requirements, if you want to change the database structure you'll be forced to edit multiple resources instead. This looks like a part of this system, which has exported functions to check if someone is a police chief or banned from law. All you have to do is to call the exported functions and get true or false in return then the system manages the rest, like the database for instance.

A police chief system based on SQLite, police chiefs can kick police officers from the police job (law ban), who doesn't do their job correctly. Law bans and police chiefs can be listed by commands.

Functions available

Not available, There is no information about this resource functions available currently, see the source code for details, or fork and contribute by yourself (pull request).

Exported functions

bool = isPoliceChief(player plr)  (server) Check if a player is a police chief or not. 
bool = isLawBanned(player plr)  (server) Check if a player is allowed to join the police force. 

Requirements

None, This resource is independent and will run without requirements of other resources.

Link to comment
  • 2 weeks later...
It would be better to use account data rather than using a database.
--[[ Police chiefs can ban from law at unlimited time ]]-- 
function add_law_ban(police_chief, cmd, bad_officer) 
    -- Check if an officer to kick was provided 
    if not bad_officer then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Check if the provided cop account exist 
    local cop_to_ban = getAccount(bad_officer) 
    local cop_to_ban_plr = getAccountPlayer(cop_to_ban) 
    if not cop_to_ban then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Notify the cop if online 
    if cop_to_ban_plr then 
        exports.GTWtopbar:dm("You have been kicked from the force by: "..getPlayerName(police_chief), cop_to_ban_plr, 255, 0, 0) 
        
        -- Reset job and team if online 
        setPlayerTeam(cop_to_ban_plr, getTeamFromName("Unemployed")) 
        setPlayerNametagColor(cop_to_ban_plr, 255, 255, 0) 
        setElementData(cop_to_ban_plr, "admin",false) 
        local skinID = exports.GTWclothes:getBoughtSkin(cop_to_ban_plr) 
        setElementModel(cop_to_ban_plr, skinID) 
        setElementData(cop_to_ban_plr, "Occupation", "") 
         
        local ac = getPlayerAccount ( cop_to_ban_plr ); 
        if ( not isGuestAccount ( cop_to_ban_plr ) ) then  
            setAccountData ( ac, "lockedFromPolice", getTickCount ( ) + 5*60*1000 ); 
        end  
    end 
    
    -- Notify the police chief issuing the command 
    outputChatBox("Police: "..bad_officer.." was kicked from the police job", police_chief, 255, 100, 0) 
  
end 
addCommandHandler("banfromlaw", add_law_ban) 
addCommandHandler("lawban", add_law_ban) 
  

When the player goes to the job, you can check the "lockedFromPolice" account data which will either return false/nil or an integer. If it's an integer, check to see if getTickCount is smaller than the value and if it is then that means they are still blocked from the job.

still didn't work, returning errors.. what can I do?

Account data creates useless requirements, if you want to change the database structure you'll be forced to edit multiple resources instead. This looks like a part of this system, which has exported functions to check if someone is a police chief or banned from law. All you have to do is to call the exported functions and get true or false in return then the system manages the rest, like the database for instance.
A police chief system based on SQLite, police chiefs can kick police officers from the police job (law ban), who doesn't do their job correctly. Law bans and police chiefs can be listed by commands.

Functions available

Not available, There is no information about this resource functions available currently, see the source code for details, or fork and contribute by yourself (pull request).

Exported functions

bool = isPoliceChief(player plr)  (server) Check if a player is a police chief or not. 
bool = isLawBanned(player plr)  (server) Check if a player is allowed to join the police force. 

Requirements

None, This resource is independent and will run without requirements of other resources.

I tried that already

function isLawBanned(plr) 
    if not plr or not getPlayerAccount(plr) or not getAccountName(getPlayerAccount(plr)) then return false end 
    return banned_cops_data[getAccountName(getPlayerAccount(plr))] or false 
end 
  

and added the export in the police job, the job works normal. I can still get the job even tho I'm banned.

Link to comment

Show the code where you call the exported function, it returns a boolean value indicating if the player is banned or not, here's an example on how you can use it. Also note that you must be logged in, otherwise it will skip the check as the feature is disabled for players not currently logged in.

local is_law_banned = exports.GTWpolicechief:isLawBanned(client)  
if team == "Government" and is_law_banned then   
    exports.GTWtopbar:dm( "You are banned from the government team! choose another job.", client, 255, 0, 0 )  
    return   
end  

Link to comment

I used this

  local is_law_banned = exports.GTWpolicechief:isLawBanned(client) 
    if exports.GRGPlayerFunctions:isLawTeam and is_law_banned then  
     exports.GRGMessages:sendClientMessage( "You are banned from Law Jobs! choose another job.", client, 255, 0, 0 ) 
     return  
    end 
 triggerClientEvent ( p, 'GRGJobs:OpenJobMenu', p, 'police' ) 

still I could take the job

Link to comment

On line 2 you also use this piece of code in your if statement:

exports.GRGPlayerFunctions:isLawTeam 

Are you sure that's not a function? written the way it is now it's seen as a variable which isn't defined and thus it will always be seen as false meaning no matter what the other condition are it will always skip that check. Try this:

local is_law_banned = exports.GTWpolicechief:isLawBanned(client) 
local is_law_team = exports.GRGPlayerFunctions:isLawTeam(client) 
if is_law_team and is_law_banned then  
    exports.GRGMessages:sendClientMessage( "You are banned from Law Jobs! choose another job.", client, 255, 0, 0 ) 
    return  
end 
triggerClientEvent ( p, 'GRGJobs:OpenJobMenu', p, 'police' ) 

Still confused about line 2 however, how does it know which player it should check, what's the correct syntax for that? GTWpolicechief is already used correctly.

Link to comment

Police Job Function

  elseif ( name == 'Police' ) then 
        create3DText ( 'Police', { x, y, z }, { 0, 100, 255 }, { nil, true } ) 
        local p = createElement ( "GodmodePed" ) 
        setElementData ( p, "Model", 281 ) 
        setElementData ( p, "Position", { x, y, z, rz } ) 
        createBlip ( x, y, z, 61, 2, 255, 255, 255, 255, 0, 450 ) 
        addEventHandler ( 'onMarkerHit', createMarker ( x, y, z - 1, 'cylinder', 2, 0, 0, 0, 0 ), function ( p ) 
         local is_law_banned = exports.GTWpolicechief:isLawBanned(client) 
           local is_law_team = exports.GRGPlayerFunctions:isLawTeam(client) 
            if ( getElementType ( p ) == 'player' and not isPedInVehicle ( p ) and not isPedDead ( p ) ) then 
           if is_law_team and is_law_banned then 
           exports['GRGMessages']:sendClientMessage ( "You are banned from Law Jobs! choose another job.", client, 255, 0, 0 ) 
    return 
end 
                if ( getPlayerWantedLevel ( p ) > max_wanted.law ) then 
                    return exports['GRGMessages']:sendClientMessage ( "The max wanted level for this job is "..tostring ( max_wanted.law )..".", p, 255, 0, 0 ) 
                end 
                triggerClientEvent ( p, 'GRGJobs:OpenJobMenu', p, 'police' ) 
            end 
        end ) 

and Police chief script

--[[  
******************************************************************************** 
    Project owner:      GTWGames                                                 
    Project name:       GTW-RPG  
    Developers:     GTWCode 
     
    Source code:        [url=https://github.com/GTWCode/GTW-RPG/]https://github.com/GTWCode/GTW-RPG/[/url] 
    Bugtracker:     [url=http://forum.gtw-games.org/bug-reports/]http://forum.gtw-games.org/bug-reports/[/url] 
    Suggestions:        [url=http://forum.gtw-games.org/mta-servers-development/]http://forum.gtw-games.org/mta-servers-development/[/url] 
     
    Version:        Open source 
    License:        GPL v.3 or later 
    Status:         Stable release 
******************************************************************************** 
]]-- 
  
-- Setup data base 
db_pc = dbConnect("sqlite", "bans.db") 
  
-- Tables for quick access 
police_chiefs_data  = { } 
banned_cops_data    = { } 
currentCount = getTickCount () 
  
--[[ Create a database table to store bans data ]]-- 
addEventHandler("onResourceStart", resourceRoot, 
function()   
    dbExec(db_pc, "CREATE TABLE IF NOT EXISTS bans (ID INTEGER PRIMARY KEY, account TEXT)") 
    dbExec(db_pc, "CREATE TABLE IF NOT EXISTS police_chiefs (ID INTEGER PRIMARY KEY, account TEXT)") 
     
    -- Load database into tables 
    dbQuery(load_banned_cops, db_pc, "SELECT account FROM bans ") 
    dbQuery(load_police_chiefs, db_pc, "SELECT account FROM police_chiefs ") 
end) 
  
--[[ Load banned cops ]]-- 
function load_banned_cops(query) 
    local result = dbPoll( query, 0 ) 
    if not result then return end 
    for _,row in pairs( result ) do 
        banned_cops_data[row["account"]] = true 
    end 
end 
  
--[[ Load police chiefs ]]-- 
function load_police_chiefs(query) 
    local result = dbPoll( query, 0 ) 
    if not result then return end 
    for _,row in pairs( result ) do 
        police_chiefs_data[row["account"]] = true 
    end 
end 
  
--[[ Administrators and moderators can give a player police chief rights ]]-- 
function toggle_police_chief(admin, cmd, account_to_add_or_remove) 
    -- Get the account of the administrator or moderator using this command 
    local accName = getAccountName(getPlayerAccount(admin)) 
     
    -- Check if the command issuer has the rights 
    if not isObjectInACLGroup ("user."..accName, aclGetGroup ("Admin")) and 
        not isObjectInACLGroup ("user."..accName, aclGetGroup ("Moderator")) then return end 
         
    -- Check if there is an account provided 
    if not account_to_add_or_remove then  
        outputChatBox("Correct syntax: /addpc ", admin, 255, 0, 0) 
        return  
    end 
     
    -- Check if the provided account exist 
    local current_chief = getAccount(account_to_add_or_remove) 
    if not current_chief then return end 
     
    -- Check if we shall add or remove this player 
    if cmd == "addpc" then 
        -- Add police chief to database 
        police_chiefs_data[account_to_add_or_remove] = true 
        dbExec(db_pc, "INSERT INTO police_chiefs VALUES (NULL,?)", account_to_add_or_remove) 
        outputChatBox("Player: "..getPlayerName(current_chief).." was successfully added as police chief", admin, 0, 200, 0) 
    else 
        -- Remove police chief from database 
        police_chiefs_data[account_to_add_or_remove] = false 
        dbExec(db_pc, "DELETE FROM police_chiefs WHERE account=?", account_to_add_or_remove) 
        outputChatBox("Player: "..getPlayerName(current_chief).." was removed from police chief", admin, 255, 200, 0) 
    end 
end 
addCommandHandler("addpc", toggle_police_chief) 
addCommandHandler("removepc", toggle_police_chief) 
  
--[[ Police chiefs can ban from law at unlimited time ]]-- 
function add_law_ban(police_chief, cmd, bad_officer) 
    -- Check if an officer to kick was provided 
    if not bad_officer then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Check if the provided cop account exist 
    local cop_to_ban = getAccount(bad_officer) 
    local cop_to_ban_plr = getAccountPlayer(cop_to_ban) 
    if not cop_to_ban then 
        outputChatBox("Correct syntax: /lawban ", police_chief, 255, 0, 0) 
        return 
    end 
    
    -- Notify the cop if online 
    if cop_to_ban_plr then 
        exports.GTWtopbar:dm("You have been kicked from the force by: "..getPlayerName(police_chief), cop_to_ban_plr, 255, 0, 0) 
        
        -- Reset job and team if online 
        setPlayerTeam(cop_to_ban_plr, getTeamFromName("Unemployed")) 
        setPlayerNametagColor(cop_to_ban_plr, 255, 255, 0) 
        setElementData(cop_to_ban_plr, "admin",false) 
        local skinID = exports.GTWclothes:getBoughtSkin(cop_to_ban_plr) 
        setElementModel(cop_to_ban_plr, skinID) 
        setElementData(cop_to_ban_plr, "Occupation", "") 
        
        local ac = getPlayerAccount ( cop_to_ban_plr ); 
        if ( not isGuestAccount ( cop_to_ban_plr ) ) then 
            setElementData ( ac, "lockedFromPolice", getTickCount ( ) + 5*60*1000 ); 
        end 
    end 
    
    -- Notify the police chief issuing the command 
    outputChatBox("Police: "..bad_officer.." was kicked from the police job", police_chief, 255, 100, 0) 
  
end 
addCommandHandler("banfromlaw", add_law_ban) 
addCommandHandler("lawban", add_law_ban) 
  
  
  
  
--[[ Police chiefs can revoke law bans ]]-- 
function revoke_law_ban(police_chief, cmd, bad_officer) 
    -- Check if an officer to kick was provided 
    if not bad_officer then  
        outputChatBox("Correct syntax: /revokelawban ", police_chief, 255, 0, 0) 
        return  
    end 
     
    -- Check if the provided cop account exist 
    local cop_to_ban = getAccount(bad_officer) 
    local cop_to_ban_plr = getAccountPlayer(cop_to_ban) 
    if not cop_to_ban then 
        outputChatBox("Correct syntax: /revokelawban ", police_chief, 255, 0, 0) 
        return  
    end 
     
    -- Notify the cop if online 
    if cop_to_ban_plr then 
        exports.GTWtopbar:dm("You are now allowed to work as a cop again, (thanks to: "..getPlayerName(police_chief)..")", cop_to_ban_plr, 0, 255, 0) 
    end 
     
    -- Notify the police chief issuing the command 
    outputChatBox("Police: "..bad_officer.." is now allowed to work again", police_chief, 255, 100, 0) 
             
    -- Remove ban from database 
    dbExec(db_pc, "DELETE FROM bans WHERE account=?", bad_officer) 
    banned_cops_data[bad_officer] = false 
end 
addCommandHandler("revokebanfromlaw", revoke_law_ban) 
addCommandHandler("revokelawban", revoke_law_ban) 
  
--[[ List banned cops ]]-- 
function list_banned_cops(plr) 
    local list = "" 
    for k,v in pairs(banned_cops_data) do 
        local name = nil 
        if getAccountPlayer(getAccount(k)) then 
            name = getPlayerName(getAccountPlayer(getAccount(k))) 
            if name then k = k.." ("..name..")" end 
        end 
        list = list..k..", " 
    end 
    outputChatBox("Lawbans: "..list, plr, 200, 200, 200) 
end 
addCommandHandler("listlawbans", list_banned_cops) 
addCommandHandler("listlawban", list_banned_cops) 
  
--[[ List police chiefs ]]-- 
function list_police_chiefs(plr) 
    local list = "" 
    for k,v in pairs(police_chiefs_data) do 
        local name = nil 
        if getAccountPlayer(getAccount(k)) then 
            name = getPlayerName(getAccountPlayer(getAccount(k))) 
            if name then k = k.." ("..name..")" end 
        end 
        list = list..k..", " 
    end 
    outputChatBox("Police chiefs: "..list, plr, 200, 200, 200) 
end 
addCommandHandler("listpolicechiefs", list_police_chiefs) 
addCommandHandler("listpolicechief", list_police_chiefs) 
  
--[[ Exported: check if a player is a police chief ]]-- 
function isPoliceChief(plr) 
    if not plr or not getPlayerAccount(plr) or not getAccountName(getPlayerAccount(plr)) then return false end 
    return police_chiefs_data[getAccountName(getPlayerAccount(plr))] or false 
end 
  
--[[ Exported: check if a player is a banned from law ]]-- 
function isLawBanned(plr) 
    if not plr or not getPlayerAccount(plr) or not getAccountName(getPlayerAccount(plr)) then return false end 
    return banned_cops_data[getAccountName(getPlayerAccount(plr))] or false 
end 
  

its GTW so I think you know that already, uhm I could still take the job and no debugs

Link to comment

Run this and let me know the result, replace client with any player element that is logged into an account that is currently banned from law.

local is_law_banned = exports.GTWpolicechief:isLawBanned(client) 
if is_law_banned then  
    outputChatBox("True")  
else  
    outputChatBox("False")  
end 

Link to comment

"that is currently banned from law."

I don't quit get where's an Element being banned other than " banned_cops_data[bad_officer] = false" which is bad_officer, and when I use it, it doesn't even work no debugs too.

in Police chief script too there is an error @ this line

setElementData ( ac, "lockedFromPolice", getTickCount ( ) + 5*60*1000 ); "Bad Argument expected element at argument 1"

Link to comment

There are built in commands for that. "/lawban " and "/revokelawban ". After that you can use: "/listlawbans" to verify that a real account was added to the list successfully, only policechiefs can add or remove lawbans and only server administrators can add or remove police chiefs using "/addpc " and "/removepc ". To check if you successfully added a police chief you can list all police chiefs by using: "/listpolicechiefs". All these commands works as soon the resource is started without other requirements. Check that first then run the above code.

Link to comment

My guess is that the bug is in your other resource named "GRGPlayerFunctions", either that or you're not using the police chief system correctly. There is no bugs in the police chief system, if it was it wouldn't work on other servers either, try to download the latest version if you're unsure then add yourself as policechief, ban someone and finally run this:

local is_law_banned = exports.GTWpolicechief:isLawBanned(client) 
if is_law_banned then  
    outputChatBox("True")  
else  
    outputChatBox("False")  
end 

And post the result. Don't forget to replace "client" with a player element who's account is currently law banned.

Link to comment

It's easier to use as a command obviously so why not,

function check_if_banned(plr, cmd) 
    local is_law_banned = exports.GTWpolicechief:isLawBanned(plr) 
    if is_law_banned then  
        outputChatBox("True", plr)  
    else  
        outputChatBox("False", plr)  
    end 
end 
addCommandHandler("checkmyban", check_if_banned) 

Run the code in any resource except GTWpolicechief (as it has exported calls). The command is "/checkmyban" and will validate the player using the command, this should be running server side.

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