Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1.  
  2. local PLUGIN = PLUGIN;
  3. local Clockwork = Clockwork;
  4.  
  5. function PLUGIN:PlayerAdjustChannels(player)
  6. local items = player:GetInventory();
  7. for k, itemList in pairs(items) do
  8. for k, itemTable in pairs(itemList) do
  9. if (!itemTable("frequency", false)) then
  10. break;
  11. elseif (itemTable:GetData("On") and (!itemTable("factionLock") or itemTable("factionLock")[player:GetFaction()])) then
  12. self:AddItemChannelToPlayer(player, itemTable);
  13. end;
  14. end;
  15. end;
  16. end;
  17.  
  18. function PLUGIN:PlayerItemGiven(player, itemTable)
  19. if (itemTable("frequency", false)) then
  20. timer.Simple(FrameTime() * 32, function()
  21. Clockwork.radio:SetPlayerChannels(player);
  22. end);
  23. end;
  24. end;
  25.  
  26. function PLUGIN:PlayerItemTaken(player, itemTable)
  27. if (itemTable("frequency", false)) then
  28. timer.Simple(FrameTime() * 32, function()
  29. Clockwork.radio:SetPlayerChannels(player);
  30. end);
  31. end;
  32. end;
  33.  
  34. Clockwork.datastream:Hook("radio_frequency", function(player, data)
  35. local itemTable = player:FindItemByID(data[2], tonumber(data[3]));
  36.  
  37. if (itemTable) then
  38. if (string.find(data[1], "^%d%d%d%.%d$")) then
  39. local first = string.match(data[1], "(%d)%d%d%.%d");
  40. if (first != "0") then
  41. itemTable:SetData("frequency", data[1]);
  42. Clockwork.radio:SetPlayerChannels(player);
  43.  
  44. Clockwork.player:Notify(player, "You have set this device's frequency to "..data[1]..".");
  45. else
  46. Clockwork.player:Notify(player, "The frequency must be between 100.0 and 999.9!");
  47. end;
  48. else
  49. Clockwork.player:Notify(player, "The radio frequency must look like xxx.x!");
  50. end;
  51. end;
  52. end);
  53.  
  54. -- Called when Clockwork has loaded all of the entities.
  55. function PLUGIN:ClockworkInitPostEntity()
  56. self:LoadRadios();
  57. end;
  58.  
  59. -- Called just after data should be saved.
  60. function PLUGIN:PostSaveData()
  61. self:SaveRadios();
  62. end;
  63.  
  64. -- Called when an entity's menu option should be handled.
  65. function PLUGIN:EntityHandleMenuOption(player, radio, option, arguments)
  66. if (radio:GetClass() == "cw_itemradio") then
  67. if (option == "Set Frequency" and type(arguments) == "string") then
  68. local channelTable = Clockwork.radio:FindByID(arguments);
  69. if (channelTable) then
  70. if (channelTable.stationaryCanAccess) then
  71. radio:SetFrequency(channelTable.uniqueID);
  72.  
  73. Clockwork.player:Notify(player, "You have set this stationary radio's channel to "..channelTable.name..".");
  74. else
  75. Clockwork.player:Notify(player, "This stationary radio cannot tune in on that channel!");
  76. end;
  77. elseif (string.find(arguments, "^%d%d%d%.%d$")) then
  78. local first = string.match(arguments, "(%d)%d%d%.%d");
  79. if (first != "0") then
  80. local freqID = "freq_"..string.gsub(arguments, "%p", "");
  81. local channelTable = Clockwork.radio:FindByID(freqID);
  82.  
  83. if (!channelTable) then
  84. self:CreateItemChannel("freq "..arguments, freqID);
  85. Clockwork.datastream:Start(nil, "create_item_channel", {"freq "..arguments, freqID});
  86.  
  87. radio:SetFrequency(freqID);
  88.  
  89. Clockwork.player:Notify(player, "You have set this stationary radio's frequency to "..arguments..".");
  90. else
  91. Clockwork.player:Notify(player, "The frequency must be between 100.0 and 999.9!");
  92. end;
  93. else
  94. Clockwork.player:Notify(player, "The radio frequency must look like xxx.x!");
  95. end;
  96. elseif (arguments == "cw_radioToggle") then
  97. radio:Toggle();
  98. elseif (arguments == "cw_radioTake") then
  99. local bSuccess, fault = player:GiveItem(Clockwork.item:CreateInstance("stat_radio"));
  100.  
  101. if (!bSuccess) then
  102. Clockwork.player:Notify(player, fault);
  103. else
  104. radio:Remove();
  105. end;
  106. end;
  107. end;
  108.  
  109. if (radio:GetClass() == "cw_bug") then
  110. if (option == "Set Frequency" and type(arguments) == "string") then
  111. local channelTable = Clockwork.radio:FindByID(arguments);
  112. if (channelTable) then
  113. if (channelTable.stationaryCanAccess) then
  114. radio:SetFrequency(channelTable.uniqueID);
  115.  
  116. Clockwork.player:Notify(player, "You have set this bug's listening frequency to "..channelTable.name..".");
  117. else
  118. Clockwork.player:Notify(player, "This bug cannot listen in on that channel!");
  119. end;
  120. elseif (string.find(arguments, "^%d%d%d%.%d$")) then
  121. local first = string.match(arguments, "(%d)%d%d%.%d");
  122. if (first != "0") then
  123. local freqID = "freq_"..string.gsub(arguments, "%p", "");
  124. local channelTable = Clockwork.radio:FindByID(freqID);
  125.  
  126. if (!channelTable) then
  127. self:CreateItemChannel("freq "..arguments, freqID);
  128. end;
  129. Clockwork.datastream:Start(nil, "create_item_channel", {"freq "..arguments, freqID});
  130.  
  131. radio:SetFrequency(freqID);
  132.  
  133. Clockwork.player:Notify(player, "You have set this bug's frequency to "..arguments..".");
  134. else
  135. Clockwork.player:Notify(player, "The frequency must be between 100.0 and 999.9!");
  136. end;
  137. else
  138. Clockwork.player:Notify(player, "The radio frequency must look like xxx.x!");
  139. end;
  140. elseif (arguments == "cw_radioToggle") then
  141. radio:Toggle();
  142. elseif (arguments == "cw_radioTake") then
  143. local bSuccess, fault = player:GiveItem(Clockwork.item:CreateInstance("stat_radio"));
  144.  
  145. if (!bSuccess) then
  146. Clockwork.player:Notify(player, fault);
  147. else
  148. radio:Remove();
  149. end;
  150.  
  151. function PLUGIN:ChatBoxMessageAdded(info)
  152. local class = info.class
  153. if (class == "ic" or class == "whisper" or class == "yell") then
  154. local player = info.speaker
  155. local radio = player:GetEyeTraceNoCursor().Entity;
  156. -- For stationary radios
  157. if (radio and radio:GetClass() == "cw_itemradio") then
  158. if (!radio:IsOff()) then
  159. local range = Clockwork.config:Get("talk_radius"):Get();
  160. local sayType = nil
  161. if (class == "whisper") then
  162. range = range / 3;
  163. sayType = "whisper"
  164. elseif (class == "yell") then
  165. range = range * 2;
  166. sayType = "yell"
  167. end;
  168.  
  169. if (radio:GetPos():DistToSqr(player:GetShootPos()) <= math.pow(range, 2)) then
  170. local data = {
  171. range = range,
  172. sayType = sayType,
  173. channelID = radio:GetFrequency(),
  174. stationaryRadio = true
  175. };
  176. Clockwork.radio:SayRadio(player, info.text, data, true);
  177.  
  178. info.bShouldSend = false;
  179. end;
  180. end;
  181. end;
  182.  
  183. -- For bugs
  184. local range = math.pow(Clockwork.config:Get("talk_radius"):Get(), 2);
  185. local radios = ents.FindByClass("cw_bug");
  186. local channelID = info.data.channelID;
  187. for k, radio in pairs(radios) do
  188. if (player:GetPos():DistToSqr(radio:GetPos()) < range) then
  189. if (!radio:IsOff()) then
  190. local range = Clockwork.config:Get("talk_radius"):Get();
  191. local sayType = nil
  192. if (class == "whisper") then
  193. range = range / 3;
  194. sayType = "whisper"
  195. elseif (class == "yell") then
  196. range = range * 2;
  197. sayType = "yell"
  198. end;
  199.  
  200. --[[local data = {
  201. range = range,
  202. sayType = sayType,
  203. channelID = radio:GetFrequency(),
  204. stationaryRadio = true
  205. };
  206. Clockwork.radio:SayRadio(player, info.text, data, true);
  207.  
  208. info.bShouldSend = false;]]
  209. Schema:AddCombineDisplayLine("(AUDIO MONITOR) "..player:Name()..": "..info.text, Color(225,192,203,255))
  210.  
  211. end;
  212. end;
  213. end;
  214. end;
  215.  
  216. function PLUGIN:PlayerCanHearRadioTransmit(player, info)
  217. local range = math.pow(Clockwork.config:Get("talk_radius"):Get(), 2);
  218. local radios = ents.FindByClass("cw_itemradio");
  219. local channelID = info.data.channelID;
  220. for k, radio in pairs(radios) do
  221. if (radio:IsOff() or radio:GetFrequency() != channelID) then
  222. continue;
  223. else
  224. if (player:GetPos():DistToSqr(radio:GetPos()) < range) then
  225. return true;
  226. end;
  227. end;
  228. end;
  229. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement