From d814049c5f8901633aa982da16f8aff94faa9e73 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Sat, 2 Sep 2023 16:42:59 +0200 Subject: [PATCH] Update v1.1 * Fixed OnlineMedics not updating --- VERSION | 2 +- client.lua | 2 +- fxmanifest.lua | 2 +- server.lua | 50 ++++++++++++++++---------------------------------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/VERSION b/VERSION index 9f8e9b6..b123147 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0 \ No newline at end of file +1.1 \ No newline at end of file diff --git a/client.lua b/client.lua index e7421ab..a642d24 100644 --- a/client.lua +++ b/client.lua @@ -1,4 +1,4 @@ -local isDead, OnlineMedics, medicCalled, medicOnRoad, triedToRevive = false, 0, false, false, false +local isDead, OnlineMedics, medicCalled, medicOnRoad, triedToRevive = false, 5, false, false, false local taskVehicle, taskNPC, taskBlip = nil, nil, nil AddEventHandler('esx:onPlayerDeath', function(data) diff --git a/fxmanifest.lua b/fxmanifest.lua index 51c77f7..b979977 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_aimedic' description 'AI Medic NPC' -version '1.0' +version '1.1' lua54 'yes' diff --git a/server.lua b/server.lua index 523aca4..0169b7d 100644 --- a/server.lua +++ b/server.lua @@ -1,8 +1,8 @@ -local OnlineMedics = 0 - -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - local xPlayers = ESX.GetExtendedPlayers() +CreateThread(function() + while true do + local sleep = 10000 + local OnlineMedics = 0 + local xPlayers = ESX.GetExtendedPlayers() for k, xPlayer in pairs(xPlayers) do if isMedic(xPlayer.job.name) then @@ -11,42 +11,24 @@ AddEventHandler('onResourceStart', function(resource) end TriggerClientEvent('msk_aimedic:refreshMedics', -1, OnlineMedics) - end -end) - -RegisterNetEvent('esx:playerLoaded') -AddEventHandler('esx:playerLoaded', function(source, xPlayer, isNew) - local src = source - - if isMedic(xPlayer.job.name) then - OnlineMedics = OnlineMedics + 1 - end - TriggerClientEvent('msk_aimedic:refreshMedics', -1, OnlineMedics) + Wait(sleep) + end end) -RegisterNetEvent('esx:playerLogout') -AddEventHandler('esx:playerLogout', function(source) - local src = source - local xPlayer = ESX.GetPlayerFromId(src) - - if isMedic(xPlayer.job.name) then - OnlineMedics = OnlineMedics - 1 - end - TriggerClientEvent('msk_aimedic:refreshMedics', -1, OnlineMedics) -end) - -RegisterNetEvent('esx:playerDropped') -AddEventHandler('esx:playerDropped', function(playerId, reason) - local src = playerId - local xPlayer = ESX.GetPlayerFromId(src) +ESX.RegisterServerCallback('msk_aimedic:getOnlineMedics', function(source, cb) + local src = source + local OnlineMedics = 0 + local xPlayers = ESX.GetExtendedPlayers() - if isMedic(xPlayer.job.name) then - OnlineMedics = OnlineMedics - 1 + for k, xPlayer in pairs(xPlayers) do + if isMedic(xPlayer.job.name) then + OnlineMedics = OnlineMedics + 1 + end end - TriggerClientEvent('msk_aimedic:refreshMedics', -1, OnlineMedics) + cb(OnlineMedics) end) isMedic = function(playerJob)