Could someone make thsi scipt of a gun shoot automatically? - Printable Version +- 2DWorlds Forums (http://2dworlds.buildism.net/forum) +-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4) +--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13) +--- Thread: Could someone make thsi scipt of a gun shoot automatically? (/showthread.php?tid=7807) |
Could someone make thsi scipt of a gun shoot automatically? - Slender_man - 08-07-2011 This is semi-automatic but can someone make it shoot automaticly? tool = script.Parent player = tool.Parent.Parent character = player.Character body = character.Body enabled = true reloading = false ammo = 12 function showAmmo() player:message("Ammo: "..ammo) end function reload() if reloading then return end reloading = true enabled = false tool.Name = "Rocket" while ammo < 1 do sleep(0.5) ammo = ammo + 12 showAmmo() end enabled = true reloading = false end function unload() enabled = false tool.Name = "Reload" end function playSound(s) if game.AssetService:getChild(s) ~= nil and game.AssetService[s]:isA("Sound") then game.AssetService[s]:play() end end function normalizeVector(vec) local m = math.sqrt(vec.x * vec.x + vec.y * vec.y) return Vec2D(vec.x / m, vec.y / m) end function onClick(btn, pos) if btn == 1 then if not enabled then return end ammo = ammo - 1 showAmmo() if ammo <= 0 then unload() end local r = create("Box") r.Size = Vec2D(4, 0.4) r.Name="Rocket" r.Color = Color(255,255,102) r.ShowBorder = false local v = normalizeVector(Vec2D(pos.x - body.Position.x + 0.1, pos.y - body.Position.y - 1.5)) local angle = math.atan2(v.y, v.x) local c = create("FixedVelocity") c.Velocity = Vec2D(v.x * 40, v.y * 40) c.Parent = r r.Rotation = math.deg(angle) r.Position = Vec2D(body.Position.x - 0.1 + v.x * 7, body.Position.y + 1.5 + v.y * 7) local s = create("Script") s.Name = "RocketScript" s.Source = [[ exploded = false function playSound(s) if game.AssetService:getChild(s) ~= nil and game.AssetService[s]:isA("Sound") then game.AssetService[s]:play() end end rocket = script.Parent function onCollide(hit) if exploded then return end exploded = true local e = create("Explosion") e.Radius = 1 e.Position = rocket.Position e.Parent = game.World rocket:remove() playSound("") end link(rocket.Collided, onCollide) link(rocket.TerrainCollided, onCollide) ]] s.Parent = r r.Parent = game.World playSound("") if enabled then enabled = false sleep(0.1) enabled = true end end end function keyDown(k) if k == "r" then reload() end end function selected() showAmmo() end function deselected() player:message() end link(script.Parent.Selected, selected) link(script.Parent.Deselected, deselected) link(script.Parent.MouseDown, onClick) link(script.Parent.KeyDown, keyDown) RE: Could someone make thsi scipt of a gun shoot automatically? - Slender_man - 08-08-2011 (08-07-2011, 05:49 PM)Slender_man Wrote: This is semi-automatic but can someone make it shoot automaticly? anyone :l? RE: Could someone make thsi scipt of a gun shoot automatically? - Duck - 08-08-2011 I'm slenderman :U But anyway, what do you mean by automatic..? RE: Could someone make thsi scipt of a gun shoot automatically? - Fat_Sacks - 08-08-2011 I think he means convert it. RE: Could someone make thsi scipt of a gun shoot automatically? - Slender_man - 08-10-2011 (08-08-2011, 08:30 AM)Interwebs Wrote: I think he means convert it. Its cause when you shoot, It shoots like a pistol. Can you make it shoot like a machinegun? |