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
- Script.bulletspeed=200--float "Bullet speed"
- 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.emitter=Emitter:Create()
- self.emitter:SetCollisionType(Collision.Prop)--Enables particle bouncing
- self.emitter:SetMaterial("Materials/Effects/tracer1.mat")
- self.emitter:SetScale(1,5,1)
- self.emitter:SetRotation(90,180,0)
- self.emitter:SetEmissionVolume(0.05,0.05,0.05)
- self.emitter:SetRotationByVelocityMode(true)
- self.emitter:SetEmissionVolume(0,0,0)
- self.emitter:SetVelocity(0,0,20)
- self.emitter:SetParticleCount(1)
- self.emitter:SetReleaseQuantity(5)
- self.emitter:SetAcceleration(0,0,0)
- self.emitter:Hide()
- self.emitter:SetParent(self.entity)
- self.local1 = self.entity:GetRotation()
- self.muzzleFlashLight = self.entity:FindChild("MuzzleLight")
- self.muzzle = self.entity:FindChild("muzzle")
- self.emitter:SetPosition(self.muzzle:GetPosition())
- 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()
- self.emitter:Reset()
- self.emitter:Play()
- end
- function Script:UpdateShooting()
- self.fireRateTimer =self.fireRateTimer +(Time:GetSpeed()/100)
- self.muzzleTimer =self.muzzleTimer +(Time:GetSpeed()/100)
- if self.target ~= -1 and self.target ~= nil then
- if(self.fireRateTimer > self.fireRate) then
- self.muzzleFlashLight:Show()
- self.muzzleTimer=0
- self.fireRateTimer=0
- local d = Transform:Normal(0,0,1,self.muzzle,nil)
- local d = Vec3(math.random(-1,1),math.random(-1,1),math.random(-1,1))
- d = d:Normalize()
- local p=self.muzzle:GetPosition(true)
- self:Shoot(p,d*self.bulletspeed)
- end
- end
- if(self.muzzleTimer > self.muzzleTime) then
- self.muzzleFlashLight:Hide()
- end
- end
- function Script:UpdatePhysics()
- self:UpdateShooting()
- 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()
- if self.target~=-1 and self.target~= nil then if self.entity:GetPosition():DistanceToPoint(self.target:GetPosition())>30 then
- self.target=-1
- world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
- end
- end
- -- world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
- --self.entity:Point(self.target, 2, Time:GetSpeed() * self.rotSpeed)
- if self.target~=-1 and self.target~= nil 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
- --]]
- function Script:Release()
- if self.emitter~=nil then
- self.emitter:Release()
- self.emitter=nil
- end
- end
- function Script:Cleanup()
- self.tracer:Release()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement