Zaktak

Rakgoul Script Errors Fix

May 4th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.32 KB | None | 0 0
  1. if( SERVER ) then
  2.     AddCSLuaFile("shared.lua")
  3. end
  4.  
  5. SWEP.Base               = "weapon_base"
  6.  
  7. SWEP.Spawnable          = true
  8. SWEP.AdminSpawnable     = true
  9.  
  10. SWEP.ViewModel      = "models/weapons/c_arms_citizen.mdl"
  11. SWEP.WorldModel     = ""   
  12. SWEP.ViewModelFOV   = 50
  13. SWEP.ViewModelFlip  = false
  14. SWEP.DrawCrosshair  = false
  15.  
  16. SWEP.Weight             = 1          
  17. SWEP.AutoSwitchTo       = true       
  18. SWEP.AutoSwitchFrom     = false
  19. SWEP.CSMuzzleFlashes    = false          
  20.    
  21. SWEP.Primary                = {}   
  22. SWEP.Primary.Damage         = 45                                 
  23. SWEP.Primary.ClipSize       = -1       
  24. SWEP.Primary.Delay          = 0.5    
  25. SWEP.Primary.DefaultClip    = 1      
  26. SWEP.Primary.Automatic      = true       
  27. SWEP.Primary.Ammo           = "none"     
  28.  
  29. SWEP.Secondary              = {}
  30. SWEP.Secondary.ClipSize     = -1           
  31. SWEP.Secondary.DefaultClip  = -1
  32. SWEP.Secondary.Delay        = 2
  33. SWEP.Secondary.Damage       = 0      
  34. SWEP.Secondary.Automatic    = false      
  35. SWEP.Secondary.Ammo         = "none"
  36.  
  37. SWEP.ReloadDelay    = 0
  38. SWEP.AnimDelay      = 0
  39. SWEP.AttackAnims    = {
  40.     "fists_left",
  41.     "fists_right"}
  42.  
  43. SWEP.PlayerModel    = nil
  44. SWEP.WerewolfModel  = "models/grealms/characters/rakghoul/rakghoul.mdl"
  45. SWEP.PlayerScale    = 1.0
  46. SWEP.WerewolfScale  = 1.0 --Change the collision type of the werewolf
  47.  
  48. SWEP.HealthBonus    = 800
  49. SWEP.HealAmount     = 5
  50. SWEP.HealTimer      = 2
  51. SWEP.HealId         = ""
  52.  
  53. SWEP.RunSpeed       = 500
  54. SWEP.WalkSpeed      = 300
  55. SWEP.SpeedModifier  = 1.4
  56.  
  57. SWEP.InfectChance   = 0.9
  58. SWEP.InfectDuration = 6 -- 5 x 12 = 60 seconds until infection turns to werewolfisms
  59. SWEP.ToggleVFX      = true
  60.  
  61. SWEP.HitSound   = {
  62.     "npc/zombie/claw_strike1.wav",
  63.     "npc/zombie/claw_strike2.wav",
  64.     "npc/zombie/claw_strike3.wav"}
  65. SWEP.MissSound  = {
  66.     "weapons/iceaxe/iceaxe_swing1.wav",
  67.     "npc/vort/claw_swing1.wav",
  68.     "npc/vort/claw_swing2.wav"}
  69. SWEP.FleshSound = {
  70.     "physics/flesh/flesh_squishy_impact_hard1.wav",
  71.     "physics/flesh/flesh_squishy_impact_hard2.wav",
  72.     "physics/flesh/flesh_squishy_impact_hard3.wav",
  73.     "physics/flesh/flesh_squishy_impact_hard4.wav"}
  74. SWEP.RoarSound  = {
  75.     "npc/ichthyosaur/attack_growl1.wav",
  76.     "npc/ichthyosaur/attack_growl2.wav",
  77.     "npc/ichthyosaur/attack_growl3.wav"}
  78. SWEP.AttackSound= {
  79.     "npc/antlion_guard/angry1.wav",
  80.     "npc/antlion_guard/angry2.wav",
  81.     "npc/antlion_guard/angry3.wav"}
  82. SWEP.SwingSound = {
  83.     "npc/zombie/claw_miss1.wav",
  84.     "npc/zombie/claw_miss2.wav"}
  85. SWEP.LeapSound = Sound("eoti/were/leaproar.wav")
  86.  
  87. if ( CLIENT ) then
  88.     SWEP.PrintName  = "Rakghoul Infection SWEP"  
  89.     SWEP.Category   = "Star Wars Rakghoul SWEP"
  90.     SWEP.Author     = "Ukushino"
  91.     SWEP.Purpose    = "\nDamage: "..SWEP.Primary.Damage.." ("..(SWEP.Primary.Damage/SWEP.Primary.Delay).." DPS)\n\nReload: Transform to Rakghoul\nHold E: Toggle Bloodvision\nRight-Click: Leap"
  92.     SWEP.Slot       = 0                  
  93.     SWEP.SlotPos    = 1
  94.     SWEP.DrawAmmo   = false
  95. end
  96.  
  97. function SWEP:Equip(owner)
  98.     self:RegeneratingHealth(owner)
  99.     timer.Simple(0.5, function()
  100.         if !IsValid(self) then return end
  101.         owner:SetActiveWeapon(self)
  102.         self:Deploy()
  103.     end)
  104. end
  105.  
  106. function SWEP:Deploy()
  107.     if CLIENT then
  108.         chat.AddText(
  109.         Color( 0, 200, 0 ), "Rakghoul Infection System (Controls):")
  110.         chat.AddText(
  111.         Color( 255, 100, 0 ), "Transform ",
  112.         Color( 255, 255, 0 ), "[Reload or Mouse2] | ",
  113.         Color( 255, 100, 0 ), "Toggle Bloodvision ",
  114.         Color( 255, 255, 0 ), "[Hold E] | ",
  115.         Color( 255, 100, 0 ), "Attack/Leap ",
  116.         Color( 255, 255, 0 ), "[Mouse1/2]")
  117.     end
  118.     if game.MaxPlayers() < 2 then
  119.         self.Owner:ChatPrint("Single Player Detected: Animations are unstable due to the game pausing, but SysTime() does not!")
  120.         self.Owner:ChatPrint("Recommend running on server or playing in +2 Player mode, Local or Internet!")
  121.     end
  122. end
  123.  
  124. function SWEP:Holster()
  125.     local owner = self.Owner
  126.     if (IsValid(owner)) then
  127.         self:MorphToHuman()
  128.     end
  129.     return true
  130. end
  131.  
  132. function SWEP:OnRemove()
  133.     self:RemoveSelf()
  134.     return true
  135. end
  136.  
  137. function SWEP:OnDrop()
  138.     self:RemoveSelf()
  139.     return true
  140. end
  141.  
  142. function SWEP:RemoveSelf()
  143.     local owner = self.Owner
  144.     if (IsValid(owner)) then
  145.         owner:StopSound("eoti_idlegrowlloop")
  146.         self:MorphToHuman()
  147.     end
  148.    
  149.     if !SERVER then return end
  150.     if timer.Exists(self.HealId) then timer.Remove( self.HealId ) return end
  151.     self:Remove()
  152. end
  153.  
  154. function SWEP:Reload()
  155.     if self.ReloadDelay > CurTime() then return end
  156.     if self.PlayerModel == nil then return end
  157.     self.ReloadDelay = CurTime() + 4
  158.     self.Weapon:SetNextPrimaryFire( CurTime() + 2.5 )
  159.     self.Weapon:SetNextSecondaryFire( CurTime() + 2.5 )
  160.  
  161.     if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + 4
  162.     else self.AnimDelay = SysTime() + 4 end
  163.    
  164.     local owner = self.Owner
  165.     if (!IsValid(owner)) then return end
  166.     if (!owner:Alive()) then return end
  167.    
  168.     if owner:GetModel() != self.WerewolfModel
  169.     then self:MorphToWerewolf()
  170.     else self:MorphToHuman()
  171.     end
  172. end
  173.  
  174. function SWEP:SecondaryAttack()
  175.     self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  176.    
  177.     if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + 0.45
  178.     else self.AnimDelay = SysTime() + 0.4 end
  179.    
  180.     local owner = self.Owner
  181.     if (!IsValid(owner)) then return end
  182.     if (!owner:Alive()) then return end
  183.     if owner:GetModel() == self.PlayerModel then
  184.         self:Reload()
  185.         return
  186.     end
  187.    
  188.     if SERVER then
  189.         owner:SetVelocity(Vector(0,0,250))
  190.         timer.Simple(0.15, function()
  191.             owner:SetVelocity(owner:GetAimVector() * 300)
  192.         end)
  193.     end
  194.    
  195.     self.Owner:EmitSound(self.LeapSound, 350, math.random(75,85))
  196. end
  197.  
  198. function SWEP:PrimaryAttack()
  199.     self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  200.    
  201.     if game.MaxPlayers() < 2 then self.AnimDelay = CurTime() + self.Primary.Delay
  202.     else self.AnimDelay = SysTime() + self.Primary.Delay end
  203.    
  204.     local owner = self.Owner
  205.     if (!IsValid(owner)) then return end
  206.     if (!owner:Alive()) then return end
  207.     if owner:GetModel() == self.PlayerModel then return end
  208.    
  209.     self:PrimaryAttackWerewolf(owner)
  210. end
  211.  
  212. ------------------------------------------------------------------------------------------------------------
  213. ------------------------------------------------------------------------------------------------------------
  214. ------------------------------------------------------------------------------------------------------------
  215. ------------------------------------------------------------------------------------------------------------
  216. ------------------------------------------------------------------------------------------------------------
  217.  
  218. function SWEP:MorphToWerewolf()
  219.     local owner = self.Owner
  220.     if self.PlayerModel == nil then return end
  221.     if owner:GetModel() == self.WerewolfModel then return end
  222.     owner:SetModelScale( self.WerewolfScale, 3 )
  223.     owner:SetModel( self.WerewolfModel )
  224.    
  225.  
  226.     if self.WerewolfScale > 1 then
  227.         owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )
  228.     else
  229.         owner:SetCollisionGroup( COLLISION_GROUP_NONE )
  230.     end
  231.  
  232.     self:Roar( owner )
  233.  
  234.     if (!IsValid(owner)) then return end
  235.     if (!owner:Alive()) then return end
  236.     self:SetHoldType( "knife" )
  237.     self:SendWeaponAnim(ACT_HL2MP_IDLE_KNIFE)
  238.    
  239.     self.Owner:EmitSound("eoti_idlegrowlloop", 350, math.random(23,40))
  240.  
  241.     self.ToggleVFX = true
  242.    
  243.     local vm = self.Owner:GetViewModel()
  244.     vm:ResetSequence( vm:LookupSequence( "fists_draw" ) )
  245. end
  246.  
  247. function SWEP:MorphToHuman()
  248.     local owner = self.Owner
  249.     if (!IsValid(owner)) or (!IsValid(self)) then return end
  250.     if (!IsValid(owner)) then return end
  251.     if owner:GetModel() == self.PlayerModel then return end
  252.     owner:StopSound("eoti_idlegrowlloop")
  253.     owner:SetModelScale( self.PlayerScale, 3 )
  254.     if self.PlayerModel != nil then owner:SetModel( self.PlayerModel ) end
  255.     self:Roar( owner )
  256.  
  257.    
  258.     if self.PlayerScale > 1 then owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )
  259.     else owner:SetCollisionGroup( COLLISION_GROUP_NONE ) end
  260.  
  261.     owner:SetRunSpeed(self.WalkSpeed)
  262.     owner:SetWalkSpeed(self.RunSpeed)
  263.  
  264.     if (!IsValid(owner)) then return end
  265.     if (!owner:Alive()) then return end
  266.     self:SetHoldType( "normal" )
  267.     self:SendWeaponAnim(ACT_HL2MP_IDLE_KNIFE)
  268.    
  269.     owner:StopSound("eoti_idlegrowlloop")
  270.    
  271.     self.ToggleVFX = false
  272.     if (!IsValid(owner)) then return end
  273.     local vm = self.Owner:GetViewModel()
  274.     if (!IsValid(vm)) then return end
  275.     if CLIENT then
  276.         vm:ResetSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
  277.     end
  278.     vm:ResetSequence( vm:LookupSequence( "fists_holster" ) )
  279. end
  280.  
  281. function SWEP:Roar(owner)
  282.     timer.Simple(0.15, function()
  283.         if (!IsValid(owner)) then return end
  284.         if (!owner:Alive()) then return end
  285.         if SERVER and not CLIENT then
  286.             owner:DoAnimationEvent(ACT_GMOD_GESTURE_TAUNT_ZOMBIE)
  287.             owner:EmitSound(table.Random(self.RoarSound), 100,math.random(75,95))
  288.         end
  289.     end)
  290. end
  291.  
  292. ------------------------------------------------------------------------------------------------------------
  293. ------------------------------------------------------------------------------------------------------------
  294. ------------------------------------------------------------------------------------------------------------
  295. ------------------------------------------------------------------------------------------------------------
  296. ------------------------------------------------------------------------------------------------------------
  297.  
  298. function SWEP:RegeneratingHealth(owner)
  299.     local hp, maxhp
  300.    
  301.     self.HealId  = math.random(165, 73623)
  302.     self.HealId = "WEAPON_INFECT_RAK"..self.HealId..owner:Name()
  303.    
  304.     timer.Create(self.HealId , self.HealTimer, 0, function()
  305.         if (!SERVER)
  306.         or (!IsValid(self))
  307.         or (!timer.Exists( self.HealId ))
  308.         then return end
  309.        
  310.         hp = owner:Health()
  311.         maxhp = (owner:GetMaxHealth() + self.HealthBonus or 100 + self.HealthBonus)
  312.         if maxhp < hp then return end
  313.         owner:SetHealth(math.Clamp( hp + self.HealAmount, 0, maxhp ))
  314.     end)
  315. end
  316.  
  317. function SWEP:PrimaryAttackWerewolf(owner)
  318.     local tr, trace, vm, anim
  319.    
  320.     --------------------------
  321.     vm = self.Owner:GetViewModel()
  322.     vm:ResetSequence( vm:LookupSequence( "fists_idle_01" ) )
  323.        
  324.     anim = self.AttackAnims[ math.random( 1, 2 ) ]
  325.  
  326.     timer.Simple( 0, function()
  327.         if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
  328.    
  329.         vm = self.Owner:GetViewModel()
  330.         vm:ResetSequence( vm:LookupSequence( anim ) )
  331.     end )
  332.    
  333.     owner:DoAnimationEvent(ACT_GMOD_GESTURE_RANGE_FRENZY)
  334.     if SERVER then
  335.         owner:EmitSound(table.Random(self.SwingSound))
  336.         owner:EmitSound(table.Random(self.AttackSound), 60)
  337.     end
  338.    
  339.     ------------------------
  340.    
  341.     tr = {}
  342.     tr.start = owner:GetShootPos()
  343.     tr.endpos = owner:GetShootPos() + ( owner:GetAimVector() * 95 )
  344.     tr.filter = owner
  345.     tr.mask = MASK_SHOT
  346.     trace = util.TraceLine( tr )
  347.  
  348.     if ( trace.Hit ) then
  349.  
  350.         if trace.Entity:IsPlayer()
  351.         or string.find(trace.Entity:GetClass(),"npc")
  352.         or string.find(trace.Entity:GetClass(),"prop_ragdoll") then
  353.             self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
  354.             bullet = {}
  355.             bullet.Num    = 1
  356.             bullet.Src    = owner:GetShootPos()
  357.             bullet.Dir    = owner:GetAimVector()
  358.             bullet.Spread = Vector(0, 0, 0)
  359.             bullet.Tracer = 0
  360.             bullet.Force  = 1
  361.             bullet.Damage = self.Primary.Damage
  362.             owner:FireBullets(bullet)
  363.             self:Infection(trace.Entity)
  364.             self.Weapon:EmitSound(table.Random(self.FleshSound),75)
  365.         else
  366.             self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
  367.             bullet = {}
  368.             bullet.Num    = 1
  369.             bullet.Src    = owner:GetShootPos()
  370.             bullet.Dir    = owner:GetAimVector()
  371.             bullet.Spread = Vector(0, 0, 0)
  372.             bullet.Tracer = 0
  373.             bullet.Force  = 1
  374.             bullet.Damage = self.Primary.Damage
  375.             owner:FireBullets(bullet)  
  376.             util.Decal("ManhackCut", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
  377.             self.Weapon:EmitSound(table.Random(self.HitSound),75)
  378.         end
  379.     else
  380.         self.Weapon:EmitSound(table.Random(self.MissSound),75)
  381.     end
  382.    
  383.     timer.Simple( 0.06, function() owner:ViewPunch( Angle( -2, -2,  0 ) ) end )
  384.     timer.Simple( 0.23, function() owner:ViewPunch( Angle(  3,  1,  0 ) ) end )
  385. end
  386.  
  387. function SWEP:Infection(dmg)
  388.     if !(math.random(0.01,1.00) >= self.InfectChance) then return end
  389.     if (!IsValid(dmg)) then return end
  390.     if (!dmg:IsPlayer()) then return end
  391.     if (!dmg:Alive()) then return end
  392.     if dmg:HasWeapon(self:GetClass()) then return end
  393.  
  394.     local id, step, cnt, rgb
  395.     id = "WerewolfInfectionTimer_"..dmg:Name()
  396.     step = math.floor(230/self.InfectDuration)
  397.     if timer.Exists(id) then return end
  398.    
  399.     cnt = 0
  400.     dmg:SetRenderMode( RENDERMODE_TRANSALPHA )
  401.     if SERVER then dmg:ChatPrint("You have contracted Rakghoul curse, you will succumb in "..(self.InfectDuration*5).." seconds.") end
  402.     dmg:EmitSound("eoti_idlegrowlloop", 350, math.random(23,40))
  403.    
  404.     timer.Create(id, 5, self.InfectDuration, function()
  405.         if (!IsValid(self))
  406.         or (!IsValid(dmg))
  407.         or (!dmg:IsPlayer())
  408.         or (!dmg:Alive())
  409.         or (dmg:HasWeapon(self:GetClass()))
  410.         or (!timer.Exists(id))
  411.         then
  412.             dmg:SetColor( Color(255,255,255) )
  413.             dmg:SetRenderMode( RENDERMODE_NORMAL )
  414.             timer.Destroy(id)
  415.             return false
  416.         end
  417.            
  418.         rgb = 255 - (cnt * step)
  419.         cnt = cnt + 1
  420.         dmg:SetColor( Color(rgb,rgb,rgb) )
  421.        
  422.         if cnt < self.InfectDuration then return end
  423.         if not SERVER and CLIENT then return end
  424.  
  425.         dmg:StopSound("eoti_idlegrowlloop")
  426.         dmg:Give(self:GetClass())
  427.         dmg:SetColor( Color(255,255,255) )
  428.         dmg:SetRenderMode( RENDERMODE_NORMAL )
  429.         timer.Destroy(id)
  430.         return true
  431.     end)
  432. end
  433.  
  434. function SWEP:Think()
  435.     local t
  436.     if game.MaxPlayers() < 2 then t = CurTime()
  437.     else t = SysTime() end
  438.     if self.AnimDelay > t then return true end
  439.    
  440.     local owner, primary
  441.     owner = self.Owner
  442.     primary = (self:GetNextPrimaryFire() - CurTime())
  443.    
  444.     if self.PlayerModel == nil then
  445.         self.PlayerModel = ""..self.Owner:GetModel()
  446.         self.PlayerScale = self.Owner:GetModelScale() or 1
  447.         self.WerewolfScale = self.PlayerScale * 1.15
  448.         self.WalkSpeed = owner:GetWalkSpeed()
  449.         self.RunSpeed = owner:GetRunSpeed()
  450.         return true
  451.     elseif owner:KeyDown(IN_USE) then
  452.         self.ToggleVFX = !self.ToggleVFX
  453.         if CLIENT then surface.PlaySound("UI/buttonclick.wav") end
  454.         self.AnimDelay = t + 0.5
  455.         return true
  456.     elseif owner:GetModel() == self.PlayerModel then
  457.         owner:SetRunSpeed(self.RunSpeed)
  458.         owner:SetWalkSpeed(self.WalkSpeed)
  459.         self.AnimDelay = t + 0.45
  460.         return true
  461.     elseif owner:KeyDown(IN_FORWARD) and !owner:KeyDown(IN_DUCK) then
  462.         owner:SetRunSpeed(math.Clamp(self.RunSpeed*self.SpeedModifier, 450, 1000))
  463.         owner:SetWalkSpeed(math.Clamp(self.WalkSpeed*self.SpeedModifier, 375, 1000))
  464.         owner:DoAnimationEvent(ACT_HL2MP_RUN_ZOMBIE_FAST)
  465.         self.AnimDelay = t + 0.4
  466.         return true
  467.     elseif t + primary > t then
  468.         self.AnimDelay = primary + 0.05
  469.         return true
  470.     end
  471.     self.AnimDelay = t + 0.5
  472. end
Add Comment
Please, Sign In to add comment