update(feat): Multi-Language Support

chore(coding-style): Fix Indentation
This commit is contained in:
nearbyplayer
2017-09-21 12:23:36 -04:00
parent 072ef503b2
commit 4c7e767a1d
11 changed files with 633 additions and 386 deletions
+218 -223
View File
@@ -1,13 +1,13 @@
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
ESX = nil
@@ -27,29 +27,29 @@ local IsAboveSpeedLimit = false
local LastVehicleHealth = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function DrawMissionText(msg, time)
ClearPrints()
SetTextEntry_2('STRING')
AddTextComponentString(msg)
DrawSubtitleTimed(time, 1)
SetTextEntry_2('STRING')
AddTextComponentString(msg)
DrawSubtitleTimed(time, 1)
end
function StartTheoryTest()
CurrentTest = 'theory'
CurrentTest = 'theory'
SendNUIMessage({
openQuestion = true
openQuestion = true
})
ESX.SetTimeout(200, function()
SetNuiFocus(true, true)
SetNuiFocus(true, true)
end)
TriggerServerEvent('esx_dmvschool:pay', Config.Prices['dmv'])
@@ -57,20 +57,20 @@ function StartTheoryTest()
end
function StopTheoryTest(success)
CurrentTest = nil
CurrentTest = nil
SendNUIMessage({
openQuestion = false
openQuestion = false
})
SetNuiFocus(false)
if success then
TriggerServerEvent('esx_dmvschool:addLicense', 'dmv')
ESX.ShowNotification('Vous avez ~g~réussi~s~ le test')
TriggerServerEvent('esx_dmvschool:addLicense', 'dmv')
ESX.ShowNotification(_U('passed_test'))
else
ESX.ShowNotification('Vous avez ~r~raté~s~ le test')
ESX.ShowNotification(_U('failed_test'))
end
end
@@ -78,33 +78,31 @@ end
function StartDriveTest(type)
ESX.Game.SpawnVehicle(Config.VehicleModels[type], Config.Zones.VehicleSpawnPoint.Pos, 317.0, function(vehicle)
CurrentTest = 'drive'
CurrentTestType = type
CurrentCheckPoint = 0
ESX.Game.SpawnVehicle(Config.VehicleModels[type], Config.Zones.VehicleSpawnPoint.Pos, 317.0, function(vehicle)
CurrentTest = 'drive'
CurrentTestType = type
CurrentCheckPoint = 0
LastCheckPoint = -1
CurrentZoneType = 'residence'
DriveErrors = 0
IsAboveSpeedLimit = false
CurrentVehicle = vehicle
LastVehicleHealth = GetEntityHealth(vehicle)
local playerPed = GetPlayerPed(-1)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end)
CurrentZoneType = 'residence'
DriveErrors = 0
IsAboveSpeedLimit = false
CurrentVehicle = vehicle
LastVehicleHealth = GetEntityHealth(vehicle)
local playerPed = GetPlayerPed(-1)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end)
TriggerServerEvent('esx_dmvschool:pay', Config.Prices[type])
TriggerServerEvent('esx_dmvschool:pay', Config.Prices[type])
end
function StopDriveTest(success)
if success then
TriggerServerEvent('esx_dmvschool:addLicense', CurrentTestType)
ESX.ShowNotification('Vous avez ~g~réussi~s~ le test')
TriggerServerEvent('esx_dmvschool:addLicense', CurrentTestType)
ESX.ShowNotification(_U('passed_test'))
else
ESX.ShowNotification('Vous avez ~r~raté~s~ le test')
ESX.ShowNotification(_U('failed_test'))
end
CurrentTest = nil
@@ -113,77 +111,77 @@ function StopDriveTest(success)
end
function SetCurrentZoneType(type)
CurrentZoneType = type
CurrentZoneType = type
end
function OpenDMVSchoolMenu()
local ownedLicenses = {}
local ownedLicenses = {}
for i=1, #Licenses, 1 do
ownedLicenses[Licenses[i].type] = true
end
for i=1, #Licenses, 1 do
ownedLicenses[Licenses[i].type] = true
end
local elements = {}
local elements = {}
if not ownedLicenses['dmv'] then
table.insert(elements, {label = 'Examen du code $' .. Config.Prices['dmv'], value = 'theory_test'})
end
if not ownedLicenses['dmv'] then
table.insert(elements, {label = _U('theory_test') .. Config.Prices['dmv'], value = 'theory_test'})
end
if ownedLicenses['dmv'] then
if ownedLicenses['dmv'] then
if not ownedLicenses['drive'] then
table.insert(elements, {label = 'Examen de conduite [voiture] $' .. Config.Prices['drive'], value = 'drive_test', type = 'drive'})
end
if not ownedLicenses['drive'] then
table.insert(elements, {label = _U('road_test_car') .. Config.Prices['drive'], value = 'drive_test', type = 'drive'})
end
if not ownedLicenses['drive_bike'] then
table.insert(elements, {label = 'Examen de conduite [moto] $' .. Config.Prices['drive_bike'], value = 'drive_test', type = 'drive_bike'})
end
if not ownedLicenses['drive_bike'] then
table.insert(elements, {label = _U('road_test_bike') .. Config.Prices['drive_bike'], value = 'drive_test', type = 'drive_bike'})
end
if not ownedLicenses['drive_truck'] then
table.insert(elements, {label = 'Examen de conduite [camion] $' .. Config.Prices['drive_truck'], value = 'drive_test', type = 'drive_truck'})
end
if not ownedLicenses['drive_truck'] then
table.insert(elements, {label = _U('road_test_truck') .. Config.Prices['drive_truck'], value = 'drive_test', type = 'drive_truck'})
end
end
end
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'dmvschool_actions',
{
title = 'Ecole de conduite',
elements = elements
},
function(data, menu)
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'dmvschool_actions',
{
title = _U('driving_school'),
elements = elements
},
function(data, menu)
if data.current.value == 'theory_test' then
menu.close()
StartTheoryTest()
end
if data.current.value == 'theory_test' then
menu.close()
StartTheoryTest()
end
if data.current.value == 'drive_test' then
menu.close()
StartDriveTest(data.current.type)
end
if data.current.value == 'drive_test' then
menu.close()
StartDriveTest(data.current.type)
end
end,
function(data, menu)
end,
function(data, menu)
menu.close()
menu.close()
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = 'Appuyez sur ~INPUT_CONTEXT~ pour ouvrir le menu'
CurrentActionData = {}
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = _U('press_open_menu')
CurrentActionData = {}
end
)
end
)
end
RegisterNUICallback('question', function(data, cb)
SendNUIMessage({
openSection = 'question'
openSection = 'question'
})
cb('OK')
@@ -201,88 +199,88 @@ end)
AddEventHandler('esx_dmvschool:hasEnteredMarker', function(zone)
if zone == 'DMVSchool' then
if zone == 'DMVSchool' then
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = 'Appuyez sur ~INPUT_CONTEXT~ pour ouvrir le menu'
CurrentActionData = {}
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = _U('press_open_menu')
CurrentActionData = {}
end
end
end)
AddEventHandler('esx_dmvschool:hasExitedMarker', function(zone)
CurrentAction = nil
ESX.UI.Menu.CloseAll()
CurrentAction = nil
ESX.UI.Menu.CloseAll()
end)
RegisterNetEvent('esx_dmvschool:loadLicenses')
AddEventHandler('esx_dmvschool:loadLicenses', function(licenses)
Licenses = licenses
Licenses = licenses
end)
-- Create Blips
Citizen.CreateThread(function()
local blip = AddBlipForCoord(Config.Zones.DMVSchool.Pos.x, Config.Zones.DMVSchool.Pos.y, Config.Zones.DMVSchool.Pos.z)
local blip = AddBlipForCoord(Config.Zones.DMVSchool.Pos.x, Config.Zones.DMVSchool.Pos.y, Config.Zones.DMVSchool.Pos.z)
SetBlipSprite (blip, 408)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2)
SetBlipAsShortRange(blip, true)
SetBlipSprite (blip, 408)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Auto-école")
EndTextCommandSetBlipName(blip)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('driving_school_blip'))
EndTextCommandSetBlipName(blip)
end)
-- Display markers
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local coords = GetEntityCoords(GetPlayerPed(-1))
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
local currentZone = nil
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_dmvschool:hasEnteredMarker', currentZone)
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_dmvschool:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_dmvschool:hasExitedMarker', LastZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_dmvschool:hasExitedMarker', LastZone)
end
end
end
end)
-- Block UI
@@ -300,7 +298,7 @@ Citizen.CreateThread(function()
DisablePlayerFiring(playerPed, true) -- Disable weapon firing
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
end
end
@@ -308,147 +306,144 @@ end)
-- Key Controls
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
if CurrentAction ~= nil then
if CurrentAction ~= nil then
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlJustReleased(0, Keys['E']) then
if IsControlJustReleased(0, Keys['E']) then
if CurrentAction == 'dmvschool_menu' then
OpenDMVSchoolMenu()
end
if CurrentAction == 'dmvschool_menu' then
OpenDMVSchoolMenu()
end
CurrentAction = nil
CurrentAction = nil
end
end
end
end
end
end
end)
-- Drive test
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
if CurrentTest == 'drive' then
if CurrentTest == 'drive' then
local playerPed = GetPlayerPed(-1)
local coords = GetEntityCoords(playerPed)
local nextCheckPoint = CurrentCheckPoint + 1
local playerPed = GetPlayerPed(-1)
local coords = GetEntityCoords(playerPed)
local nextCheckPoint = CurrentCheckPoint + 1
if Config.CheckPoints[nextCheckPoint] == nil then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
if Config.CheckPoints[nextCheckPoint] == nil then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
CurrentTest = nil
CurrentTest = nil
ESX.ShowNotification('Test de conduite terminé')
ESX.ShowNotification(_U('driving_test_complete'))
if DriveErrors < Config.MaxErrors then
StopDriveTest(true)
else
StopDriveTest(false)
end
else
if DriveErrors < Config.MaxErrors then
StopDriveTest(true)
else
StopDriveTest(false)
end
else
if CurrentCheckPoint ~= LastCheckPoint then
if CurrentCheckPoint ~= LastCheckPoint then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
CurrentBlip = AddBlipForCoord(Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z)
SetBlipRoute(CurrentBlip, 1)
CurrentBlip = AddBlipForCoord(Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z)
SetBlipRoute(CurrentBlip, 1)
LastCheckPoint = CurrentCheckPoint
LastCheckPoint = CurrentCheckPoint
end
end
local distance = GetDistanceBetweenCoords(coords, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, true)
local distance = GetDistanceBetweenCoords(coords, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, true)
if distance <= 100.0 then
DrawMarker(1, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 1.5, 1.5, 1.5, 102, 204, 102, 100, false, true, 2, false, false, false, false)
end
if distance <= 100.0 then
DrawMarker(1, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 1.5, 1.5, 1.5, 102, 204, 102, 100, false, true, 2, false, false, false, false)
end
if distance <= 3.0 then
Config.CheckPoints[nextCheckPoint].Action(playerPed, CurrentVehicle, SetCurrentZoneType)
CurrentCheckPoint = CurrentCheckPoint + 1
end
if distance <= 3.0 then
Config.CheckPoints[nextCheckPoint].Action(playerPed, CurrentVehicle, SetCurrentZoneType)
CurrentCheckPoint = CurrentCheckPoint + 1
end
end
end
end
end
end
end
end)
-- Speed / Damage control
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
if CurrentTest == 'drive' then
if CurrentTest == 'drive' then
local playerPed = GetPlayerPed(-1)
local playerPed = GetPlayerPed(-1)
if IsPedInAnyVehicle(playerPed, false) then
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
local tooMuchSpeed = false
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
local tooMuchSpeed = false
for k,v in pairs(Config.SpeedLimits) do
if CurrentZoneType == k and speed > v then
for k,v in pairs(Config.SpeedLimits) do
if CurrentZoneType == k and speed > v then
tooMuchSpeed = true
tooMuchSpeed = true
if not IsAboveSpeedLimit then
if not IsAboveSpeedLimit then
DriveErrors = DriveErrors + 1
IsAboveSpeedLimit = true
DriveErrors = DriveErrors + 1
IsAboveSpeedLimit = true
ESX.ShowNotification('Vous roulez trop vite, vitesse limite : ~y~' .. v .. 'km/h')
ESX.ShowNotification('Erreurs : ~r~' .. DriveErrors .. '~s~/' .. Config.MaxErrors)
ESX.ShowNotification(_U('driving_too_fast') .. v .. 'km/h')
ESX.ShowNotification(_U('errors') .. DriveErrors .. '~s~/' .. Config.MaxErrors)
end
end
end
end
end
end
if not tooMuchSpeed then
IsAboveSpeedLimit = false
end
if not tooMuchSpeed then
IsAboveSpeedLimit = false
end
local health = GetEntityHealth(vehicle)
local health = GetEntityHealth(vehicle)
if health < LastVehicleHealth then
if health < LastVehicleHealth then
DriveErrors = DriveErrors + 1
DriveErrors = DriveErrors + 1
ESX.ShowNotification('Vous avez endommagé votre véhicule')
ESX.ShowNotification('Erreurs : ~r~' .. DriveErrors .. '~s~/' .. Config.MaxErrors)
LastVehicleHealth = health
ESX.ShowNotification(_U('you_damaged_veh'))
ESX.ShowNotification(_U('errors') .. DriveErrors .. '~s~/' .. Config.MaxErrors)
LastVehicleHealth = health
end
end
end
end
end
end
end
end
end)
end)