Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- SmartInteraction = {}
- if CLIENT then
- CreateClientConVar('cl_use_hint_background_color', '20 20 20 100', true, true, 'color of hint background in RGBA format.')
- CreateClientConVar('cl_use_hint_color', '255 235 15', true, true, 'color of hint text && halo in RGB format.')
- SmartInteraction.HintExtraEntities = {
- ['prop_door_rotating'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
- ['func_door_rotating'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
- ['func_door'] = string.upper(language.GetPhrase('smart_interaction.hint.open')),
- ['gmod_button'] = string.upper(language.GetPhrase('smart_interaction.hint.push'))
- }
- SmartInteraction.HintDistance = 120
- SmartInteraction.HintVisiblity = false
- SmartInteraction.HintString = ''
- SmartInteraction.HintAnimationSpeed = 15
- SmartInteraction.HintAlpha = 0
- SmartInteraction.HintBackgroundAlpha = 0
- SmartInteraction.HintWidth = 0
- hook.Add('PreDrawHalos', 'SmartInteraction_PreDrawHalos', function()
- local __a = LocalPlayer()
- local __b = __a:GetEyeTrace()
- if __b.Entity and IsValid(__b.Entity) and not __a:InVehicle() and __a:GetPos():DistToSqr(__b.Entity:GetPos()) <= SmartInteraction.HintDistance * SmartInteraction.HintDistance then
- local __c = __b.Entity
- local __d = __c:GetClass()
- local __e = string.upper(input.LookupBinding('+use'))
- local f = string.upper(language.GetPhrase('smart_interaction.hint.press'))
- if __c:IsWeapon() or string.StartWith(__d, 'item') or __c:IsVehicle() or SmartInteraction.HintExtraEntities[__d] then
- if __c:IsWeapon() or string.StartWith(__d, 'item') then
- SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. string.upper(language.GetPhrase('smart_interaction.hint.pick'))
- elseif __c:IsVehicle() then
- SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. string.upper(language.GetPhrase('smart_interaction.hint.enter'))
- elseif SmartInteraction.HintExtraEntities[__d] then
- SmartInteraction.HintString = f .. ' ' .. __e .. ' ' .. SmartInteraction.HintExtraEntities[__d]
- end
- halo.Add({__c}, SmartInteraction:ParseRGBConVar('cl_use_hint_color', 255), 5, 5, 3)
- SmartInteraction.HintVisiblity = true
- else
- SmartInteraction.HintVisiblity = false
- end
- else
- SmartInteraction.HintVisiblity = false
- end
- end)
- function SmartInteraction:ParseRGBConVar(__g, __h)
- local __i = string.Split(GetConVar(__g):GetString() or '0 0 0 0', ' ')
- return Color(__i[1] or 0, __i[2] or 0, __i[3] or 0, __h or __i[4] or 0)
- end
- hook.Add('HUDPaint', 'SmartInteraction_HUDPaint', function()
- local __a = LocalPlayer()
- if IsValid(__a) then
- if SmartInteraction.HintWidth > 1 then
- local __j, __k = ScrW() / 2, ScrH() / 2
- draw.RoundedBox(6, __j - SmartInteraction.HintWidth / 2, __k + 225, SmartInteraction.HintWidth, 45, SmartInteraction:ParseRGBConVar('cl_use_hint_background_color', SmartInteraction.HintBackgroundAlpha))
- draw.SimpleText(SmartInteraction.HintString, 'GModNotify', __j, __k + 237, SmartInteraction:ParseRGBConVar('cl_use_hint_color', SmartInteraction.HintAlpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
- end
- if SmartInteraction.HintVisiblity then
- SmartInteraction.HintWidth = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintWidth, 325)
- if SmartInteraction.HintWidth > 300 then
- SmartInteraction.HintAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintAlpha, 255)
- end
- SmartInteraction.HintBackgroundAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintBackgroundAlpha, SmartInteraction:ParseRGBConVar('cl_use_hint_background_color').a)
- else
- SmartInteraction.HintWidth = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintWidth, 0)
- SmartInteraction.HintAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed * 5, 1), SmartInteraction.HintAlpha, 0)
- SmartInteraction.HintBackgroundAlpha = Lerp(math.min(FrameTime() * SmartInteraction.HintAnimationSpeed, 1), SmartInteraction.HintBackgroundAlpha, 0)
- end
- end
- end)
- end
- if SERVER then
- local __l = FindMetaTable('Player')
- function __l:Give(__d)
- local __c = ents.Create(__d)
- if IsValid(__c) then
- __c:SetPos(self:GetPos())
- __c.GiveTo = self
- __c:Spawn()
- timer.Simple(0.1, function()
- self:SelectWeapon(__d)
- end)
- end
- end
- function SmartInteraction:IsInPlayerSight(__a, __c)
- local __b = __a:GetEyeTrace()
- if IsValid(__c) and __b then
- if __b.Entity == __c then
- return true
- else
- return false
- end
- end
- end
- hook.Add('PlayerCanPickupItem', 'SmartInteraction_PlayerCanPickupItem', function(__a, __c)
- if __a:KeyDown(IN_USE) and not __a:KeyDown(IN_ATTACK) then
- return SmartInteraction:IsInPlayerSight(__a, __c)
- else
- return false
- end
- end)
- hook.Add('PlayerCanPickupWeapon', 'SmartInteraction_PlayerCanPickupWeapon', function(__a, __m)
- if __a.SmartInteractionWeaponPickupSpawn and CurTime() > __a.SmartInteractionWeaponPickupSpawn then
- if IsValid(__m.GiveTo) and __m.GiveTo == __a then
- return true
- end
- if SmartInteraction:IsInPlayerSight(__a, __m) and __a:KeyPressed(IN_USE) and not __a:KeyDown(IN_ATTACK) then
- __a.DrawWeapon = __m:GetClass()
- timer.Simple(0.1, function()
- __a:SelectWeapon(__a.DrawWeapon)
- end)
- return true
- else
- return false
- end
- end
- end)
- hook.Add('PlayerSpawn', 'SmartInteraction_PlayerSpawn', function(__a)
- __a.SmartInteractionWeaponPickupSpawn = CurTime()
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement