Facebook
From Turbo, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 242
  1. ------------------------------------------------------------
  2. ------------------------------------------------------------
  3. ---- Author: Dylan 'Itokoyamato' Thuillier              ----
  4. ----                                                    ----
  5. ---- Email: [email protected]                      ----
  6. ----                                                    ----
  7. ---- Resource: tokovoip_script                          ----
  8. ----                                                    ----
  9. ---- File: c_TokoVoip.lua                               ----\
  10. ------------------------------------------------------------
  11. ------------------------------------------------------------
  12.  
  13. --------------------------------------------------------------------------------
  14. --      Client: TokoVoip functions
  15. --------------------------------------------------------------------------------
  16.  
  17. TokoVoip = {};
  18. TokoVoip.__index = TokoVoip;
  19. local lastTalkState = false
  20.  
  21. function TokoVoip.init(self, config)
  22.         local self = setmetatable(config, TokoVoip);
  23.         self.config = json.decode(json.encode(config));
  24.         self.lastNetworkUpdate = 0;
  25.         self.lastPlayerListUpdate = self.playerListRefreshRate;
  26.         self.playerList = {};
  27.         return (self);
  28. end
  29.  
  30. function TokoVoip.loop(self)
  31.         Citizen.CreateThread(function()
  32.                 while (true) do
  33.                         Citizen.Wait(self.refreshRate);
  34.                         self:processFunction();
  35.                         self:sendDataToTS3();
  36.  
  37.                         self.lastNetworkUpdate = self.lastNetworkUpdate + self.refreshRate;
  38.                         self.lastPlayerListUpdate = self.lastPlayerListUpdate + self.refreshRate;
  39.                         if (self.lastNetworkUpdate >= self.networkRefreshRate) then
  40.                                 self.lastNetworkUpdate = 0;
  41.                                 self:updateTokoVoipInfo();
  42.                         end
  43.                         if (self.lastPlayerListUpdate >= self.playerListRefreshRate) then
  44.                                 self.playerList = GetActivePlayers();
  45.                                 self.lastPlayerListUpdate = 0;
  46.                         end
  47.                 end
  48.         end);
  49. end
  50.  
  51. function TokoVoip.sendDataToTS3(self) -- Send usersdata to the Javascript Websocket
  52.         if (self.pluginStatus == -1) then return end;
  53.         self:updatePlugin("updateTokoVoip", self.plugin_data);
  54. end
  55.  
  56. function TokoVoip.updateTokoVoipInfo(self, forceUpdate) -- Update the top-left info
  57.         local info = "";
  58.         if (self.mode == 1) then
  59.                 info = "Normal";
  60.         elseif (self.mode == 2) then
  61.                 info = "Hvisker";
  62.         elseif (self.mode == 3) then
  63.                 info = "Råber";
  64.         end
  65.  
  66.         if (self.plugin_data.radioTalking) then
  67.                 info = info .. " I radio ";
  68.         end
  69.         if (self.talking == 1 or self.plugin_data.radioTalking) then
  70.                 info = "<font class='talking'>" .. info .. "</font>";
  71.         end
  72.         if (self.plugin_data.radioChannel ~= -1 and self.myChannels[self.plugin_data.radioChannel]) then
  73.                 if (string.match(self.myChannels[self.plugin_data.radioChannel].name, "Call")) then
  74.                         info = info  .. "<br> [Mobil] " .. self.myChannels[self.plugin_data.radioChannel].name;
  75.                 else
  76.                         info = info  .. "<br> [Radio] " .. self.myChannels[self.plugin_data.radioChannel].name;
  77.                 end
  78.         end
  79.         if (info == self.screenInfo and not forceUpdate) then return end
  80.         self.screenInfo = info;
  81.         self:updatePlugin("updateTokovoipInfo", "" .. info);
  82. end
  83.  
  84. function TokoVoip.updatePlugin(self, event, payload)
  85.         --exports.tokovoip_script:doSendNuiMessage(event, payload);
  86.         SendNUIMessage({
  87.                         type = event,
  88.                         payload = payload
  89.         })
  90. end
  91.  
  92. function TokoVoip.updateConfig(self)
  93.         local data = self.config;
  94.         data.plugin_data = self.plugin_data;
  95.         data.pluginVersion = self.pluginVersion;
  96.         data.pluginStatus = self.pluginStatus;
  97.         data.pluginUUID = self.pluginUUID;
  98.         self:updatePlugin("updateConfig", data);
  99. end
  100.  
  101. function TokoVoip.initialize(self)
  102.         self:updateConfig();
  103.         self:updatePlugin("initializeSocket", self.wsServer);
  104.         Citizen.CreateThread(function()
  105.                 while (true) do
  106.                         Citizen.Wait(5);
  107.  
  108.                         if ((self.keySwitchChannelsSecondary and IsControlPressed(0, self.keySwitchChannelsSecondary)) or not self.keySwitchChannelsSecondary) then -- Switch radio channels
  109.                                 if (IsControlJustPressed(0, self.keySwitchChannels) and tablelength(self.myChannels) > 0) then
  110.                                         local myChannels = {};
  111.                                         local currentChannel = 0;
  112.                                         local currentChannelID = 0;
  113.  
  114.                                         for channel, _ in pairs(self.myChannels) do
  115.                                                 if (channel == self.plugin_data.radioChannel) then
  116.                                                         currentChannel = #myChannels + 1;
  117.                                                         currentChannelID = channel;
  118.                                                 end
  119.                                                 myChannels[#myChannels + 1] = {channelID = channel};
  120.                                         end
  121.                                         if (currentChannel == #myChannels) then
  122.                                                 currentChannelID = myChannels[1].channelID;
  123.                                         else
  124.                                                 currentChannelID = myChannels[currentChannel + 1].channelID;
  125.                                         end
  126.                                         self.plugin_data.radioChannel = currentChannelID;
  127.                                         setPlayerData(self.serverId, "radio:channel", currentChannelID, true);
  128.                                         self:updateTokoVoipInfo();
  129.                                 end
  130.                         elseif (IsControlJustPressed(0, self.keyProximity)) then -- Switch proximity modes (normal / whisper / shout)
  131.                                 if (not self.mode) then
  132.                                         self.mode = 1;
  133.                                 end
  134.                                 self.mode = self.mode + 1;
  135.                                 if (self.mode > 3) then
  136.                                         self.mode = 1;
  137.                                 end
  138.                                 setPlayerData(self.serverId, "voip:mode", self.mode, true);
  139.                                 self:updateTokoVoipInfo();
  140.                         end
  141.  
  142.  
  143.                         if (IsControlPressed(0, self.radioKey) and self.plugin_data.radioChannel ~= -1 and self.config.radioEnabled) then -- Talk on radio
  144.                                 self.plugin_data.radioTalking = true;
  145.                                 self.plugin_data.localRadioClicks = true;
  146.                                 if (self.plugin_data.radioChannel > self.config.radioClickMaxChannel) then
  147.                                         self.plugin_data.localRadioClicks = false;
  148.                                 end
  149.                                 if (not getPlayerData(self.serverId, "radio:talking")) then
  150.                                         setPlayerData(self.serverId, "radio:talking", true, true);
  151.                                 end
  152.                                 self:updateTokoVoipInfo();
  153.                                 if (lastTalkState == false and self.myChannels[self.plugin_data.radioChannel] and self.config.radioAnim) then
  154.                                         if (not string.match(self.myChannels[self.plugin_data.radioChannel].name, "Call") and not IsPedSittingInAnyVehicle(PlayerPedId())) then
  155.                                                 RequestAnimDict("random@arrests");
  156.                                                 while not HasAnimDictLoaded("random@arrests") do
  157.                                                         Wait(5);
  158.                                                 end
  159.                                                 local prop = GetHashKey("prop_cs_hand_radio")
  160.                                                 while not HasModelLoaded(prop ) do
  161.                                                    RequestModel(prop )
  162.                                                    Citizen.Wait(10)
  163.                                                 end
  164.                                                 if HasModelLoaded(prop) then
  165.                                                    object = CreateObject(prop, GetEntityCoords(PlayerPedId()), true)
  166.                                                    AttachEntityToEntity(object, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 60309), -0.03, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
  167.                                                    TaskPlayAnim(PlayerPedId(),"random@arrests","generic_radio_chatter", 8.0, 0.0, -1, 49, 0, 0, 0, 0);
  168.                                                    end
  169.                                                    lastTalkState = true
  170.                                                    end
  171.                                            end
  172.                                    else
  173.                                            self.plugin_data.radioTalking = false;
  174.                                            if (getPlayerData(self.serverId, "radio:talking")) then
  175.                                                    setPlayerData(self.serverId, "radio:talking", false, true);
  176.                                            end
  177.                                            self:updateTokoVoipInfo();
  178.                                            
  179.                                            if lastTalkState == true and self.config.radioAnim then
  180.                                                    lastTalkState = false
  181.                                                    StopAnimTask(PlayerPedId(), "random@arrests","generic_radio_chatter", -4.0);
  182.                                                    DeleteObject(object)
  183.                                            end
  184.                                    end
  185.                            end
  186.                    end);
  187.            end
  188.  
  189. function TokoVoip.disconnect(self)
  190.         self:updatePlugin("disconnect");
  191. end
  192.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Sons_OF_Anarchy text 5 Months ago.
Re: Untitled Flying Leopard text 2 Years ago.