Add files via upload

This commit is contained in:
Andyyy7666
2022-07-08 23:18:25 +02:00
committed by GitHub
parent 3ff2e7967a
commit d5d3b85d1a
8 changed files with 417 additions and 95 deletions

View File

@@ -1,5 +1,5 @@
config = {
maxJailTime = 10, -- Max time in seconds that someone can jail another player.
maxJailTime = 300, -- Max time in seconds that someone can jail another player.
jailDistance = 90.0, -- How far can the player go from the Jail coordinates. If the player is further than the set amount they will be teleported back.
jailCoords = {x = 1680.21, y = 2513.25, z = 44.56, h = 6.53},
@@ -7,9 +7,9 @@ config = {
-- Where can players access it from.
accessLocation = {
{x = -449.61, y = 6012.42, z = 31.72}, -- Paleto Bay Sheriff's Office
{x = 1853.08, y = 3690.2, z = 34.27}, -- Sandy Shores Sheriff's Office
{x = 459.84, y = -989.15, z = 24.91}, -- Mission Row PD
{x = -450.17, y = 6012.62, z = 31.71}, -- Paleto Bay Sheriff's Office
{x = 1853.57, y = 3690.74, z = 34.26}, -- Sandy Shores Sheriff's Office
{x = 460.53, y = -988.84, z = 24.91} -- Mission Row PD
},
-- Departments that can access the jail tablet.
@@ -20,5 +20,5 @@ config = {
},
-- How close does the player have to be to the coordiantes to be able to open the tablet.
accessDistance = 0.5,
accessDistance = 1.2,
}

View File

@@ -1,3 +1,3 @@
server_config = {
discordWebhook = "",
}
}

View File

@@ -1,25 +1,23 @@
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
version "1.2"
description "Jail tablet"
author "Andyyy#7666"
description "ND Framework Jailing"
version "2.0.0"
fx_version "cerulean"
game "gta5"
lua54 "yes"
ui_page "source/ui/index.html"
files {
"source/ui/index.html",
"source/ui/js/jquery-3.6.0.min.js",
"source/ui/js/listener.js",
"source/ui/script.js",
"source/ui/style.css"
}
ui_page "source/ui/index.html"
shared_script "config_client.lua"
server_scripts {
"source/server.lua",
"config_server.lua"
}
client_script "source/client.lua"
server_scripts {
"config_server.lua",
"source/server.lua"
}

View File

