[HELP] Police Database (MDT2) not working

I only get one error relating to the script which comes in F8 menu only once when i join the server, no other errors even when pressing “9”, the button which is supposed to open it.

The error i get is this

This is the whole line of code where the error is

Citizen.CreateThread(function()

while true do

    Citizen.Wait(0)

    local playerPed = PlayerPedId()

    local playerVeh = GetVehiclePedIsIn(playerPed, false)

    if not isVisible and IsPedInAnyPoliceVehicle(playerPed) and IsControlJustPressed(0, 311) and GetEntitySpeed(playerVeh) < 10.0 then

        if GetVehicleNumberPlateText(getVehicleInFront()) then

            TriggerServerEvent("mdt:performVehicleSearchInFront", GetVehicleNumberPlateText(getVehicleInFront()))

        end

    elseif IsControlJustPressed(0, 163) then

        TriggerServerEvent("mdt:hotKeyOpen")

    end

elseif not IsPedInAnyPoliceVehicle(playerPed) and not IsPauseMenuActive() then

    TriggerServerEvent("mdt:hotKeyOpen")

end

if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)

    SetPedUsingActionMode(playerPed, -1, -1, 1)

end

end)

and this is what it looks like in visual code studio

I really can´t figure this out, i would really appreciate if someone helped out. Thank you in advance.

Your “while” loop needs an “end”, just like the error says.
You have “elseif” where “end” should be. Not sure how you wanted this to work.
If you put an end above that line and replace the “elseif” with “if” these 2 if statements at the end will never run because the while loop is infinite.
So the whole things needs to be rewritten. I really am not sure what you were trying to do, but I took a guess and did my best, based on what I think you may have wanted.

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		local playerPed = PlayerPedId()
		local playerVeh = GetVehiclePedIsIn(playerPed, false)
		if not isVisible and IsPedInAnyPoliceVehicle(playerPed) and IsControlJustPressed(0, 311) and GetEntitySpeed(playerVeh) < 10.0 then
			if GetVehicleNumberPlateText(getVehicleInFront()) then
				TriggerServerEvent("mdt:performVehicleSearchInFront", GetVehicleNumberPlateText(getVehicleInFront()))
			end
		end
		if IsControlJustPressed(0, 163) and IsPedInAnyPoliceVehicle(playerPed) and not IsPauseMenuActive() then
			TriggerServerEvent("mdt:hotKeyOpen")
		end
		if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)
			SetPedUsingActionMode(playerPed, -1, -1, 1)
		end
	end
end)

Now i don´t get the error in F8 but i get a new error in txadmin console and it´s.

[ script:mysql-async] [MySQL] [WARNING] [mdt2] [173ms] SELECT firstname, lastname FROM users WHERE identifier = ? : [“steam:11000011c23b118”]

What does this mean. And do you know how i could fix.

And only when connecting to the server, but the menu is still not opening

That’s not an error, it’s a warning. Likely because it’s taking 173ms to execute that SQL query, which is slow enough to trigger a server console message, but not slow enough to cause problems. If it’s still not opening, it’s something else doing it. And I wouldn’t be able to help you without more information.

I found something that could really help, but i don´t know what im doing wrong.

Here is a clip where first im trying to open it (its exactly the code you wrote), then i quickly add the line that was missing from your code

if not IsPedInAnyPoliceVehicle(playerPed) and not IsPauseMenuActive() then

TriggerServerEvent("mdt:hotKeyOpen")

end

and restart the script, what happens after that is my screen starts flashing with the police database (mdt2), even though i didn´t even press the button to open it, then i ofc put the code to what yours was and restart the script and then the flashing stops.

So no literal errors, but then i checked my TXAdmin and its full of these two warnings

[ script:mysql-async] [MySQL] [WARNING] [mdt2] [336ms] SELECT firstname, lastname FROM users WHERE identifier = ? : [“steam:11000011c23b118”]
[ script:mysql-async] [MySQL] [WARNING] [mdt2] [463ms] SELECT * FROM (SELECT * FROM mdt_warrants ORDER BY id DESC LIMIT 3) sub ORDER BY id DESC : []

And here is the whole line of how i put the missing line of code

Citizen.CreateThread(function()

while true do

    Citizen.Wait(0)

    local playerPed = PlayerPedId()

    local playerVeh = GetVehiclePedIsIn(playerPed, false)

    if not isVisible and IsPedInAnyPoliceVehicle(playerPed) and IsControlJustPressed(0, 311) and GetEntitySpeed(playerVeh) < 10.0 then

        if GetVehicleNumberPlateText(getVehicleInFront()) then

            TriggerServerEvent("mdt:performVehicleSearchInFront", GetVehicleNumberPlateText(getVehicleInFront()))

        end

    end

    if IsControlJustPressed(0, 163) and IsPedInAnyPoliceVehicle(playerPed) and not IsPauseMenuActive() then

        TriggerServerEvent("mdt:hotKeyOpen")

    end

    if not IsPedInAnyPoliceVehicle(playerPed) and not IsPauseMenuActive() then

    TriggerServerEvent("mdt:hotKeyOpen")

    end

    if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)

        SetPedUsingActionMode(playerPed, -1, -1, 1)

    end

end

end)

If you want more info just tell me and thank you for helping this far!

The code you said was missing and you put back in, wasn’t missing.
By you adding that, you are telling the script to open the MDT, every frame, if you are not in a police vehicle and not in the pause menu. So it’s opening over and over and over, every frame.
I didn’t remove that code, I moved it to the key press check. So when pressing the key, it checks if you are in a police vehicle and not paused. It might not be opening when you are testing it, because you aren’t in a police vehicle. Like I said, I couldn’t tell how you wanted it to function, because the code made no sense. So if you don’t care about being in a police vehicle, you can remove that native all together. Not sure why it was there at all in that case. So try this;

