Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.Load("../ns2/lua/Marine.lua")
- local trigger = false
- local kSetFOV = 40
- local range = 1000
- function Marine:LookAtPoint(toPoint, direct)
- local player = self
- // compute direction to target
- local diff = toPoint - player:GetEyePos()
- local direction = GetNormalizedVector(diff)
- // look at target
- if direct then
- self.move.yaw = GetYawFromVector(direction) - player.baseYaw
- else
- local turnSpeed = ConditionalValue(player:isa("Alien"), .8, .4)
- self.move.yaw = SlerpRadians(self.move.yaw, GetYawFromVector(direction) - player.baseYaw, turnSpeed)
- end
- self.move.pitch = GetPitchFromVector(direction) - player.basePitch
- //self.move.pitch = SlerpRadians(self.move.pitch, GetPitchFromVector(direction) - player.basePitch, .4)
- end
- function Marine:OverrideInput(input)
- -- input.commands = bit.bor(input.commands, Move.PrimaryAttack)
- if (bit.band(input.commands, Move.SecondaryAttack) ~= 0) then
- input.commands = bit.band(input.commands, bit.bnot(Move.SecondaryAttack))
- if (self.GetOrigin ~= nil) then
- local origin = self:GetOrigin()
- local eyepos = GetEntityEyePos(self)
- local ents = GetEntitiesWithinRangeInView("Player", range, self)
- Shared.Message(string.format("Got %d ents", table.getn(ents)))
- local bestEnt = nil
- local bestFOV = 180
- for k,v in pairs(ents) do
- local targetent = v
- if targetent.GetTeamNumber ~= nil then
- -- teamfire vs enemyfire
- if self:GetTeamNumber() ~= targetent:GetTeamNumber() then
- local targetOrigin = (HasMixin(targetent, "Target") and targetent:GetEngagementPoint()) or targetent:GetOrigin()
- local toTarget = eyepos - targetOrigin
- toTarget = GetNormalizedVector(toTarget)
- local yawToTarget = GetYawFromVector(toTarget)
- local pitchToTarget = GetPitchFromVector(toTarget)
- -- Shared.Message(string.format("Pitch: %f Yaw: %f", pitchToTarget, yawToTarget))
- local viewVector = -GetEntityViewAngles(self):GetCoords().zAxis
- local dotProduct = toTarget:DotProduct(viewVector)
- local angularDistance = math.acos(dotProduct) * 57
- Shared.Message(string.format("angularDistance: %f", angularDistance))
- if angularDistance < bestFOV then
- bestFOV = angularDistance
- bestEnt = targetent
- end
- end
- end
- end
- if bestFOV > kSetFOV then bestEnt = nil end
- if bestEnt ~= nil then
- local targetOrigin = bestEnt.boneCoords:Get(0) -- (HasMixin(bestEnt, "Target") and bestEnt:GetEngagementPoint()) or bestEnt:GetOrigin()
- local vTargetVector = targetOrigin - eyepos
- local targetLength = vTargetVector:GetLength()
- local invCoords = self:GetAngles():GetCoords():GetInverse()
- local relativeTargetDirection = GetNormalizedVector( invCoords:TransformVector( vTargetVector ) )
- local targetent = bestEnt
- local targetOrigin = (HasMixin(targetent, "Target") and targetent:GetEngagementPoint()) or targetent:GetOrigin()
- local toTarget = eyepos - targetOrigin
- toTarget = GetNormalizedVector(toTarget)
- local yawToTarget = GetYawFromVector(toTarget)
- local pitchToTarget = GetPitchFromVector(toTarget)
- Shared.Message(string.format("[B] Pitch: %f Yaw: %f", pitchToTarget, yawToTarget))
- input.pitch = math.asin(-vTargetVector.y/targetLength)
- input.yaw = yawToTarget -math.pi--math.atan(vTargetVector.x/vTargetVector.z)
- -- if input.yaw > 0 then input.yaw = input.yaw + math.pi end
- self:SetAngles(Angles(0, input.yaw, 0))
- end
- -- local targetOrigin = (HasMixin(target, "Target") and target:GetEngagementPoint()) or target:GetOrigin()
- -- local dotProduct = self:GetCoords().zAxis:DotProduct(toTarget)
- -- target is enemy, alive, in range and in fov
- -- if fov == 360 or math.acos(dotProduct) >= math.rad(self:GetMixinConstants().kFov / 2) then
- end
- end
- if (self.GetOrigin ~= nil) then
- local origin = self:GetOrigin()
- local barrelPoint = self:GetEyePos()
- if (self.GetCrossHairTarget ~= nil) then
- local target = self:GetCrossHairTarget()
- if target ~= nil then
- if target.GetTeamNumber ~= nil then
- -- teamfire vs enemyfire
- if self:GetTeamNumber() == target:GetTeamNumber() then
- if (trigger == true) then
- input.commands = bit.bor(input.commands, Move.PrimaryAttack)
- end
- end
- end
- end
- end
- end
- end
- local function OnCommandS(_pitch, _yaw)
- local command = ""
- local pitch = tonumber(_pitch)
- local yaw = tonumber(_yaw)
- Client.GetLocalPlayer():SetAngles(Angles(pitch, yaw, 0))
- --desiredPitch = pitch
- --desiredYaw = yaw
- Client.GetLocalPlayer():SetViewAngles(Angles(pitch, yaw, 0))
- end
- Event.Hook("Console_s", OnCommandS)
- local function OnCommandBones()
- local boneValues = { }
- local boneCoords = Client.GetLocalPlayer().boneCoords
- for i = 0,boneCoords:GetSize() - 1 do
- local coords = boneCoords:Get(i)
- local coordsName = "coords[" .. i .. "]"
- boneValues[coordsName .. ".origin.x"] = coords.origin.x
- boneValues[coordsName .. ".origin.y"] = coords.origin.y
- boneValues[coordsName .. ".origin.z"] = coords.origin.z
- end
- for k,v in pairs(boneValues) do
- Shared.Message(k .. " : " .. v)
- end
- end
- Event.Hook("Console_b", OnCommandBones)
- local function OnCommandF(...)
- local command = ""
- for i, p in ipairs({...}) do
- command = command .. " " .. p
- end
- if command == "on" then
- trigger = true
- elseif command == off then
- trigger = false
- else
- trigger = not trigger
- end
- end
- Event.Hook("Console_f", OnCommandF)
Advertisement
Add Comment
Please, Sign In to add comment