@@ -1,5 +1,7 @@
local display = false
local isJailed = false
local nearJailingUi = false
local jailTime = 0
local ped
function SetDisplay(bool)
display = bool
@@ -10,59 +12,186 @@ function SetDisplay(bool)
})
end
function alert(msg)
BeginTextCommandDisplayHelp("STRING")
AddTextComponentSubstringPlayerName(msg)
EndTextCommandDisplayHelp(0, 0, 1, -1)
function text(text, x, y, scale)
SetTextFont(4)
SetTextProportional(0)
SetTextScale(scale, scale)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow(0, 0, 0, 0,255)
SetTextOutline()
SetTextJustification(0)
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x, y)
end
function drawText3D(coords, text)
local onScreen, _x, _y = World3dToScreen2d(coords.x, coords.y, coords.z + 0.3)
local pX, pY, pZ = table.unpack(GetGameplayCamCoords())
SetTextScale(0.4, 0.4)
SetTextFont(4)
SetTextProportional(1)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextColour(255, 255, 255, 255)
SetTextOutline()
AddTextComponentString(text)
DrawText(_x, _y)
end
function hasAccess()
local selectedDepartment = exports["ND_Core"]:getCharacterInfo().department
for _, department in pairs(config.accessDepartments) do
if department == selectedDepartment then
return true
end
end
return false
end
function inRange(ped)
local pedCoords = GetEntityCoords(ped)
for locations in pairs(config.accessLocation) do
local uiCoords = vector3(config.accessLocation[locations].x, config.accessLocation[locations].y, config.accessLocation[locations].z)
if (#(pedCoords - uiCoords)) < config.accessDistance then
if hasAccess() then
return uiCoords
end
end
end
return false
end
local tablet = false
function ToggleTablet(toggle)
if toggle and not tablet then
tablet = true
Citizen.CreateThread(function()
RequestAnimDict("amb@code_human_in_bus_passenger_idles@female@tablet@base")
while not HasAnimDictLoaded("amb@code_human_in_bus_passenger_idles@female@tablet@base") do
Citizen.Wait(150)
end
RequestModel(`prop_cs_tablet`)
while not HasModelLoaded(`prop_cs_tablet`) do
Citizen.Wait(150)
end
local playerPed = PlayerPedId()
local tabletObj = CreateObject(`prop_cs_tablet`, 0.0, 0.0, 0.0, true, true, false)
local tabletBoneIndex = GetPedBoneIndex(playerPed, 60309)
SetCurrentPedWeapon(playerPed, `weapon_unarmed`, true)
AttachEntityToEntity(tabletObj, playerPed, tabletBoneIndex, 0.03, 0.002, -0.0, 10.0, 160.0, 0.0, true, false, false, false, 2, true)
SetModelAsNoLongerNeeded(`prop_cs_tablet`)
while tablet do
Citizen.Wait(100)
playerPed = PlayerPedId()
if not IsEntityPlayingAnim(playerPed, "amb@code_human_in_bus_passenger_idles@female@tablet@base", "base", 3) then
TaskPlayAnim(playerPed, "amb@code_human_in_bus_passenger_idles@female@tablet@base", "base", 3.0, 3.0, -1, 49, 0, 0, 0, 0)
end
end
ClearPedSecondaryTask(playerPed)
Citizen.Wait(450)
DetachEntity(tabletObj, true, false)
DeleteEntity(tabletObj)
end)
elseif not toggle and tablet then
tablet = false
end
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
ped = PlayerPedId()
nearJailingUi = inRange(ped)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not display and nearJailingUi then
drawText3D(nearJailingUi, "~w~Press ~b~E ~w~to open the jail ui")
if IsControlJustPressed(0, 51) then
TriggerServerEvent("ND_Jailing:getPlayers")
end
end
end
end)
-- Return list of all players on the server and open ui.
RegisterNetEvent("ND_Jailing:returnPlayers")
AddEventHandler("ND_Jailing:returnPlayers", function(players)
for _, player in pairs(players) do
SendNUIMessage({
type = "players",
players = player,
})
end
SetDisplay(true)
ToggleTablet(display)
end)
AddEventHandler("playerSpawned", function()
TriggerServerEvent("ND_Jailing:getJailTime")
end)
function jail(time)
local player = PlayerPedId()
local pedCoords = GetEntityCoords(player)
jailTime = time
SetEntityCoords(player, config.jailCoords.x, config.jailCoords.y, config.jailCoords.z, false, false, false, false)
SetEntityHeading(player, config.jailCoords.h)
TriggerEvent("ND_Jailing:timeLeft")
TriggerServerEvent("ND_Jailing:updateJailing", jailTime)
while jailTime > 0 do
jailTime = jailTime -1
player = PlayerPedId()
if #(GetEntityCoords(player) - vector3(config.jailCoords.x, config.jailCoords.y, config.jailCoords.z)) > config.jailDistance then
SetEntityCoords(player, config.jailCoords.x, config.jailCoords.y, config.jailCoords.z, false, false, false, false)
end
Citizen.Wait(1000)
end
SetEntityCoords(player, config.releaseCoords.x, config.releaseCoords.y, config.releaseCoords.z, false, false, false, false)
SetEntityHeading(player, config.releaseCoords.h)
TriggerServerEvent("ND_Jailing:updateJailing", jailTime)
end
RegisterNetEvent("ND_Jailing:timeLeft")
AddEventHandler("ND_Jailing:timeLeft", function()
while jailTime > 0 do
Citizen.Wait(0)
text("Time until release: " .. tostring(jailTime), 0.5, 0.9, 0.5)
end
end)
-- Jail a player and loop to keep them in jail every second.
RegisterNetEvent("ND_Jailing:jailPlayer")
AddEventHandler("ND_Jailing:jailPlayer", function(time)
local player = PlayerPedId()
isJailed = true
SetEntityCoords(player, config.jailCoords.x, config.jailCoords.y, config.jailCoords.z, false, false, false, false)
SetEntityHeading(player, config.jailCoords.h)
jail(time)
end)
while isJailed do
time = time -1
local pedCoords = GetEntityCoords(player)
if #(pedCoords - vector3(config.jailCoords.x, config.jailCoords.y, config.jailCoords.z)) > config.jailDistance then
SetEntityCoords(player, config.jailCoords.x, config.jailCoords.y, config.jailCoords.z, false, false, false, false)
end
if time == 0 then
SetEntityCoords(player, config.releaseCoords.x, config.releaseCoords.y, config.releaseCoords.z, false, false, false, false)
SetEntityHeading(player, config.releaseCoords.h)
Citizen.Wait(100)
TaskGoStraightToCoord(player, config.releaseCoords.x + 10, config.releaseCoords.y, config.releaseCoords.z, 1.0, 8000, config.releaseCoords.h, 0)
isJailed = false
end
Citizen.Wait(1000)
end
RegisterNetEvent("ND_Jailing:unjailPlayer")
AddEventHandler("ND_Jailing:unjailPlayer", function(time)
jailTime = 0
end)
-- Chat suggestion for command.
TriggerEvent("chat:addSuggestion", "/jail", "Jail a player", {
{name="Id", help="Player Id"},
{name="time", help="time to jail (seconds)"},
{name="Reason", help="Short reason or list of charges."}
{name="Time", help="Time to jail (seconds)"},
{name="Fine", help="How much will the player be fined?"},
{name="Reason", help="Short description of the charge."}
})
-- Same jail function but with a command.
RegisterCommand("jail", function(source, args, rawCommand)
local id = tonumber(args[1])
local time = tonumber(args[2])
local reason = args[3]
local hasAccess = false
for _, dept in pairs(config.accessDepartments) do
if exports["ND_Core"]:getCharacterInfo(6) == dept then
hasAccess = true
break
end
end
if hasAccess then
local name = GetPlayerName(GetPlayerFromServerId(id))
local fine = args[3]
local reason = args[4]
if hasAccess() then
if not GetPlayerFromServerId(id) then
TriggerEvent("chat:addMessage", {
color = { 255, 0, 0},
@@ -76,7 +205,7 @@ RegisterCommand("jail", function(source, args, rawCommand)
args = {"[Error]", "max time to jail is: " .. config.maxJailTime .. " seconds."}
})
elseif time <= config.maxJailTime then
TriggerServerEvent("jailPlayer", id, name, time, reason)
TriggerServerEvent("ND_Jailing:jailPlayer", id, time, fine, reason)
SetDisplay(false)
end
else
@@ -88,46 +217,12 @@ RegisterCommand("jail", function(source, args, rawCommand)
end
end, false)
-- Return list of all players on the server and open ui.
RegisterNetEvent("ND_Jailing:returnPlayers")
AddEventHandler("ND_Jailing:returnPlayers", function(players)
for _, player in pairs(players) do
SendNUIMessage({
type = "players",
players = player,
})
end
SetDisplay(true)
end)
-- Check permission and distance of player.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local pedCoords = GetEntityCoords(PlayerPedId())
for locations in pairs(config.accessLocation) do
if #(pedCoords - vector3(config.accessLocation[locations].x, config.accessLocation[locations].y, config.accessLocation[locations].z)) < config.accessDistance then
for _, dept in pairs(config.accessDepartments) do
if exports["ND_Core"]:getCharacterInfo(6) == dept then
if not display then
alert("Press ~INPUT_CONTEXT~ to open the jail ui")
end
if IsControlJustPressed(1, 51) then
TriggerServerEvent("ND_Jailing:getPlayers")
end
end
end
end
end
end
end)
-- When form is submitted.
RegisterNUICallback("sumbit", function(data)
local id = tonumber(string.sub(data.id, 2, string.find(data.id, ")") - 1))
local time = tonumber(data.time)
local fine = data.fine
local reason = data.reason
local name = GetPlayerName(GetPlayerFromServerId(id))
if time > config.maxJailTime then
SendNUIMessage({
error = "Error: max time to jail is: " .. config.maxJailTime .. " seconds."
@@ -137,15 +232,17 @@ RegisterNUICallback("sumbit", function(data)
error = ""
})
else
TriggerServerEvent("ND_Jailing:jailPlayer", id, name, time, reason)
TriggerServerEvent("ND_Jailing:jailPlayer", id, time, fine, reason)
SendNUIMessage({
type = "clean"
})
SetDisplay(false)
ToggleTablet(display)
end
end)
-- Close ui.
RegisterNUICallback("closeUI", function(data)
RegisterNUICallback("close", function(data)
SetDisplay(false)
ToggleTablet(display)
end)

View File

@@ -1,3 +1,18 @@
local jailedPlayers = {}
-- Get player any identifier, available types: steam, license, xbl, ip, discord, live.
function GetPlayerIdentifierFromType(type, source)
local identifierCount = GetNumPlayerIdentifiers(source)
for count = 0, identifierCount do
local identifier = GetPlayerIdentifier(source, count)
if identifier and string.find(identifier, type) then
return identifier
end
end
return nil
end
-- send discord embed with webhook.
function sendToDiscord(name, message, color)
local embed = {
{
@@ -15,25 +30,36 @@ end
-- Jail player discord log, trigger the even on the players client and send a message to everyone.
RegisterNetEvent("ND_Jailing:jailPlayer")
AddEventHandler("ND_Jailing:jailPlayer", function(id, name, time, reason)
AddEventHandler("ND_Jailing:jailPlayer", function(id, time, fine, reason)
local player = source
local players = exports["ND_Core"]:getCharacterTable()
local dept = players[player].dept
for _, department in pairs(config.accessDepartments) do
print(department)
if department == dept then
jailedPlayers[GetPlayerIdentifierFromType("license", id)] = time
exports["ND_Core"]:deductMoney(fine, id, "bank")
TriggerClientEvent("ND_Jailing:jailPlayer", id, time)
sendToDiscord("Jail Logs", "**" .. GetPlayerName(source) .. "** Jailed **" .. name .. "** for **" .. time .. " seconds** with the reason: **" .. reason .. "**.", 1595381)
sendToDiscord("Jail Logs", "**" .. GetPlayerName(player) .. "** Jailed **" .. GetPlayerName(id) .. "** for **" .. time .. " seconds** with the reason: **" .. reason .. "**.", 1595381)
TriggerClientEvent('chat:addMessage', -1, {
color = { 255, 0, 0},
multiline = true,
args = {"[Judge]", name .. " was charaged with " .. reason .. " and will be spending " .. time .. " months in jail."}
args = {"[Judge]", GetPlayerName(id) .. " was charaged with " .. reason .. " and will be spending " .. time .. " months in jail."}
})
break
end
end
end)
RegisterNetEvent("ND_Jailing:updateJailing")
AddEventHandler("ND_Jailing:updateJailing", function(time)
local player = source
if time == 0 then
jailedPlayers[GetPlayerIdentifierFromType("license", player)] = nil
else
jailedPlayers[GetPlayerIdentifierFromType("license", player)] = time
end
end)
-- Gets all players on the server and adds them to a table.
RegisterNetEvent("ND_Jailing:getPlayers")
AddEventHandler("ND_Jailing:getPlayers", function()
@@ -43,3 +69,12 @@ AddEventHandler("ND_Jailing:getPlayers", function()
end
TriggerClientEvent("ND_Jailing:returnPlayers", source, players)
end)
RegisterNetEvent("ND_Jailing:getJailTime")
AddEventHandler("ND_Jailing:getJailTime", function()
local player = source
local time = jailedPlayers[GetPlayerIdentifierFromType("license", player)]
if time then
TriggerClientEvent("ND_Jailing:jailPlayer", player, time)
end
end)

View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<form id="overlay">
<p id="title">Jailing Interface</p>
<hr id="line">
<div class="infoBox">
<label class="text" for="playerid">Player id</label>
<select id="id" class="input" name="Player" style="width: 96%; height: 3vh;" required>
</select>
<label class="text" for="jailtime">Time</label>
<input id="time" class="input" type="number" placeholder="In seconds" name="jailtime" min="10" required>
<label class="text" for="fine">Fine</label>
<input id="fine" class="input" type="number" placeholder="In seconds" name="fine" max="" required>
<label class="text" for="reason">Reason</label>
<input id="reason" class="input" type="text" placeholder="short reason" name="reason" required>
</div>
<hr id="line" style="position: absolute; margin: auto; left: 0; right: 0; bottom: 15%;">
<p id="error"></p>
<button class="resetButton" type="reset">Close</button>
<button class="submitButton" type="submit" form="overlay">Jail</button>
</form>
</body>
</html>

View File

@@ -0,0 +1,61 @@
$(document).ready(function() {
function display(bool) {
if (bool) {
$("#overlay").fadeIn("slow");
} else {
$("#overlay").fadeOut("slow");
}
}
display(false);
window.addEventListener('message', function(event) {
var item = event.data;
if (item.type === "ui") {
if (item.status == true) {
display(true);
} else {
display(false);
}
}
$("#error").text(item.error);
if (item.type === "players") {
$("#id").append($("<option>", {
text: item.players
}));
}
if (item.type === "clean") {
$("#id, #time, #reason").val("");
}
})
$("#overlay").submit(function() {
let id = $("#id").val();
let time = $("#time").val();
let fine = $("#fine").val();
let reason = $("#reason").val();
$.post(`https://${GetParentResourceName()}/sumbit`, JSON.stringify({
id: id,
time: time,
fine: fine,
reason: reason
}));
return false;
})
$(".resetButton").click(function() {
$.post(`https://${GetParentResourceName()}/close`);
$("#id, #time, #reason").val("");
return;
})
document.onkeyup = function(data) {
if (data.which == 27) {
$.post(`https://${GetParentResourceName()}/close`);
$("#id, #time, #reason").val("");
return;
}
};
});

View File

@@ -0,0 +1,98 @@
#overlay {
display: none;
position: absolute;
margin: auto;
inset: 0;
height: 45vh;
width: 38vw;
background-color: rgba(2, 2, 2, 0.911);
border-radius: 25px;
}
#title {
margin-left: 4%;
color: white;
font-size: 120%;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: bold;
}
#line {
background: rgb(255, 255, 255);
background: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(255,255,255,1) 15%, rgba(255,255,255,1) 85%, rgba(0, 0, 0, 0) 100%);
height: 0.1vh;
width: 95%;
border: none;
border-radius: 2vh;
}
.infoBox {
position: absolute;
margin: auto;
left: 4%;
}
.text {
color: white;
display: inline-block;
margin: 1vh 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: bold;
}
.input {
background: white;
color: black;
display: inline-block;
border: none;
border-radius: 5px;
height: 2.5vh;
width: 95%;
outline: none;
padding: 0.5%;
}
.submitButton {
position: absolute;
left: 4%;
width: 45%;
background-color: rgb(17, 113, 238);
}
.resetButton {
position: absolute;
right: 4%;
width: 45%;
background-color: rgb(231, 50, 50);
}
.submitButton, .resetButton {
bottom: 2.5vh;
height: 3vh;
color: white;
font-weight: bold;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
border: none;
border-radius: 1vh;
transition: 0.3s;
}
.submitButton:hover, .resetButton:hover {
transition: 0.3s;
opacity: 0.7;
}
.submitButton:active, .resetButton:active {
transition: none;
opacity: 1;
}
#error {
position: absolute;
margin: auto;
bottom: 18%;
right: 0;
left: 0;
text-align: center;
color: white;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: bold;
}