Could someone make thsi scipt of a gun shoot automatically?
#1
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)
Reply
#2
(08-07-2011, 05:49 PM)Slender_man Wrote: 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)

anyone :l?
Reply
#3
I'm slenderman :U

But anyway, what do you mean by automatic..?
Reply
#4
I think he means convert it.
[Image: 76561198037039305.png]
[Image: nmdd7o.gif]
Reply
#5
(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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)