Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #136 from FiveM-Scripts/mysql-patch
Browse files Browse the repository at this point in the history
Mysql patch
  • Loading branch information
ghermans authored Sep 30, 2018
2 parents acb7308 + 9d63ff6 commit 1c464ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.4.2
* Added missing command `CopDept`.

## 1.4.4.2
* A fix has been provided regarding the mysql error `MySQL-async.js:209563: uncaught type error: cannot convert undefined or null object.`
* The vehicles list in the garage will only display vehicles that are assigned to the players department.
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ When you restart your server you will see a mysql error inside your server conso
This is just confirmation that your new database column has been added.

## Commands
* /copadd ID : Add the player as cop to the database.
* /coprem ID : Remove a player from the database.
* /coprank ID Rank : To change the rank of a police officer.
* /copdept ID Department : Add a player to a specific department id.

**You can also use these commands with RCON (`CopAdd` / `CopAddAdmin` / `CopRem` / `CopRank`).
To see how to use them, just type the command you want without any parameter.**
You can use these commands with RCON (`CopAdd` / `CopAddAdmin` / `CopDept`/ `CopRem` / `CopRank`).
To see how to use them, just type the command you want without any parameter.

## Departments
| ID | Name |
Expand Down
4 changes: 2 additions & 2 deletions police/__resource.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource_manifest_version '05cfa83c-a124-4cfa-a768-c24a5811d8f9'
resource_version 'v1.4.5'
resource_versionNum '144'
resource_version '1.4.4.3'
resource_versionNum '1443'
resource_Isdev 'no'

dependency 'mysql-async'
Expand Down
38 changes: 35 additions & 3 deletions police/server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function setDept(source, player,playerDept)
if(result[1].dept ~= playerDept) then
MySQL.Async.execute("UPDATE police SET dept="..playerDept.." WHERE identifier='"..identifier.."'", { ['@identifier'] = identifier})
TriggerClientEvent('chatMessage', source, i18n.translate("title_notification"), {255, 0, 0}, i18n.translate("command_received"))
TriggerClientEvent("police:notify", player, "CHAR_ANDREAS", 1, i18n.translate("title_notification"), false, i18n.translate("new_dept")..config.departments.label[playerDept])
TriggerClientEvent("police:notify", player, "CHAR_ANDREAS", 1, i18n.translate("title_notification"), false, i18n.translate("new_dept") .. " " .. config.departments.label[playerDept])
TriggerClientEvent('police:receiveIsCop', source, result[1].rank, playerDept)
else
TriggerClientEvent('chatMessage', source, i18n.translate("title_notification"), {255, 0, 0}, i18n.translate("same_dept"))
Expand Down Expand Up @@ -352,7 +352,7 @@ RegisterCommand("CopRem", function(source,args,raw)
end, true)

RegisterCommand("CopRank", function(source,args,raw)
if #args ~= 1 and #args ~= 2 then
if #args ~= 2 then
RconPrint("Usage: CopRank [ingame-id] [rank]\n")
CancelEvent()
return
Expand Down Expand Up @@ -382,6 +382,38 @@ RegisterCommand("CopRank", function(source,args,raw)
end
end, true)

RegisterCommand("CopDept", function(source,args,raw)
if #args ~= 2 then
RconPrint("Usage: CopDept [ingame-id] [department]\n")
CancelEvent()
return
else
if(GetPlayerName(tonumber(args[1])) == nil) then
RconPrint("Player is not ingame\n")
CancelEvent()
return
end

local identifier = getPlayerID(tonumber(args[1]))
MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier = @identifier", { ['@identifier'] = identifier}, function (result)
if(result[1]) then
if(GetPlayerName(tonumber(args[1])) ~= nil) then
local player = tonumber(args[1])
local dept = tonumber(args[2])

setDept(args[1], player, dept)
else
TriggerClientEvent('chatMessage', args[1], i18n.translate("title_notification"), {255, 0, 0}, i18n.translate("no_player_with_this_id"))
end
else
TriggerClientEvent('chatMessage', args[1], i18n.translate("title_notification"), {255, 0, 0}, i18n.translate("not_enough_permission"))
end
end)

CancelEvent()
end
end, true)

function getPlayerID(source)
local identifiers = GetPlayerIdentifiers(source)
local player = getIdentifiant(identifiers)
Expand All @@ -392,4 +424,4 @@ function getIdentifiant(id)
for _, v in ipairs(id) do
return v
end
end
end

0 comments on commit 1c464ce

Please sign in to comment.