Skip to content

Commit

Permalink
Update v1.1
Browse files Browse the repository at this point in the history
* Fixed OnlineMedics not updating
  • Loading branch information
Musiker15 committed Sep 2, 2023
1 parent e7442bf commit d814049
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0
1.1
2 changes: 1 addition & 1 deletion client.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
50 changes: 16 additions & 34 deletions server.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d814049

Please sign in to comment.