Advertisement
Shark_vil

smart_interaction_2818916773 - SRC

Jun 26th, 2022
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. SmartInteraction = {}
  4.  
  5. if CLIENT then
  6.   CreateClientConVar('cl_use_hint_background_color', '20 20 20 100', true, true, 'color of hint background in RGBA format.')
  7.  
  8.   CreateClientConVar('cl_use_hint_color', '255 235 15', true, true, 'color of hint text && halo in RGB format.')
  9.  
  10.   SmartInteraction.HintExtraEntities = {
  11.     ['prop_door_rotating'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
  12.     ['func_door_rotating'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
  13.     ['func_door'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
  14.     ['gmod_button'] = string.upper(language.GetPhrase('smart_interaction.hint.push'))
  15.   }
  16.  
  17.   SmartInteraction.HintDistance = 120
  18.   SmartInteraction.HintVisiblity = false
  19.   SmartInteraction.HintString = ''
  20.   SmartInteraction.HintAnimationSpeed = 15
  21.   SmartInteraction.HintAlpha = 0
  22.   SmartInteraction.HintBackgroundAlpha = 0
  23.   SmartInteraction.HintWidth = 0
  24.  
  25.   hook.Add('PreDrawHalos', 'SmartInteraction_PreDrawHalos', function()
  26.     local __a = LocalPlayer()
  27.     local __b = __a:GetEyeTrace()
  28.  
  29.     if __b.Entity and IsValid(__b.Entity) and not __a:InVehicle() and __a:GetPos():DistToSqr(__b.Entity:GetPos()) <= SmartInteraction.HintDistance * SmartInteraction.HintDistance then
  30.       local __c = __b.Entity
  31.       local __d = __c:GetClass()
  32.       local __e = string.upper(input.LookupBinding('+use'))
  33.       local f = string.upper(language.GetPhrase('smart_interaction.hint.press'))
  34.  
  35.       if __c:IsWeapon() or string.StartWith(__d, 'item') or __c:IsVehicle() or SmartInteraction.HintExtraEntities[__d] then
  36.         if __c:IsWeapon() or string.StartWith(__d, 'item') then
  37.           SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. string.upper(language.GetPhrase('smart_interaction.hint.pick'))
  38.         elseif __c:IsVehicle() then
  39.           SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. string.upper(language.GetPhrase('smart_interaction.hint.enter'))
  40.         elseif SmartInteraction.HintExtraEntities[__d] then
  41.           SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. SmartInteraction.HintExtraEntities[__d]
  42.         end
  43.  
  44.         halo.Add({__c}, SmartInteraction:ParseRGBConVar('cl_use_hint_color', 255), 5, 5, 3)
  45.  
  46.         SmartInteraction.HintVisiblity = true
  47.       else
  48.         SmartInteraction.HintVisiblity = false
  49.       end
  50.     else
  51.       SmartInteraction.HintVisiblity = false
  52.     end
  53.   end)
  54.  
  55.   function SmartInteraction:ParseRGBConVar(__g, __h)
  56.     local __i = string.Split(GetConVar(__g):GetString() or '0 0 0 0', ' ')
  57.  
  58.     return Color(__i[1] or 0, __i[2] or 0, __i[3] or 0, __h or __i[4] or 0)
  59.   end
  60.  
  61.   hook.Add('HUDPaint', 'SmartInteraction_HUDPaint', function()
  62.     local __a = LocalPlayer()
  63.  
  64.     if IsValid(__a) then
  65.       if SmartInteraction.HintWidth > 1 then
  66.         local __j, __k = ScrW() / 2, ScrH() / 2
  67.         draw.RoundedBox(6, __j - SmartInteraction.HintWidth / 2, __k + 225, SmartInteraction.HintWidth, 45, SmartInteraction:ParseRGBConVar('cl_use_hint_background_color', SmartInteraction.HintBackgroundAlpha))
  68.         draw.SimpleText(SmartInteraction.HintString, 'GModNotify', __j, __k + 237, SmartInteraction:ParseRGBConVar('cl_use_hint_color', SmartInteraction.HintAlpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
  69.       end
  70.  
  71.       if SmartInteraction.HintVisiblity then
  72.         SmartInteraction.HintWidth = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintWidth, 325)
  73.  
  74.         if SmartInteraction.HintWidth > 300 then
  75.           SmartInteraction.HintAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintAlpha, 255)
  76.         end
  77.  
  78.         SmartInteraction.HintBackgroundAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintBackgroundAlpha, SmartInteraction:ParseRGBConVar('cl_use_hint_background_color').a)
  79.       else
  80.         SmartInteraction.HintWidth = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintWidth, 0)
  81.         SmartInteraction.HintAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed * 5, 1), SmartInteraction.HintAlpha, 0)
  82.         SmartInteraction.HintBackgroundAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintBackgroundAlpha, 0)
  83.       end
  84.     end
  85.   end)
  86. end
  87.  
  88. if SERVER then
  89.   local __l = FindMetaTable('Player')
  90.  
  91.   function __l:Give(__d)
  92.     local __c = ents.Create(__d)
  93.  
  94.     if IsValid(__c) then
  95.       __c:SetPos(self:GetPos())
  96.       __c.GiveTo = self
  97.       __c:Spawn()
  98.  
  99.       timer.Simple(0.1, function()
  100.         self:SelectWeapon(__d)
  101.       end)
  102.     end
  103.   end
  104.  
  105.   function SmartInteraction:IsInPlayerSight(__a, __c)
  106.     local __b = __a:GetEyeTrace()
  107.  
  108.     if IsValid(__c) and __b then
  109.       if __b.Entity == __c then
  110.         return true
  111.       else
  112.         return false
  113.       end
  114.     end
  115.   end
  116.  
  117.   hook.Add('PlayerCanPickupItem', 'SmartInteraction_PlayerCanPickupItem', function(__a, __c)
  118.     if __a:KeyDown(IN_USE) and not __a:KeyDown(IN_ATTACK) then
  119.       return SmartInteraction:IsInPlayerSight(__a, __c)
  120.     else
  121.       return false
  122.     end
  123.   end)
  124.  
  125.   hook.Add('PlayerCanPickupWeapon', 'SmartInteraction_PlayerCanPickupWeapon', function(__a, __m)
  126.     if __a.SmartInteractionWeaponPickupSpawn and CurTime() > __a.SmartInteractionWeaponPickupSpawn then
  127.       if IsValid(__m.GiveTo) and __m.GiveTo == __a then
  128.         return true
  129.       end
  130.  
  131.       if SmartInteraction:IsInPlayerSight(__a, __m) and __a:KeyPressed(IN_USE) and not __a:KeyDown(IN_ATTACK) then
  132.         __a.DrawWeapon = __m:GetClass()
  133.  
  134.         timer.Simple(0.1, function()
  135.           __a:SelectWeapon(__a.DrawWeapon)
  136.         end)
  137.  
  138.         return true
  139.       else
  140.         return false
  141.       end
  142.     end
  143.   end)
  144.  
  145.   hook.Add('PlayerSpawn', 'SmartInteraction_PlayerSpawn', function(__a)
  146.     __a.SmartInteractionWeaponPickupSpawn = CurTime()
  147.   end)
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement