Files
PlaneBuilding/scripts/modules/BulletModule.lua
T

91 lines
3.0 KiB
Lua

if _G.IsClient then
local module = {}
function module.fire(barrel)
spawn(function()
local bullet = _G.Remotes.Shoot:InvokeServer(barrel)
bullet = game.Workspace:WaitForChild(bullet)
if not bullet then return end
bullet.CFrame = barrel.CFrame * CFrame.Angles(0,math.rad(-90),0)
bullet.Velocity = bullet.CFrame.LookVector * 1000
--bullet.BodyVelocity.Velocity = bullet.Velocity
end)
end
return module
elseif _G.IsServer then
-- SERVER-SIDE
function touched(touched,team,player,bullet,barrel)
if not touched or not touched.Parent then return end
local humanoid = touched.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if humanoid.Parent:FindFirstChild("Team") and humanoid.Parent.Team.Value == game.Teams.Loon then
humanoid.Health = humanoid.Health - 25
bullet:Destroy()
end
end
local object
local part
if touched.Parent:IsA("Model") and touched.Parent:HasTag("Combat") then
object = touched.Parent
part = object.PrimaryPart
else
part = touched
object = touched
end
if object:HasTag("Combat") then
if not object:HasTag("P_"..player.UserId) then
if not object:GetAttribute("Health") then
local max = part.Size.Magnitude/1.5
if object:IsA("Model") then max = object:GetExtentsSize().Magnitude/1.5 end
object:SetAttribute("Health",max)
object:SetAttribute("MaxHealth",max)
end
local health = object:GetAttribute("Health")
local max = object:GetAttribute("MaxHealth")
health = health - 3
--part.Transparency = 1-(health/max)
if barrel.BlastPressure.Value ~= -1 then
local explosion = Instance.new("Explosion")
explosion.BlastPressure = barrel.BlastPressure.Value
explosion.DestroyJointRadiusPercent = barrel.Destruction.Value
explosion.Parent = part
explosion.Position = part.Position
end
object:SetAttribute("Health",health)
if health < 0 then
_G.Methods.break_part(object,player)
object.Parent = game.Workspace.Hidden -- stop busted mechanics please
end
bullet:Destroy()
end
end
end
function fire(barrel,team,player)
if not barrel then return end
local bullet = _G.Storage[barrel.Parent.Name.."Bullet"]:Clone()
delay(1.8,function() if bullet and bullet.Parent then bullet:Destroy() end end)
bullet.CFrame = CFrame.new(0,1000000000,0)
bullet.Parent = game.Workspace
local connection = bullet.Touched:Connect(function(part)
touched(part,team,player,bullet,barrel)
end)
bullet.CFrame = barrel.CFrame * CFrame.Angles(0,math.rad(-90),0)
bullet.Velocity = bullet.CFrame.LookVector * 1000
bullet.Anchored = false
bullet:SetAttribute("Team",team.Name)
if player then
bullet:SetNetworkOwner(player) --[[delay(0,function() bullet:SetNetworkOwnershipAuto() end)]]
bullet:SetAttribute("Owner",player.UserId)
end
bullet:FindFirstChildWhichIsA("Sound"):Play()
bullet.Name = bullet.Name .. tostring(math.random(1,1000000))
return bullet.Name
end
_G.Remotes.Shoot.OnServerInvoke = function(player,barrel) return fire(barrel,player.Team,player) end
return getfenv()
end