Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options and config export #61

Merged
merged 7 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions fivem_script/tokovoip_script/__resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@ ui_page "nui/index.html"
files({
"nui/index.html",
"nui/script.js",
})

export "setPlayerData"
export "getPlayerData"
export "refreshAllPlayerData"
export "addPlayerToRadio"
export "removePlayerFromRadio"
export "clientRequestUpdateChannels"
export "isPlayerInChannel"
})
23 changes: 22 additions & 1 deletion fivem_script/tokovoip_script/c_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ TokoVoipConfig = {
keySwitchChannels = Keys["Z"], -- Keybind used to switch the radio channels
keySwitchChannelsSecondary = Keys["LEFTSHIFT"], -- If set, both the keySwitchChannels and keySwitchChannelsSecondary keybinds must be pressed to switch the radio channels
keyProximity = Keys["Z"], -- Keybind used to switch the proximity mode

radioClickMaxChannel = 100, -- Set the max amount of radio channels that will have local radio clicks enabled
radioAnim = true, -- Enable or disable the radio animation
radioEnabled = true, -- Enable or disable using the radio

plugin_data = {
-- TeamSpeak channel name used by the voip
-- If the TSChannelWait is enabled, players who are currently in TSChannelWait will be automatically moved
Expand Down Expand Up @@ -55,3 +58,21 @@ AddEventHandler("onClientResourceStart", function(resource)
TriggerEvent("initializeVoip"); -- Trigger this event whenever you want to start the voip
end
end)

-- Update config properties from another script
function SetTokoProperty(key, value)
if TokoVoipConfig[key] ~= nil and TokoVoipConfig[key] ~= "plugin_data" then
TokoVoipConfig[key] = value

if voip then
if voip.config then
if voip.config[key] ~= nil then
voip.config[key] = value
end
end
end
end
end

-- Make exports available on first tick
exports("SetTokoProperty", SetTokoProperty)
8 changes: 4 additions & 4 deletions fivem_script/tokovoip_script/src/c_TokoVoip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ function TokoVoip.initialize(self)
end


if (IsControlPressed(0, self.radioKey) and self.plugin_data.radioChannel ~= -1) then -- Talk on radio
if (IsControlPressed(0, self.radioKey) and self.plugin_data.radioChannel ~= -1 and self.config.radioEnabled) then -- Talk on radio
self.plugin_data.radioTalking = true;
self.plugin_data.localRadioClicks = true;
if (self.plugin_data.radioChannel > 100) then
if (self.plugin_data.radioChannel > self.config.radioClickMaxChannel) then
self.plugin_data.localRadioClicks = false;
end
if (not getPlayerData(self.serverId, "radio:talking")) then
setPlayerData(self.serverId, "radio:talking", true, true);
end
self:updateTokoVoipInfo();
if (lastTalkState == false and self.myChannels[self.plugin_data.radioChannel]) then
if (lastTalkState == false and self.myChannels[self.plugin_data.radioChannel] and self.config.radioAnim) then
if (not string.match(self.myChannels[self.plugin_data.radioChannel].name, "Call") and not IsPedSittingInAnyVehicle(PlayerPedId())) then
RequestAnimDict("random@arrests");
while not HasAnimDictLoaded("random@arrests") do
Expand All @@ -162,7 +162,7 @@ function TokoVoip.initialize(self)
end
self:updateTokoVoipInfo();

if lastTalkState == true then
if lastTalkState == true and self.config.radioAnim then
lastTalkState = false
StopAnimTask(PlayerPedId(), "random@arrests","generic_radio_chatter", -4.0);
end
Expand Down
9 changes: 7 additions & 2 deletions fivem_script/tokovoip_script/src/c_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ local function clientProcessing()

for _, channel in pairs(voip.myChannels) do
if (channel.subscribers[voip.serverId] and channel.subscribers[playerServerId] and voip.myChannels[remotePlayerChannel] and remotePlayerUsingRadio) then
if (remotePlayerChannel <= 100) then
if (remotePlayerChannel <= voip.config.radioClickMaxChannel) then
tbl.radioEffect = true;
end
tbl.volume = 0;
Expand Down Expand Up @@ -321,4 +321,9 @@ end
AddEventHandler("updateVoipTargetPed", function(newTargetPed, useLocal)
targetPed = newTargetPed
useLocalPed = useLocal
end)
end)

-- Make exports available on first tick
exports("addPlayerToRadio", addPlayerToRadio);
exports("removePlayerFromRadio", removePlayerFromRadio);
exports("isPlayerInChannel", isPlayerInChannel);
6 changes: 5 additions & 1 deletion fivem_script/tokovoip_script/src/c_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ end
RegisterNetEvent("Tokovoip:doRefreshAllPlayerData");
AddEventHandler("Tokovoip:doRefreshAllPlayerData", doRefreshAllPlayerData);


--------------------------------------------------------------------------------
-- Utils: Drawing functions
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -193,3 +192,8 @@ Keys = {
["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
}

-- Make exports available on first tick
exports("getPlayerData", getPlayerData);
exports("setPlayerData", setPlayerData);
exports("refreshAllPlayerData", refreshAllPlayerData);