CreateThread(function()
	while true do
		Wait(0)
		local playerPed = PlayerPedId()
		if not isVisible and not IsPauseMenuActive() then
			if IsControlJustPressed(0, 311)  and IsPedInAnyPoliceVehicle(playerPed) and GetEntitySpeed(GetVehiclePedIsIn(playerPed, false)) < 10.0 then
				local plate = GetVehicleNumberPlateText(getVehicleInFront())
				if plate then
					TriggerServerEvent("mdt:performVehicleSearchInFront", plate)
				end
			end
			if IsControlJustPressed(0, 163) then
				TriggerServerEvent("mdt:hotKeyOpen")
			end
		end
		if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)
			SetPedUsingActionMode(playerPed, -1, -1, 1)
		end
	end
end)

This allows you to auto search the plate of the vehicle in front of you, if you are in a police vehicle at low speed and pressing K, or open the MDT at any time when pressing 9, on foot or in a vehicle. Is that what you wanted?

Thank you so much for helping me this far, it works now but closing it doesn´t work and it gets no errors do you know what that could possibly be?

this is the only line what i found searching “close” in all the files of mdt2

RegisterNUICallback(“close”, function(data, cb)

local playerPed = PlayerPedId()

DeleteEntity(tabletObject)

ClearPedTasks(playerPed)

tabletObject = nil

ToggleGUI(false)

cb('ok')

end)

it was in the cl_mdt.lua too

here is a clip of it not closing

im pressing the “Sulje” button with my mouse which is the button that should close it but nothing happens

Please share the code for the “mdt:hotKeyOpen” event.
I suspect that it toggles open and closed and is just poorly named.
In which case it should be an easy fix. But I need to see it to know.

RegisterServerEvent(“mdt:hotKeyOpen”)

AddEventHandler(“mdt:hotKeyOpen”, function()

local usource = source

local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.job.name == 'police' or xPlayer.job.name == 'sheriff' or xPlayer.job.name == 'krp' then

    MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM mdt_reports ORDER BY id DESC LIMIT 3) sub ORDER BY id DESC", {}, function(reports)

        for r = 1, #reports do

            reports[r].charges = json.decode(reports[r].charges)

        end

        MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM mdt_warrants ORDER BY id DESC LIMIT 3) sub ORDER BY id DESC", {}, function(warrants)

            for w = 1, #warrants do

                warrants[w].charges = json.decode(warrants[w].charges)

            end

            local officer = GetCharacterName(usource)

            TriggerClientEvent('mdt:toggleVisibilty', usource, reports, warrants, officer)

        end)

    end)

end

end)

and this is found in sv_mdt.lua

CreateThread(function()
	while true do
		Wait(0)
		local playerPed = PlayerPedId()
		if not IsPauseMenuActive() then
			if IsControlJustPressed(0, 311) and not isVisible and IsPedInAnyPoliceVehicle(playerPed) and GetEntitySpeed(GetVehiclePedIsIn(playerPed, false)) < 10.0 then
				local plate = GetVehicleNumberPlateText(getVehicleInFront())
				if plate then
					TriggerServerEvent("mdt:performVehicleSearchInFront", plate)
				end
			end
			if IsControlJustPressed(0, 163) then
				TriggerServerEvent("mdt:hotKeyOpen")
			end
		end
		if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)
			SetPedUsingActionMode(playerPed, -1, -1, 1)
		end
	end
end)

I meant that it worked, it opened but the close button doesn´t work. The close button is not supposed to be on keyboard but in that clip before you can see me try to close with the “sulje” button, and the code of closing is there two. But thank you for helping so much!

Oh and i found new lines from script.js that might be useful

this

closeMDT() {

        $.post('http://mdt/close', JSON.stringify({}));

    },

    OffenderSearch() {

        if (this.offender_search) {

            this.offender_results.query = this.offender_search;

            $.post('http://mdt/performOffenderSearch', JSON.stringify({

                query: this.offender_search

            }));

            this.offender_results.results = false;

            return;

        }

    },

and this

document.onkeydown = function (data) {

if (data.which == 27 || data.which == 112) { // ESC or F1

    $.post('http://mdt/close', JSON.stringify({}));

} else if (data.which == 13) { // enter

    /* stop enter key from crashing MDT in an input?  */

    var textarea = document.getElementsByTagName('textarea');

    if (!$(textarea).is(':focus')) {

        return false;

    }

}

};

Please share the code for the “ToggleGUI” function.
Also, when posting code, wrap them in 3 backticks above and below.
You can also put the language it is after the first 3 backticks to show syntax highlighting, etc.
Makes it WAY easier for people to read and avoids the forum replacing quotes with different characters.

Like this;

```lua
function Example()
print(“See?”)
end
```

That becomes;

function Example()
    print("See?")
end

Same for Javascript;

```javascript
function Example() {
console.log(“See?”)
}
```

That becomes;

function Example() {
    console.log("See?")
}

It took me a little long to respond because i wasn´t home but here is the ToggleGUI function

function ToggleGUI(explicit_status)

if explicit_status ~= nil then

isVisible = explicit_status

else

isVisible = not isVisible

end

SetNuiFocus(isVisible, isVisible)

SendNUIMessage({

type = "enable",

isVisible = isVisible

})

end

Have you figured it out yet, or have you even seen my last message (above this one where the ToggleGUI function is). But i can’t thank you enough for how much you have helped me and taught me

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.