forked from stevoscriptsteam/stevo_citizenship
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mri-Qbox-Brasil/dev
Reestruturação da Whitelist
- Loading branch information
Showing
13 changed files
with
1,140 additions
and
188 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
ColorScheme = GlobalState.UIColors or {} | ||
Config = {} | ||
local examCompleted = false | ||
|
||
local function shuffleData(t) | ||
local shuffled = {} | ||
for i = #t, 1, -1 do | ||
local rand = math.random(i) | ||
t[i], t[rand] = t[rand], t[i] | ||
table.insert(shuffled, t[i]) | ||
end | ||
return shuffled | ||
end | ||
|
||
local function showDialog(type, data) | ||
if type == "alert" then | ||
return lib.alertDialog(data) == "confirm" | ||
else | ||
return lib.inputDialog(data) | ||
end | ||
end | ||
|
||
local function showAlertDialog(header, content, cancel, confirmLabel, cancelLabel) | ||
local data = { | ||
header = header, | ||
content = content, | ||
cancel = cancel or false, | ||
centered = true, | ||
labels = { | ||
confirm = confirmLabel or "Confirmar", | ||
cancel = cancelLabel or "Cancelar" | ||
} | ||
} | ||
return showDialog("alert", data) | ||
end | ||
|
||
local function askQuestion(question) | ||
local options = {} | ||
options[#options + 1] = { | ||
type = "select", | ||
options = shuffleData(question.options) | ||
} | ||
local input = lib.inputDialog(question.question, options) | ||
if not input then | ||
for k, v in pairs(options[1].options) do | ||
if v.value then | ||
return false | ||
end | ||
return false | ||
end | ||
else | ||
return input[1] | ||
end | ||
end | ||
|
||
local function teleportPlayer(player, coords) | ||
DoScreenFadeOut(800) | ||
Wait(800) | ||
SetEntityCoords(player, coords.x, coords.y, coords.z) | ||
SetEntityHeading(player, coords.h) | ||
DoScreenFadeIn(1000) | ||
end | ||
|
||
local function beginExam() | ||
local correctAnswers = 0 | ||
local ped = PlayerPedId() | ||
if ped then | ||
if not showAlertDialog(Config.StartExamHeader, Config.StartExamContent, true, "Iniciar") then | ||
return | ||
end | ||
|
||
local score = 0 | ||
local questions = shuffleData(Config.Questions) | ||
for _, question in ipairs(questions) do | ||
correctAnswers = correctAnswers + (askQuestion(question) and 1 or 0) | ||
end | ||
local anwserPercentage = ((100 * correctAnswers) / #Config.Questions) | ||
if anwserPercentage >= Config.Percent then | ||
showAlertDialog(Config.SuccessHeader, Config.SuccessContent, false, "Jogar") | ||
lib.callback.await("mri_Qwhitelist:addCitizenship", false) | ||
examCompleted = true | ||
Zone:Remove() | ||
teleportPlayer(ped, Config.CompletionCoords) | ||
else | ||
showAlertDialog(Config.FailedHeader, Config.FailedContent, false, "Entendi") | ||
end | ||
end | ||
end | ||
|
||
local function escapeCitizenship() | ||
teleportPlayer(cache.ped, Config.SpawnCoords) | ||
lib.notify({description = Config.escapeNotify, type = "error"}) | ||
end | ||
|
||
function loadCitizenship() | ||
teleportPlayer(cache.ped, Config.SpawnCoords) | ||
|
||
if Config.Interaction.Type == "marker" then | ||
Marker:LoadInteractions({callbackFunction = beginExam}) | ||
elseif Config.Interaction.Type == "target" then | ||
Target:LoadInteractions({callbackFunction = beginExam}) | ||
elseif Config.Interaction.Type == "3dtext" then | ||
Text:LoadInteractions({callbackFunction = beginExam}) | ||
end | ||
|
||
local zoneData = { | ||
name = "citizenZone", | ||
coords = Config.citizenZone.coords, | ||
size = Config.citizenZone.size, | ||
rotation = Config.citizenZone.rotation, | ||
debug = true, | ||
onExit = escapeCitizenship | ||
} | ||
|
||
Zone:Load({type = "box", zoneData = zoneData}) | ||
lib.notify({description = Config.loadNotify, type = "info"}) | ||
end | ||
|
||
local function OnPlayerLoaded() | ||
Config = lib.callback.await("mri_Qwhitelist:getConfig", false) | ||
if not lib.callback.await("mri_Qwhitelist:checkCitizenship", false) then | ||
if Config.Enabled then | ||
loadCitizenship() | ||
end | ||
end | ||
end | ||
|
||
AddEventHandler( | ||
"onResourceStart", | ||
function(resourceName) | ||
if (GetCurrentResourceName() ~= resourceName) then | ||
return | ||
end | ||
OnPlayerLoaded() | ||
end | ||
) | ||
|
||
RegisterNetEvent( | ||
"QBCore:Client:OnPlayerLoaded", | ||
function() | ||
OnPlayerLoaded() | ||
end | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
fx_version "cerulean" | ||
game "gta5" | ||
lua54 "yes" | ||
use_experimental_fxv2_oal "yes" | ||
|
||
author "StevoScripts | steve" | ||
description "REPO_DESCRIPTION" | ||
author "MRI QBOX Team" | ||
version "MRIQBOX_VERSION" | ||
|
||
ox_lib "locale" | ||
|
||
shared_scripts { | ||
'@ox_lib/init.lua', | ||
'config.lua', | ||
"@ox_lib/init.lua", | ||
} | ||
|
||
client_scripts { | ||
'resource/client.lua', | ||
'resource/interactions/**.lua', | ||
server_scripts { | ||
"@oxmysql/lib/MySQL.lua", | ||
"server/*.lua" | ||
} | ||
|
||
server_scripts { | ||
'@oxmysql/lib/MySQL.lua', | ||
'resource/server.lua', | ||
client_scripts { | ||
"interactions/*.lua", | ||
"client/*.lua" | ||
} | ||
|
||
dependencies { | ||
'ox_lib', | ||
'oxmysql', | ||
'/server:4500', | ||
"ox_lib", | ||
"oxmysql", | ||
"/server:4500" | ||
} | ||
|
||
lua54 "yes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Marker = { | ||
LoadInteractions = function(self, data) | ||
if Config.Interaction.Type ~= "marker" then | ||
return | ||
end | ||
|
||
local point = | ||
lib.points.new( | ||
{ | ||
coords = Config.ExamCoords, | ||
distance = 8 | ||
} | ||
) | ||
|
||
function point:nearby() | ||
DrawMarker( | ||
Config.Interaction.MarkerType, | ||
Config.ExamCoords.x, | ||
Config.ExamCoords.y, | ||
Config.ExamCoords.z - (Config.Interaction.MarkerOnFloor and 1.3 or 0.0), | ||
0.0, | ||
0.0, | ||
0.0, | ||
0.0, | ||
0.0, | ||
0.0, | ||
Config.Interaction.MarkerSize.x, | ||
Config.Interaction.MarkerSize.y, | ||
Config.Interaction.MarkerSize.z, | ||
Config.Interaction.MarkerColor.r, | ||
Config.Interaction.MarkerColor.g, | ||
Config.Interaction.MarkerColor.b, | ||
200, | ||
false, | ||
true, | ||
2.0, | ||
false, | ||
false, | ||
false, | ||
false | ||
) | ||
|
||
local onScreen, _x, _y = | ||
World3dToScreen2d(Config.ExamCoords.x, Config.ExamCoords.y, Config.ExamCoords.z + 1) | ||
if onScreen then | ||
SetTextScale(0.4, 0.4) | ||
SetTextFont(4) | ||
SetTextProportional(1) | ||
SetTextColour(255, 255, 255, 255) | ||
SetTextOutline() | ||
SetTextEntry("STRING") | ||
SetTextCentre(true) | ||
AddTextComponentString("[~b~E~w~] " .. Config.Interaction.MarkerLabel .. "") | ||
DrawText(_x, _y) | ||
end | ||
|
||
if self.currentDistance < 3 and IsControlJustReleased(0, 38) then | ||
data.callbackFunction() | ||
end | ||
end | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Target = { | ||
TargetId = nil, | ||
LoadInteractions = function(self, data) | ||
if Config.Interaction.Type ~= "target" then | ||
return | ||
end | ||
local options = { | ||
{ | ||
name = "mri_Qwhitelist:targetExam", | ||
onSelect = data.callbackFunction, | ||
icon = Config.Interaction.TargetIcon, | ||
label = Config.Interaction.TargetLabel, | ||
distance = Config.Interaction.TargetDistance, | ||
}, | ||
} | ||
Target.TargetId = | ||
exports.ox_target:addBoxZone( | ||
{ | ||
coords = Config.ExamCoords, | ||
size = Config.Interaction.TargetRadius, | ||
rotation = 45, | ||
options = options | ||
} | ||
) | ||
end | ||
} | ||
|
||
AddEventHandler( | ||
"onResourceStop", | ||
function(resource) | ||
if resource == GetCurrentResourceName() then | ||
exports.ox_target:removeZone(Target.TargetId) | ||
end | ||
end | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Text = { | ||
LoadInteractions = function(self, data) | ||
if Config.Interaction.Type ~= "3dtext" then | ||
return | ||
end | ||
|
||
local point = | ||
lib.points.new( | ||
{ | ||
coords = Config.ExamCoords, | ||
distance = 8 | ||
} | ||
) | ||
|
||
function point:nearby() | ||
local onScreen, _x, _y = | ||
World3dToScreen2d(Config.ExamCoords.x, Config.ExamCoords.y, Config.ExamCoords.z + 1) | ||
if onScreen then | ||
SetTextScale(0.4, 0.4) | ||
SetTextFont(4) | ||
SetTextProportional(1) | ||
SetTextColour(255, 255, 255, 255) | ||
SetTextOutline() | ||
SetTextEntry("STRING") | ||
SetTextCentre(true) | ||
AddTextComponentString("[~b~E~w~] " .. Config.Interaction.MarkerLabel .. "") | ||
DrawText(_x, _y) | ||
end | ||
if self.currentDistance < 3 and IsControlJustReleased(0, 38) then | ||
data.callbackFunction() | ||
end | ||
end | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Zone = { | ||
Zone = nil, | ||
Load = function(self, data) | ||
if data.type == "box" then | ||
Zone.Zone = lib.zones.box(data.zoneData) | ||
end | ||
end, | ||
Remove = function(self) | ||
if Zone.Zone then | ||
Zone.Zone:remove() | ||
Zone.Zone = nil | ||
end | ||
end | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.