mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
Performance improvements, removed keys table
This commit is contained in:
+66
-125
@@ -1,21 +1,6 @@
|
||||
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
|
||||
}
|
||||
|
||||
local Instance = {}
|
||||
local InstanceInvite = nil
|
||||
local InstancedPlayers = {}
|
||||
local RegisteredInstanceTypes = {}
|
||||
local InsideInstance = false
|
||||
ESX = nil
|
||||
local instance, instancedPlayers, registeredInstanceTypes = {}, {}, {}
|
||||
local instanceInvite, insideInstance
|
||||
ESX = nil
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
@@ -25,7 +10,7 @@ Citizen.CreateThread(function()
|
||||
end)
|
||||
|
||||
function GetInstance()
|
||||
return Instance
|
||||
return instance
|
||||
end
|
||||
|
||||
function CreateInstance(type, data)
|
||||
@@ -33,43 +18,42 @@ function CreateInstance(type, data)
|
||||
end
|
||||
|
||||
function CloseInstance()
|
||||
Instance = {}
|
||||
instance = {}
|
||||
TriggerServerEvent('instance:close')
|
||||
InsideInstance = false
|
||||
insideInstance = false
|
||||
end
|
||||
|
||||
function EnterInstance(instance)
|
||||
InsideInstance = true
|
||||
insideInstance = true
|
||||
TriggerServerEvent('instance:enter', instance.host)
|
||||
|
||||
if RegisteredInstanceTypes[instance.type].enter ~= nil then
|
||||
RegisteredInstanceTypes[instance.type].enter(instance)
|
||||
if registeredInstanceTypes[instance.type].enter then
|
||||
registeredInstanceTypes[instance.type].enter(instance)
|
||||
end
|
||||
end
|
||||
|
||||
function LeaveInstance()
|
||||
if Instance.host ~= nil then
|
||||
|
||||
if #Instance.players > 1 then
|
||||
if instance.host then
|
||||
if #instance.players > 1 then
|
||||
ESX.ShowNotification(_U('left_instance'))
|
||||
end
|
||||
|
||||
if RegisteredInstanceTypes[Instance.type].exit ~= nil then
|
||||
RegisteredInstanceTypes[Instance.type].exit(Instance)
|
||||
if registeredInstanceTypes[instance.type].exit then
|
||||
registeredInstanceTypes[instance.type].exit(instance)
|
||||
end
|
||||
|
||||
TriggerServerEvent('instance:leave', Instance.host)
|
||||
TriggerServerEvent('instance:leave', instance.host)
|
||||
end
|
||||
|
||||
InsideInstance = false
|
||||
insideInstance = false
|
||||
end
|
||||
|
||||
function InviteToInstance(type, player, data)
|
||||
TriggerServerEvent('instance:invite', Instance.host, type, player, data)
|
||||
TriggerServerEvent('instance:invite', instance.host, type, player, data)
|
||||
end
|
||||
|
||||
function RegisterInstanceType(type, enter, exit)
|
||||
RegisteredInstanceTypes[type] = {
|
||||
registeredInstanceTypes[type] = {
|
||||
enter = enter,
|
||||
exit = exit
|
||||
}
|
||||
@@ -87,8 +71,8 @@ AddEventHandler('instance:close', function()
|
||||
CloseInstance()
|
||||
end)
|
||||
|
||||
AddEventHandler('instance:enter', function(instance)
|
||||
EnterInstance(instance)
|
||||
AddEventHandler('instance:enter', function(_instance)
|
||||
EnterInstance(_instance)
|
||||
end)
|
||||
|
||||
AddEventHandler('instance:leave', function()
|
||||
@@ -104,157 +88,114 @@ AddEventHandler('instance:registerType', function(name, enter, exit)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onInstancedPlayersData')
|
||||
AddEventHandler('instance:onInstancedPlayersData', function(instancedPlayers)
|
||||
InstancedPlayers = instancedPlayers
|
||||
AddEventHandler('instance:onInstancedPlayersData', function(_instancedPlayers)
|
||||
instancedPlayers = _instancedPlayers
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onCreate')
|
||||
AddEventHandler('instance:onCreate', function(instance)
|
||||
Instance = {}
|
||||
AddEventHandler('instance:onCreate', function(_instance)
|
||||
instance = {}
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onEnter')
|
||||
AddEventHandler('instance:onEnter', function(instance)
|
||||
Instance = instance
|
||||
AddEventHandler('instance:onEnter', function(_instance)
|
||||
instance = _instance
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onLeave')
|
||||
AddEventHandler('instance:onClose', function(instance)
|
||||
Instance = {}
|
||||
AddEventHandler('instance:onLeave', function(_instance)
|
||||
instance = {}
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onClose')
|
||||
AddEventHandler('instance:onClose', function(instance)
|
||||
Instance = {}
|
||||
AddEventHandler('instance:onClose', function(_instance)
|
||||
instance = {}
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onPlayerEntered')
|
||||
AddEventHandler('instance:onPlayerEntered', function(instance, player)
|
||||
Instance = instance
|
||||
AddEventHandler('instance:onPlayerEntered', function(_instance, player)
|
||||
instance = _instance
|
||||
local playerName = GetPlayerName(GetPlayerFromServerId(player))
|
||||
|
||||
ESX.ShowNotification(_('entered_into', playerName))
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onPlayerLeft')
|
||||
AddEventHandler('instance:onPlayerLeft', function(instance, player)
|
||||
Instance = instance
|
||||
AddEventHandler('instance:onPlayerLeft', function(_instance, player)
|
||||
instance = _instance
|
||||
local playerName = GetPlayerName(GetPlayerFromServerId(player))
|
||||
|
||||
ESX.ShowNotification(_('left_out', playerName))
|
||||
end)
|
||||
|
||||
RegisterNetEvent('instance:onInvite')
|
||||
AddEventHandler('instance:onInvite', function(instance, type, data)
|
||||
InstanceInvite = {
|
||||
AddEventHandler('instance:onInvite', function(_instance, type, data)
|
||||
instanceInvite = {
|
||||
type = type,
|
||||
host = instance,
|
||||
host = _instance,
|
||||
data = data
|
||||
}
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
Citizen.Wait(10000)
|
||||
|
||||
if InstanceInvite ~= nil then
|
||||
if instanceInvite then
|
||||
ESX.ShowNotification(_U('invite_expired'))
|
||||
InstanceInvite = nil
|
||||
instanceInvite = nil
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterInstanceType('default')
|
||||
|
||||
-- Input invites
|
||||
-- Controls for invite
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
if InstanceInvite ~= nil then
|
||||
if instanceInvite then
|
||||
ESX.ShowHelpNotification(_U('press_to_enter'))
|
||||
|
||||
if IsControlJustReleased(0, 38) then
|
||||
EnterInstance(instanceInvite)
|
||||
ESX.ShowNotification(_U('entered_instance'))
|
||||
instanceInvite = nil
|
||||
end
|
||||
else
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
-- Controls
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
|
||||
Citizen.Wait(0)
|
||||
|
||||
if InstanceInvite ~= nil and IsControlJustReleased(0, Keys['E']) then
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
EnterInstance(InstanceInvite)
|
||||
ESX.ShowNotification(_U('entered_instance'))
|
||||
InstanceInvite = nil
|
||||
|
||||
elseif InstanceInvite == nil then
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
-- Instance players
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(10)
|
||||
local playerPed = PlayerPedId()
|
||||
local playersToHide = {}
|
||||
|
||||
Citizen.Wait(0)
|
||||
|
||||
if Instance.host ~= nil then
|
||||
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
for i=0, Config.MaxPlayers, 1 do
|
||||
|
||||
local found = false
|
||||
for j=1, #Instance.players, 1 do
|
||||
instancePlayer = GetPlayerFromServerId(Instance.players[j])
|
||||
|
||||
if i == instancePlayer then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
local otherPlayerPed = GetPlayerPed(i)
|
||||
|
||||
SetEntityLocallyInvisible(otherPlayerPed)
|
||||
SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true)
|
||||
end
|
||||
|
||||
if instance.host then
|
||||
-- Get players and sets them as pairs
|
||||
for k,v in ipairs(GetActivePlayers()) do
|
||||
playersToHide[v] = true
|
||||
end
|
||||
|
||||
-- Dont set our instanced players invisible
|
||||
for _,player in ipairs(instance.players) do
|
||||
playersToHide[GetPlayerFromServerId(player)] = nil
|
||||
end
|
||||
else
|
||||
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
for i=0, Config.MaxPlayers, 1 do
|
||||
|
||||
local found = false
|
||||
for j=1, #InstancedPlayers, 1 do
|
||||
instancePlayer = GetPlayerFromServerId(InstancedPlayers[j])
|
||||
|
||||
if i == instancePlayer then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
|
||||
if found then
|
||||
local otherPlayerPed = GetPlayerPed(i)
|
||||
|
||||
SetEntityLocallyInvisible(otherPlayerPed)
|
||||
SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true)
|
||||
end
|
||||
|
||||
for player,_ in pairs(instancedPlayers) do
|
||||
playersToHide[GetPlayerFromServerId(player)] = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Hide all these players
|
||||
for player,_ in pairs(playersToHide) do
|
||||
local otherPlayerPed = GetPlayerPed(player)
|
||||
SetEntityVisible(otherPlayerPed, false, false)
|
||||
SetEntityNoCollisionEntity(playerPed, otherPlayerPed, false)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -267,7 +208,7 @@ Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0) -- must be run every frame
|
||||
|
||||
if InsideInstance then
|
||||
if insideInstance then
|
||||
SetVehicleDensityMultiplierThisFrame(0.0)
|
||||
SetParkedVehicleDensityMultiplierThisFrame(0.0)
|
||||
|
||||
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
Config = {}
|
||||
Config.Locale = 'fr'
|
||||
Config.MaxPlayers = 32
|
||||
Config = {}
|
||||
|
||||
Config.Locale = 'fr'
|
||||
+30
-38
@@ -1,11 +1,11 @@
|
||||
local Instances = {}
|
||||
local instances = {}
|
||||
|
||||
function GetInstancedPlayers()
|
||||
local players = {}
|
||||
|
||||
for k,v in pairs(Instances) do
|
||||
for i=1, #v.players, 1 do
|
||||
table.insert(players, v.players[i])
|
||||
for k,v in pairs(instances) do
|
||||
for k2,v2 in ipairs(v.players) do
|
||||
players[v2] = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,26 +13,26 @@ function GetInstancedPlayers()
|
||||
end
|
||||
|
||||
function CreateInstance(type, player, data)
|
||||
Instances[player] = {
|
||||
instances[player] = {
|
||||
type = type,
|
||||
host = player,
|
||||
players = {},
|
||||
data = data
|
||||
}
|
||||
|
||||
TriggerEvent('instance:onCreate', Instances[player])
|
||||
TriggerClientEvent('instance:onCreate', player, Instances[player])
|
||||
TriggerEvent('instance:onCreate', instances[player])
|
||||
TriggerClientEvent('instance:onCreate', player, instances[player])
|
||||
TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers())
|
||||
end
|
||||
|
||||
function CloseInstance(instance)
|
||||
if Instances[instance] ~= nil then
|
||||
if instances[instance] then
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
TriggerClientEvent('instance:onClose', Instances[instance].players[i])
|
||||
for i=1, #instances[instance].players do
|
||||
TriggerClientEvent('instance:onClose', instances[instance].players[i])
|
||||
end
|
||||
|
||||
Instances[instance] = nil
|
||||
instances[instance] = nil
|
||||
|
||||
TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers())
|
||||
TriggerEvent('instance:onClose', instance)
|
||||
@@ -42,22 +42,22 @@ end
|
||||
function AddPlayerToInstance(instance, player)
|
||||
local found = false
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
if Instances[instance].players[i] == player then
|
||||
for i=1, #instances[instance].players do
|
||||
if instances[instance].players[i] == player then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
table.insert(Instances[instance].players, player)
|
||||
table.insert(instances[instance].players, player)
|
||||
end
|
||||
|
||||
TriggerClientEvent('instance:onEnter', player, Instances[instance])
|
||||
TriggerClientEvent('instance:onEnter', player, instances[instance])
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
if Instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerEntered', Instances[instance].players[i], Instances[instance], player)
|
||||
for i=1, #instances[instance].players do
|
||||
if instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerEntered', instances[instance].players[i], instances[instance], player)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,42 +65,34 @@ function AddPlayerToInstance(instance, player)
|
||||
end
|
||||
|
||||
function RemovePlayerFromInstance(instance, player)
|
||||
if instances[instance] then
|
||||
TriggerClientEvent('instance:onLeave', player, instances[instance])
|
||||
|
||||
if Instances[instance] ~= nil then
|
||||
|
||||
TriggerClientEvent('instance:onLeave', player, Instances[instance])
|
||||
|
||||
if Instances[instance].host == player then
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
if Instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player)
|
||||
if instances[instance].host == player then
|
||||
for i=1, #instances[instance].players do
|
||||
if instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerLeft', instances[instance].players[i], instances[instance], player)
|
||||
end
|
||||
end
|
||||
|
||||
CloseInstance(instance)
|
||||
|
||||
else
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
if Instances[instance].players[i] == player then
|
||||
Instances[instance].players[i] = nil
|
||||
for i=1, #instances[instance].players do
|
||||
if instances[instance].players[i] == player then
|
||||
instances[instance].players[i] = nil
|
||||
end
|
||||
end
|
||||
|
||||
for i=1, #Instances[instance].players, 1 do
|
||||
if Instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player)
|
||||
for i=1, #instances[instance].players do
|
||||
if instances[instance].players[i] ~= player then
|
||||
TriggerClientEvent('instance:onPlayerLeft', instances[instance].players[i], instances[instance], player)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers())
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function InvitePlayerToInstance(instance, type, player, data)
|
||||
|
||||
Reference in New Issue
Block a user