Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. Script.rotSpeed = 0.1
  2. Script.target = -1 --entity "target"
  3. Script.Pivot = nil
  4. Script.sightRadius = 10--float
  5. Script.fireRate= 0.5 --float "FireRat"
  6. Script.fireRateTimer=0
  7. Script.muzzleTime = 0.1
  8. Script.muzzleTimer=0
  9. Script.weapon = ""--path "Weapon"
  10. Script.firesoundFile = nil
  11.  
  12. Script.local1=0
  13. function Script:SetNearestEnemy(pWhich)
  14.         self.target= pWhich
  15. end
  16. function Callback(entity,extra)
  17.         if entity:GetKeyValue("type")=="enemy" then
  18.             extra.script:SetNearestEnemy(entity)
  19.         end
  20. end
  21.  
  22. function Script:Start()
  23.         self.local1 = self.entity:GetRotation()
  24.         self.muzzleFlashLight = self.entity:FindChild("MuzzleLight")
  25.         self.muzzle = self.entity:FindChild("muzzle")
  26.         self.muzzleFlashLight:Hide()
  27.         if self.firesoundFile ~= "" then
  28.                 self.firesoundFile = Sound:Load(self.fireSound)
  29.         end
  30.         self.entity:SetPickMode(0)
  31.         self.entity:SetRotation(self.local1)
  32. end
  33.  
  34. --[[
  35. function Script:UpdateWorld()
  36.        
  37. end
  38. --]]
  39.  
  40. function Script:Shoot()
  41.             local bullet = Model:Box()
  42.             bullet:SetScale(0.1,0.1,0.1)
  43.             bullet:SetPickMode(0)
  44.             bullet:Hide()
  45.             bullets = bullet:Instance()
  46.             local avec=self.muzzle:GetPosition(true)
  47.             bullets:SetPosition(avec.x,avec.y+2,avec.z)
  48.             bullets:Show()
  49.             bullets:SetMass(1)
  50.             bullets:AddForce(0,0,-2000,false)
  51. end
  52.  
  53. function Script:UpdateShooting()
  54.         self.fireRateTimer =self.fireRateTimer +(Time:GetSpeed()/100)
  55.         self.muzzleTimer =self.muzzleTimer +(Time:GetSpeed()/100)
  56.        
  57.         if(self.fireRateTimer > self.fireRate) then
  58.             self.muzzleFlashLight:Show()
  59.                 self.muzzleTimer=0
  60.                 self.fireRateTimer=0
  61.             self:Shoot()
  62.         end
  63.        
  64.         if(self.muzzleTimer > self.muzzleTime) then
  65.             self.muzzleFlashLight:Hide()
  66.         end
  67. end
  68. function Script:UpdatePhysics()
  69.         self:UpdateShooting()
  70.      --Create an axis-aligned bounding box
  71.         local position = self.entity:GetPosition(true)
  72.         local aabb = AABB()
  73.         aabb.min.x=position.x-self.sightRadius
  74.         aabb.min.y=position.y-self.sightRadius
  75.         aabb.min.z=position.z-self.sightRadius
  76.         aabb.max.x=position.x+self.sightRadius
  77.         aabb.max.y=position.y+self.sightRadius
  78.         aabb.max.z=position.z+self.sightRadius
  79.         aabb:Update()
  80.        
  81.       --  world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
  82.        
  83.     --self.entity:Point(self.target, 2, Time:GetSpeed() * self.rotSpeed)
  84.     if self.target~=-1 then
  85.         self.vector = self.target:GetPosition(true)-self.entity:GetPosition(true)
  86.         self.entity:AlignToVector(self.vector:Normalize(),2)
  87.         local newRot = self.entity:GetRotation(true)
  88.         self.entity:SetRotation( Vec3( 90, -180+newRot.y, newRot.z ), true)
  89.     else
  90.         world:ForEachEntityInAABBDo(aabb,"Callback",self.entity)
  91.     end
  92. end
  93. --[[
  94. function Script:Collision(entity, position, normal, speed)
  95.    
  96. end
  97. --]]
  98.  
  99. --[[
  100. function Script:Draw()
  101.    
  102. end
  103. --]]
  104.  
  105. --[[
  106. function Script:DrawEach(entity)
  107.    
  108. end
  109. --]]
  110.  
  111. --[[
  112. --This function will be called after the world is rendered, before the screen is refreshed.
  113. --Use this to perform any 2D drawing you want the entity to display.
  114. function Script:PostRender(context)
  115.    
  116. end
  117. --]]
  118.  
  119. --[[
  120. --This function will be called when the entity is deleted.
  121. function Script:Detach()
  122.    
  123. end
  124. --]]
  125.  
  126. --[[
  127. --This function will be called when the last instance of this script is deleted.
  128. function Script:Cleanup()
  129.    
  130. end
  131. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement