Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
feat(config) : Add config to use RP name
Browse files Browse the repository at this point in the history
  • Loading branch information
mahanmoulaei committed Apr 10, 2022
1 parent b18f1f5 commit cd85fba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Config = {}

Config.UseRPName = true

Config.RadioChannelsWithName = {
["0"] = "Admin",
["1"] = "Police",
Expand Down
34 changes: 19 additions & 15 deletions Server/Server.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local PlayersInCurrentRadioChannel = {}

--TODO : Check The Bug In playerDropped Event
AddEventHandler("playerDropped", function()
local src = source

local PlayerState = Player(src).state
local currentRadioChannel = PlayerState.radioChannel
local currentRadioChannel = Player(src).state.radioChannel

local playersInCurrentRadioChannel = CreateFullRadioListOfChannel(currentRadioChannel)
for index, player in pairs(playersInCurrentRadioChannel) do
Expand All @@ -21,8 +20,7 @@ AddEventHandler('pma-voice:setPlayerRadio', function(channelToJoin)
local src = source
local radioChannelToJoin = tonumber(channelToJoin)
if not radioChannelToJoin then print(('radioChannelToJoin was not a number. Got: %s Expected: Number'):format(type(channelToJoin))) return end
local currentRadioChannel = Player(src).state.radioChannel
--print("\n\nCurrent Radio Channel: "..currentRadioChannel.." - To Join Radio Channel: "..radioChannelToJoin)
local currentRadioChannel = Player(src).state.radioChannel
if radioChannelToJoin == 0 then
Disconnect(src, currentRadioChannel)
else
Expand All @@ -35,19 +33,15 @@ function Connect(src, currentRadioChannel, radioChannelToJoin)
Disconnect(src, currentRadioChannel)
end
Wait(1000) -- Wait for pma-voice to finilize setting the player radio channel
--CONNECTING
--print("Connecting [{"..GetPlayerName(src).."} To "..radioChannelToJoin.."]")

local playersInCurrentRadioChannel = CreateFullRadioListOfChannel(radioChannelToJoin)
for index, player in pairs(playersInCurrentRadioChannel) do
--print("Sending "..src.."("..player.Name..") to "..player.Source)
TriggerClientEvent("JolbakLifeRP-RadioList:Client:SyncRadioChannelPlayers", player.Source, src, radioChannelToJoin, playersInCurrentRadioChannel)
end
playersInCurrentRadioChannel = {}
end

function Disconnect(src, currentRadioChannel)
--DISCONNECTING
--print("Diconnecting [{"..GetPlayerName(src).."} From "..currentRadioChannel.."]")
local playersInCurrentRadioChannel = CreateFullRadioListOfChannel(currentRadioChannel)
TriggerClientEvent("JolbakLifeRP-RadioList:Client:SyncRadioChannelPlayers", src, src, 0, playersInCurrentRadioChannel)
for index, player in pairs(playersInCurrentRadioChannel) do
Expand All @@ -61,11 +55,21 @@ function CreateFullRadioListOfChannel(RadioChannel)
for player, isTalking in pairs(playersInRadio) do
playersInRadio[player] = {}
playersInRadio[player].Source = player
playersInRadio[player].Name = GetPlayerName(player)
--print("Inside CreateFullRadioListOfChannel -> RadioChannel: "..RadioChannel)
--print("Inside CreateFullRadioListOfChannel -> Source: "..player)
--print("Inside CreateFullRadioListOfChannel -> Name: "..GetPlayerName(player))
--print("--------------------------------------------------------------------------------")

local name

if Config.UseRPName then
local xPlayer = ESX.GetPlayerFromId(player)
if xPlayer then
name = xPlayer.getName()
else --extra check to make sure player sends a name to client
name = GetPlayerName(player)
end
else
name = GetPlayerName(player)
end

playersInRadio[player].Name = name
end

return playersInRadio
Expand Down
8 changes: 4 additions & 4 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
fx_version 'cerulean'
game 'gta5'

name 'JL-RadioList'
description 'List of players in each radio for pma-voice'
name 'JLRP-RadioList'
author 'Mahan#8183'
description 'JolbakLifeRP Radio List : List of players in each radio for pma-voice'

shared_scripts {
'@es_extended/imports.lua',
'Config.lua',
}

ui_page "UI/index.html"
ui_page "ui/index.html"

files {
"UI/index.html"
"ui/index.html"
}

server_script {
Expand Down

0 comments on commit cd85fba

Please sign in to comment.