hlsdk

ns2 nonsense

Dec 29th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.60 KB | None | 0 0
  1.  
  2. Script.Load("../ns2/lua/Marine.lua")
  3.  
  4. local trigger = false
  5. local kSetFOV = 40
  6. local range = 1000
  7.  
  8. function Marine:LookAtPoint(toPoint, direct)
  9.  
  10.     local player = self
  11.  
  12.     // compute direction to target
  13.     local diff = toPoint - player:GetEyePos()
  14.     local direction = GetNormalizedVector(diff)
  15.    
  16.     // look at target
  17.     if direct then
  18.         self.move.yaw = GetYawFromVector(direction) - player.baseYaw
  19.     else
  20.         local turnSpeed = ConditionalValue(player:isa("Alien"), .8, .4)
  21.         self.move.yaw = SlerpRadians(self.move.yaw, GetYawFromVector(direction) - player.baseYaw, turnSpeed)
  22.     end
  23.     self.move.pitch = GetPitchFromVector(direction) - player.basePitch
  24.     //self.move.pitch = SlerpRadians(self.move.pitch, GetPitchFromVector(direction) - player.basePitch, .4)
  25.    
  26. end
  27.  
  28. function Marine:OverrideInput(input)
  29.  
  30.     -- input.commands = bit.bor(input.commands, Move.PrimaryAttack)
  31.     if (bit.band(input.commands, Move.SecondaryAttack) ~= 0) then
  32.         input.commands = bit.band(input.commands, bit.bnot(Move.SecondaryAttack))
  33.         if (self.GetOrigin ~= nil) then
  34.             local origin = self:GetOrigin()
  35.             local eyepos = GetEntityEyePos(self)
  36.             local ents = GetEntitiesWithinRangeInView("Player", range, self)
  37.            
  38.             Shared.Message(string.format("Got %d ents", table.getn(ents)))
  39.             local bestEnt = nil
  40.             local bestFOV = 180
  41.             for k,v in pairs(ents) do
  42.                 local targetent = v
  43.                 if targetent.GetTeamNumber ~= nil then
  44.                     -- teamfire vs enemyfire
  45.                     if self:GetTeamNumber() ~= targetent:GetTeamNumber() then
  46.                         local targetOrigin = (HasMixin(targetent, "Target") and targetent:GetEngagementPoint()) or targetent:GetOrigin()
  47.                         local toTarget = eyepos - targetOrigin
  48.                         toTarget = GetNormalizedVector(toTarget)
  49.                         local yawToTarget = GetYawFromVector(toTarget)
  50.                         local pitchToTarget = GetPitchFromVector(toTarget)
  51.                        
  52.                         -- Shared.Message(string.format("Pitch: %f Yaw: %f", pitchToTarget, yawToTarget))
  53.                         local viewVector = -GetEntityViewAngles(self):GetCoords().zAxis
  54.                         local dotProduct = toTarget:DotProduct(viewVector)
  55.                         local angularDistance = math.acos(dotProduct) * 57
  56.                         Shared.Message(string.format("angularDistance: %f", angularDistance))
  57.                         if angularDistance < bestFOV then
  58.                             bestFOV = angularDistance
  59.                             bestEnt = targetent
  60.                         end
  61.                     end
  62.                 end
  63.             end
  64.             if bestFOV > kSetFOV then bestEnt = nil end
  65.             if bestEnt ~= nil then
  66.                 local targetOrigin = bestEnt.boneCoords:Get(0) -- (HasMixin(bestEnt, "Target") and bestEnt:GetEngagementPoint()) or bestEnt:GetOrigin()
  67.                 local vTargetVector = targetOrigin - eyepos
  68.                 local targetLength = vTargetVector:GetLength()
  69.                
  70.                 local invCoords = self:GetAngles():GetCoords():GetInverse()
  71.                 local relativeTargetDirection = GetNormalizedVector( invCoords:TransformVector( vTargetVector ) )
  72.                
  73.                
  74.                 local targetent = bestEnt
  75.                 local targetOrigin = (HasMixin(targetent, "Target") and targetent:GetEngagementPoint()) or targetent:GetOrigin()
  76.                 local toTarget = eyepos - targetOrigin
  77.                 toTarget = GetNormalizedVector(toTarget)
  78.                 local yawToTarget = GetYawFromVector(toTarget)
  79.                 local pitchToTarget = GetPitchFromVector(toTarget)
  80.                
  81.                 Shared.Message(string.format("[B] Pitch: %f Yaw: %f", pitchToTarget, yawToTarget))
  82.                
  83.                
  84.                
  85.                 input.pitch = math.asin(-vTargetVector.y/targetLength)
  86.                 input.yaw = yawToTarget -math.pi--math.atan(vTargetVector.x/vTargetVector.z)
  87.                 -- if input.yaw > 0 then input.yaw = input.yaw + math.pi end
  88.                 self:SetAngles(Angles(0, input.yaw, 0))
  89.             end
  90.            
  91.             -- local targetOrigin = (HasMixin(target, "Target") and target:GetEngagementPoint()) or target:GetOrigin()
  92.            
  93.             -- local dotProduct = self:GetCoords().zAxis:DotProduct(toTarget)
  94.            
  95.             -- target is enemy, alive, in range and in fov
  96.             -- if fov == 360 or math.acos(dotProduct) >= math.rad(self:GetMixinConstants().kFov / 2) then
  97.            
  98.         end
  99.     end
  100.     if (self.GetOrigin ~= nil) then
  101.         local origin = self:GetOrigin()
  102.         local barrelPoint = self:GetEyePos()
  103.         if (self.GetCrossHairTarget ~= nil) then
  104.             local target = self:GetCrossHairTarget()
  105.             if target ~= nil then
  106.                 if target.GetTeamNumber ~= nil then
  107.                     -- teamfire vs enemyfire
  108.                     if self:GetTeamNumber() == target:GetTeamNumber() then
  109.                         if (trigger == true) then
  110.                             input.commands = bit.bor(input.commands, Move.PrimaryAttack)
  111.                         end
  112.                     end
  113.                 end
  114.             end
  115.         end
  116.     end
  117. end
  118.  
  119. local function OnCommandS(_pitch, _yaw)
  120.     local command = ""
  121.     local pitch = tonumber(_pitch)
  122.     local yaw = tonumber(_yaw)
  123.     Client.GetLocalPlayer():SetAngles(Angles(pitch, yaw, 0))
  124.     --desiredPitch = pitch
  125.     --desiredYaw = yaw
  126.     Client.GetLocalPlayer():SetViewAngles(Angles(pitch, yaw, 0))
  127. end
  128. Event.Hook("Console_s", OnCommandS)
  129.  
  130. local function OnCommandBones()
  131.  
  132.     local boneValues = { }
  133.     local boneCoords = Client.GetLocalPlayer().boneCoords
  134.    
  135.     for i = 0,boneCoords:GetSize() - 1 do
  136.         local coords = boneCoords:Get(i)
  137.         local coordsName = "coords[" .. i .. "]"
  138.         boneValues[coordsName .. ".origin.x"] = coords.origin.x
  139.         boneValues[coordsName .. ".origin.y"] = coords.origin.y
  140.         boneValues[coordsName .. ".origin.z"] = coords.origin.z            
  141.     end
  142.     for k,v in pairs(boneValues) do
  143.         Shared.Message(k .. " : " .. v)
  144.     end
  145. end
  146. Event.Hook("Console_b", OnCommandBones)
  147.  
  148. local function OnCommandF(...)
  149.     local command = ""
  150.     for i, p in ipairs({...}) do
  151.         command = command .. " " .. p
  152.     end
  153.     if command == "on" then
  154.         trigger = true
  155.     elseif command == off then
  156.         trigger = false
  157.     else
  158.         trigger = not trigger
  159.     end
  160. end
  161. Event.Hook("Console_f", OnCommandF)
Advertisement
Add Comment
Please, Sign In to add comment