Advertisement
NSKuber

Fixed Damaging script

Sep 1st, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.48 KB | None | 0 0
  1. local time = GetDateTimeLocal()
  2. local seed = 3600*tonumber(string.sub(time,-8,-7))+60*tonumber(string.sub(time,-5,-4))+tonumber(string.sub(time,-2,-1))
  3. local RNG = CreateRandomNumberGenerator(seed + mthTruncF(mthRndF() * 1000))  
  4. local rndIntRange = function(a,b)
  5.   return (mthFloorF(RNG:RndF()*(b-a+1)) % (b-a+1) + a)
  6. end
  7.  
  8. local Math = worldGlobals.Math
  9. local resSpawnTemplates = worldGlobals.worldInfo:LoadResource(Depfile("Content/7SmokeTennis2017_Blue/Levels/10_Tenebriaquies/Scripts/NightmareLord/Templates/Beam.rsc"))
  10.  
  11. --Gets properties for player variable
  12. -- player : CPlayerPuppetEntity
  13. -- NightmareLord : CPuppetEntity
  14. -- BeamMarkerVar : CPathMarkerEntity
  15. -- BeamBaseVar :CParticleEffectEntity
  16. -- BeamVar :CParticleEffectEntity
  17. -- resSpawnTemplates : CTemplatePropertiesHolder
  18.  
  19. --local variables
  20. local player = nil
  21. local NightmareLord = nil
  22. local playerplacement = nil
  23. local LordPos = nil
  24. local BeamMarkerVar = nil
  25. local BeamBaseVar = nil
  26. local BeamVar = nil
  27.  
  28.  
  29. --PillarDamageScriptByRyason
  30. local PillarDamager = --Damages players within a XZ radius of a marker for an amount of time
  31.   function(OwnerPuppet,Marker,DamagerRadius,Damage,DamageTime,LifeTime)
  32.     RunAsync( function()
  33.       local Vect_Marker = Marker:GetPlacement():GetVect()
  34.       Vect_Marker.y = 0
  35.       local StartTime = worldInfo:SimNow()
  36.       local LastDamageTime = worldInfo:SimNow()
  37.       while timDifference(worldInfo:SimNow(),StartTime) <= LifeTime do
  38.         if timDifference(worldInfo:SimNow(),LastDamageTime) >= DamageTime then
  39.           local RealDamage = mthFloorF(timDifference(worldInfo:SimNow(),LastDamageTime)/DamageTime)*Damage
  40.           LastDamageTime = worldInfo:SimNow()
  41.           local AllChars = worldInfo:GetCharacters("","",Marker,100)
  42.           for i = 1,#AllChars,1 do
  43.             if not ((AllChars[i] == OwnerPuppet) or IsDeleted(AllChars[i])) then
  44.               local BoundingBox = AllChars[i]:GetBoundingBoxSize()
  45.               local CharRadius = (BoundingBox.x + BoundingBox.z) / 4
  46.               local Vect_Puppet = AllChars[i]:GetPlacement():GetVect()
  47.               Vect_Puppet.y = 0
  48.               local Distance = mthLenV3f(Vect_Marker-Vect_Puppet)
  49.               if (Distance - CharRadius) <= DamagerRadius then
  50.                 if not ((OwnerPuppet == nil) or IsDeleted(OwnerPuppet)) then
  51.                   OwnerPuppet:InflictDamageToTarget(AllChars[i],RealDamage,-1,"Piercing")
  52.                 else
  53.                   AllChars[i]:InflictDamageOfType(RealDamage,"Piercing")
  54.                 end
  55.               end
  56.             end
  57.           end
  58.         end
  59.         Wait(CustomEvent("OnStep"))
  60.       end
  61.     end)
  62.   end
  63.  
  64. worldGlobals.CreateRPC("server", "reliable", "RPCBeam", function(BeamPos)  
  65.   RunAsync(function()  
  66.     local BeamMarkerVar = resSpawnTemplates:SpawnEntityFromTemplateByName("BeamMarker", worldGlobals.worldInfo, BeamPos)
  67.     local BeamBaseVar = resSpawnTemplates:SpawnEntityFromTemplateByName("BeamBase", worldGlobals.worldInfo, BeamPos)
  68.     local BeamVar = resSpawnTemplates:SpawnEntityFromTemplateByName("Beam", worldGlobals.worldInfo, BeamPos)
  69.     BeamBaseVar:SetParent(BeamMarkerVar)
  70.     BeamVar:SetParent(BeamMarkerVar)
  71.     BeamMarkerVar:SetPlacement(LordPos)  
  72.  
  73.     Wait(Delay(1))
  74.     if worldGlobals.netIsHost then
  75.       PillarDamager(NightmareLord, BeamMarkerVar, 1.375, 1, 0.06, 3)
  76.     end
  77.     Wait(Delay(4))
  78.     if not IsDeleted(BeamMarkerVar) then BeamMarkerVar:Delete() end
  79.     if not IsDeleted(BeamBaseVar) then BeamBaseVar:Delete() end
  80.     if not IsDeleted(BeamVar) then BeamVar:Delete() end
  81.   end)
  82. end)  
  83.  
  84. --Sets up the Spawnee for scripting  
  85. RunHandled(WaitForever,
  86.  
  87. On(Event(NightmareLordSpawnee.SpawneeAvailable)),
  88. function(SpawnedEvent)
  89.   NightmareLord = SpawnedEvent:GetSpawnedEntity()
  90.    
  91.   RunHandled(
  92.   function()
  93.     Wait(Event(NightmareLord.Died))
  94.   end,
  95.  
  96.  
  97.   --Starts script on Macro Event
  98.   OnEvery(CustomEvent(NightmareLord, "LaserWave")),
  99.     function()    
  100.     local LordPos = NightmareLord:GetPlacement()  
  101.     for i=1,16,1 do
  102.       if IsDeleted(NightmareLord) then break end
  103.       if not NightmareLord:IsAlive() then break end
  104.       local fRadius = RNG:RndF()*30 + 5
  105.       local fAngle = RNG:RndF()*360
  106.       local BeamPos = mthCloneQV(LordPos)
  107.       BeamPos.vx = BeamPos.vx + mthSinF(mthDegToRad(fAngle))*fRadius
  108.       BeamPos.vz = BeamPos.vz + mthCosF(mthDegToRad(fAngle))*fRadius                
  109.       worldGlobals.RPCBeam(BeamPos)
  110.       Wait(Delay(0.5*(1+RNG:RndF())))  
  111.     end          
  112.   end)
  113. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement