Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.rotSpeed = 0.1
- Script.target = -1 --entity "target"
- Script.Pivot = nil
- Script.sightRadius = 10--float
- Script.fireRate= 0.5 --float "FireRat"
- Script.fireRateTimer=0
- Script.muzzleTime = 0.1
- Script.muzzleTimer=0
- Script.weapon = ""--path "Weapon"
- Script.firesoundFile = nil
- Script.local1=0
- function Script:SetNearestEnemy(pWhich)
- self.target= pWhich
- end
- function Callback(entity,extra)
- if entity:GetKeyValue("type")=="enemy" then
- extra.script:SetNearestEnemy(entity)
- end
- end
- function Script:Start()
- self.local1 = self.entity:GetRotation()
- self.muzzleFlashLight = self.entity:FindChild("MuzzleLight")
- self.muzzle = self.entity:FindChild("muzzle")
- self.muzzleFlashLight:Hide()
- if self.firesoundFile ~= "" then
- self.firesoundFile = Sound:Load(self.fireSound)
- end
- self.entity:SetPickMode(0)
- self.entity:SetRotation(self.local1)
- end
- --[[
- function Script:UpdateWorld()
- end
- --]]
- function Script:Shoot()
- local bullet = Model:Box()
- bullet:SetScale(0.1,0.1,0.1)
- bullet:SetPickMode(0)
- bullet:Hide()
- bullets = bullet:Instance()
- local avec=self.muzzle:GetPosition(true)
- bullets:SetPosition(avec.x,avec.y+2,avec.z)
- bullets:Show()
- bullets:SetMass(1)
- bullets:AddForce(0,0,-2000,false)
- end
- function Script:UpdateShooting()
- self.fireRateTimer =self.fireRateTimer +(Time:GetSpeed()/100)
- self.muzzleTimer =self.muzzleTimer +(Time:GetSpeed()/100)
- if(self.fireRateTimer > self.fireRate) then
- self.muzzleFlashLight:Show()
- self.muzzleTimer=0
- self.fireRateTimer=0
- self:Shoot()
- end
- if(self.muzzleTimer > self.muzzleTime) then
- self.muzzleFlashLight:Hide()
- end
- end
- function Script:UpdatePhysics()
- self:UpdateShooting()
- --Create an axis-aligned bounding box
- local position = self.entity:GetPosition(true)
- local aabb = AABB()
- aabb.min.x=position.x-self.sightRadius
- aabb.min.y=position.y-self.sightRadius
- aabb.min.z=position.z-self.sightRadius
- aabb.max.x=position.x+self.sightRadius
- aabb.max.y=position.y+self.sightRadius
- aabb.max.z=position.z+self.sightRadius
- aabb:Update()
- -- world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
- --self.entity:Point(self.target, 2, Time:GetSpeed() * self.rotSpeed)
- if self.target~=-1 then
- self.vector = self.target:GetPosition(true)-self.entity:GetPosition(true)
- self.entity:AlignToVector(self.vector:Normalize(),2)
- local newRot = self.entity:GetRotation(true)
- self.entity:SetRotation( Vec3( 90, -180+newRot.y, newRot.z ), true)
- else
- world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
- end
- end
- --[[
- function Script:Collision(entity, position, normal, speed)
- end
- --]]
- --[[
- function Script:Draw()
- end
- --]]
- --[[
- function Script:DrawEach(entity)
- end
- --]]
- --[[
- --This function will be called after the world is rendered, before the screen is refreshed.
- --Use this to perform any 2D drawing you want the entity to display.
- function Script:PostRender(context)
- end
- --]]
- --[[
- --This function will be called when the entity is deleted.
- function Script:Detach()
- end
- --]]
- --[[
- --This function will be called when the last instance of this script is deleted.
- function Script:Cleanup()
- end
- --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement