# RD MDT

{% embed url="<https://www.youtube.com/watch?v=CS7uIbcVarE>" %}

## Step 1 - Propertys&#x20;

### For QB-Houses

If you use qb-houses you can simply add the following to the bottom of qb-houses/server/main.lua.

```lua
function GetHouses()
    return Config.Houses
end
exports("GetHouses", GetHouses)
```

### Custom Script

If you use a custom script you can set it up in RD\_mdt/server/utils.lua in the function called GetPersonPropertys starting on line 70.

The value returned by the function need to be in the following format.

```lua
return {
    {
        house = (a identifier for the house),
        coords = (Coords the house for setting waypoint),
        label = (House address),
    },
}
```

You can always view the default version for qb-houses to see how it should be formatted or ask in my discord.

## Step 2 - pma-voice

### Only need to do this if you want to us our system for detecting what unit is available for a 911 call

Add the following to the bottom pma-voice/server/module/phone.lua.

```lua
exports("getPlayerCall", function(source)
    return voiceData[source].call
end)
```

### If you don't use pma-voice

You can then setup the InCall function in RD\_mdt/server/utils.lua starting on line 3. This simply needs to return true if someone is in a call and false if they are not.

## Step 3 - Security Cameras

### For QB-Policejob

Add the following to the bottom of qb-policejob/client/camera.lua.

```lua
function GetCameras()
    local cameras = {}
    local cCameras = Config.SecurityCameras.cameras
    for i, c in pairs(cCameras) do
        table.insert(cameras, {
            id = i,
            coords = c.coords,
        })
    end
    return cameras
end
exports("GetCameras", GetCameras)
```

### Custom script

If you use another script for police job you can modify the GetSecurityCameras in RD\_mdt/client/utils.lua starting on line 7.

Needs to return the cameras in the following format.

```lua
return {
    {
        id = id,
        coords = coords,
    },
}
```

The id variable needs to be a unik identifier that you can use to open the camera. It will be the value of the camid variable in the ConnectToCamera function in RD\_mdt/client/utils.lua starting on line 11. The coords variable in simply the camera location that will be used to display the camera on the map.

## Step 4 - 911 system

### For QB-Phone

Add the following code to qb-phone/html/js/phone.js at line 141.

```javascript
if(InputNum == "911"){
        $.post('https://qb-phone/call911', JSON.stringify({
            ContactData: [],
            Anonymous: QB.Phone.Data.AnonymousCall,
        }), function(info){
            let status = info.status
            let cData = info.cData
            if (cData.number !== QB.Phone.Data.PlayerData.charinfo.phone) {
                if (status.IsOnline) {
                    if (status.CanCall) {
                        if (!status.InCall) {
                            $(".phone-call-outgoing").css({"display":"block"});
                            $(".phone-call-incoming").css({"display":"none"});
                            $(".phone-call-ongoing").css({"display":"none"});
                            $(".phone-call-outgoing-caller").html(cData.name);
                            QB.Phone.Functions.HeaderTextColor("white", 400);
                            QB.Phone.Animations.TopSlideUp('.phone-application-container', 400, -160);
                            setTimeout(function(){
                                $(".phone-app").css({"display":"none"});
                                QB.Phone.Animations.TopSlideDown('.phone-application-container', 400, 0);
                                QB.Phone.Functions.ToggleApp("phone-call", "block");
                            }, 450);
    
                            CallData.name = cData.name;
                            CallData.number = cData.number;
    
                            QB.Phone.Data.currentApplication = "phone-call";
                        } else {
                            QB.Phone.Notifications.Add("fas fa-phone", "Phone", "You're already in a call!");
                        }
                    } else {
                        QB.Phone.Notifications.Add("fas fa-phone", "Phone", "This person is busy!");
                    }
                } else {
                    QB.Phone.Notifications.Add("fas fa-phone", "Phone", "This person is not available!");
                }
            } else {
                QB.Phone.Notifications.Add("fas fa-phone", "Phone", "You can't call yourself!");
            }
        });
        return;
    }
```

Add the following code to qb-phone/client/main.lua.

```lua
RegisterNUICallback("call911", function(__, cb)
    QBCore.Functions.TriggerCallback("RDM:callback:getavailable911", function(number)
        local data = {
            ContactData = {
                number = number,
                name = number,
            },
            Anonymous = false,
        }
        QBCore.Functions.TriggerCallback('qb-phone:server:GetCallState', function(CanCall, IsOnline, _)
            local status = {
                CanCall = CanCall,
                IsOnline = IsOnline,
                InCall = PhoneData.CallData.InCall,
            }
            cb({status = status, cData = data.ContactData})
            if CanCall and not status.InCall and (data.ContactData.number ~= PhoneData.PlayerData.charinfo.phone) then
                CallContact(data.ContactData, data.Anonymous)
            end
        end, data.ContactData)
    end)
end)
```

### Custom script

To setup this for a custom script you have to call the callback "RDM:callback:getavailable911" and it will return the available number, that you can then use to call the person.

## Step 5 - Radio Script

### For qb-radio

```
function GetMyChannel()
    return RadioChannel
end
exports("GetMyChannel", GetMyChannel)
```

### Custom Script

You need to create a client export in your radio  script that returns the radio channel you are on. Prob ably will be similar to qb-radio for most scripts

## Step 6 (Optional) - PS-Dispatch

Add the following to line 23 in ps-dispatch/server/sv\_main.lua:

```lua
exports["RD_mdt"]:AddPSDispatchCall(data)
```
