generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

New to filtering enabled...

Previous Thread :: Next Thread 
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:03 AM
How can i make a tool work with this? Also how can i detect when a player clicks; a click detector?
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:12 AM
bump
Report Abuse
pinballboy7 is not online. pinballboy7
Joined: 12 Mar 2009
Total Posts: 1485
13 Dec 2015 12:13 AM
The first thing to know is this:
http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial
Basically allows a localscript taking user input to give commands to a serverside script which does stuff local scripts can't.
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:14 AM
Is there a way to simplify that because:

--------------------- TEMPLATE ASSAULT RIFLE WEAPON ---------------------------
-- Waits for the child of the specified parent
local function WaitForChild(parent, childName)
while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
return parent[childName]
end

----- MAGIC NUMBERS ABOUT THE TOOL -----
-- How much damage a bullet does
local Damage = 23
-- How many times per second the gun can fire
local FireRate = 1 / 9
-- The maximum distance the can can shoot, this value should never go above 1000
local Range = 800
-- In radians the minimum accuracy penalty
local MinSpread = 0.000000001
-- In radian the maximum accuracy penalty
local MaxSpread = 0.07
-- Number of bullets in a clip
local ClipSize = 30
-- DefaultValue for spare ammo
local SpareAmmo = 300
-- The amount the aim will increase or decrease by
-- decreases this number reduces the speed that recoil takes effect
local AimInaccuracyStepAmount = 0.05
-- Time it takes to reload weapon
local ReloadTime = 2.3
----------------------------------------

-- Colors
local FriendlyReticleColor = Color3.new(0, 1, 0)
local EnemyReticleColor = Color3.new(1, 0, 0)
local NeutralReticleColor = Color3.new(1, 1, 1)

local Spread = MinSpread
local AmmoInClip = ClipSize

local Tool = script.Parent
local Handle = WaitForChild(Tool, 'Handle')
local WeaponGui = nil

local LeftButtonDown
local Reloading = false
local IsShooting = false

-- Player specific convenience variables
local MyPlayer = nil
local MyCharacter = nil
local MyHumanoid = nil
local MyTorso = nil
local MyMouse = nil

local RecoilAnim
local RecoilTrack = nil

local IconURL = Tool.TextureId -- URL to the weapon icon asset

local DebrisService = game:GetService('Debris')
local PlayersService = game:GetService('Players')


local FireSound

local OnFireConnection = nil
local OnReloadConnection = nil

local DecreasedAimLastShot = false
local LastSpreadUpdate = time()

-- this is a dummy object that holds the flash made when the gun is fired
local FlashHolder = nil


local WorldToCellFunction = Workspace.Terrain.WorldToCellPreferSolid
local GetCellFunction = Workspace.Terrain.GetCell

function RayIgnoreCheck(hit, pos)
if hit then
if hit.Transparency >= 1 or string.lower(hit.Name) == "water" or
hit.Name == "Effect" or hit.Name == "Rocket" or hit.Name == "Bullet" or
hit.Name == "Handle" or hit:IsDescendantOf(MyCharacter) then
return true
elseif hit:IsA('Terrain') and pos then
local cellPos = WorldToCellFunction(Workspace.Terrain, pos)
if cellPos then
local cellMat = GetCellFunction(Workspace.Terrain, cellPos.x, cellPos.y, cellPos.z)
if cellMat and cellMat == Enum.CellMaterial.Water then
return true
end
end
end
end
return false
end

-- @preconditions: vec should be a unit vector, and 0 < rayLength <= 1000
function RayCast(startPos, vec, rayLength)
local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * .01), vec * rayLength), Handle)
if hitObject and hitPos then
local distance = rayLength - (hitPos - startPos).magnitude
if RayIgnoreCheck(hitObject, hitPos) and distance > 0 then
-- there is a chance here for potential infinite recursion
return RayCast(hitPos, vec, distance)
end
end
return hitObject, hitPos
end



function TagHumanoid(humanoid, player)
-- Add more tags here to customize what tags are available.
while humanoid:FindFirstChild('creator') do
humanoid:FindFirstChild('creator'):Destroy()
end
local creatorTag = Instance.new("ObjectValue")
creatorTag.Value = player
creatorTag.Name = "creator"
creatorTag.Parent = humanoid
DebrisService:AddItem(creatorTag, 1.5)

local weaponIconTag = Instance.new("StringValue")
weaponIconTag.Value = IconURL
weaponIconTag.Name = "icon"
weaponIconTag.Parent = creatorTag
end


local function CreateBullet(bulletPos)
local bullet = Instance.new('Part', Workspace)
bullet.FormFactor = Enum.FormFactor.Custom
bullet.Size = Vector3.new(0.1, 0.1, 0.1)
bullet.BrickColor = BrickColor.new("Really red")
bullet.Shape = Enum.PartType.Block
bullet.CanCollide = false
bullet.CFrame = CFrame.new(bulletPos)
bullet.Anchored = true
bullet.TopSurface = Enum.SurfaceType.Smooth
bullet.BottomSurface = Enum.SurfaceType.Smooth
bullet.Name = 'Bullet'
bullet.Material = 'Neon'
DebrisService:AddItem(bullet, 2.5)
return bullet
end

local function Reload()
if not Reloading then
Reloading = true
-- Don't reload if you are already full or have no extra ammo
if AmmoInClip ~= ClipSize and SpareAmmo > 0 then
if RecoilTrack then
RecoilTrack:Stop()
end
if WeaponGui and WeaponGui:FindFirstChild('Crosshair') then
if WeaponGui.Crosshair:FindFirstChild('ReloadingLabel') then
WeaponGui.Crosshair.ReloadingLabel.Visible = true
end
end
script.Parent.Handle.Reload:Play()
wait(ReloadTime)
-- Only use as much ammo as you have
local ammoToUse = math.min(ClipSize - AmmoInClip, SpareAmmo)
AmmoInClip = AmmoInClip + ammoToUse
SpareAmmo = SpareAmmo - ammoToUse
UpdateAmmo(AmmoInClip)
WeaponGui.Reload.Visible = false
end
Reloading = false
end
end

function OnFire()
if IsShooting then return end
if MyHumanoid and MyHumanoid.Health > 0 then
if RecoilTrack and AmmoInClip > 0 then
RecoilTrack:Play()
end
IsShooting = true
while LeftButtonDown and AmmoInClip > 0 and not Reloading do
if Spread and not DecreasedAimLastShot then
Spread = math.min(MaxSpread, Spread + AimInaccuracyStepAmount)
UpdateCrosshair(Spread)
end
DecreasedAimLastShot = not DecreasedAimLastShot
if Handle:FindFirstChild('FireSound') then
Handle.FireSound:Play()
Handle.Flash.Enabled = true
end
if MyMouse then
local targetPoint = MyMouse.Hit.p
local shootDirection = (targetPoint - Handle.Position).unit
-- Adjust the shoot direction randomly off by a little bit to account for recoil
shootDirection = CFrame.Angles((0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread) * shootDirection
local hitObject, bulletPos = RayCast(Handle.Position, shootDirection, Range)
local bullet
-- Create a bullet here
if hitObject then
bullet = CreateBullet(bulletPos)
end
if hitObject and hitObject.Parent then
local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
if hitHumanoid then
local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
if MyPlayer.Neutral or (hitPlayer and hitPlayer.TeamColor ~= MyPlayer.TeamColor) then
TagHumanoid(hitHumanoid, MyPlayer)
hitHumanoid:TakeDamage(Damage)
if bullet then
bullet:Destroy()
bullet = nil
--bullet.Transparency = 1
end
Spawn(UpdateTargetHit)
end
end
end

AmmoInClip = AmmoInClip - 1
UpdateAmmo(AmmoInClip)
end
wait(FireRate)
end
Handle.Flash.Enabled = false
IsShooting = false
if AmmoInClip == 0 then
Handle.Tick:Play()
WeaponGui.Reload.Visible = true
end
if RecoilTrack then
RecoilTrack:Stop()
end
end
end

local TargetHits = 0
function UpdateTargetHit()
TargetHits = TargetHits + 1
if WeaponGui and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('TargetHitImage') then
WeaponGui.Crosshair.TargetHitImage.Visible = true
end
wait(0.5)
TargetHits = TargetHits - 1
if TargetHits == 0 and WeaponGui and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('TargetHitImage') then
WeaponGui.Crosshair.TargetHitImage.Visible = false
end
end

function UpdateCrosshair(value, mouse)
if WeaponGui then
local absoluteY = 650
WeaponGui.Crosshair:TweenSize(
UDim2.new(0, value * absoluteY * 2 + 23, 0, value * absoluteY * 2 + 23),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
0.33)
end
end

function UpdateAmmo(value)
if WeaponGui and WeaponGui:FindFirstChild('AmmoHud') and WeaponGui.AmmoHud:FindFirstChild('ClipAmmo') then
WeaponGui.AmmoHud.ClipAmmo.Text = AmmoInClip
if value > 0 and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('ReloadingLabel') then
WeaponGui.Crosshair.ReloadingLabel.Visible = false
end
end
if WeaponGui and WeaponGui:FindFirstChild('AmmoHud') and WeaponGui.AmmoHud:FindFirstChild('TotalAmmo') then
WeaponGui.AmmoHud.TotalAmmo.Text = SpareAmmo
end
end


function OnMouseDown()
LeftButtonDown = true
OnFire()
end

function OnMouseUp()
LeftButtonDown = false
end

function OnKeyDown(key)
if string.lower(key) == 'r' then
Reload()
end
end


function OnEquipped(mouse)
Handle.EquipSound:Play()
RecoilAnim = WaitForChild(Tool, 'Recoil')
FireSound = WaitForChild(Handle, 'FireSound')

MyCharacter = Tool.Parent
MyPlayer = game:GetService('Players'):GetPlayerFromCharacter(MyCharacter)
MyHumanoid = MyCharacter:FindFirstChild('Humanoid')
MyTorso = MyCharacter:FindFirstChild('Torso')
MyMouse = mouse
WeaponGui = WaitForChild(Tool, 'WeaponHud'):Clone()
if WeaponGui and MyPlayer then
WeaponGui.Parent = MyPlayer.PlayerGui
UpdateAmmo(AmmoInClip)
end
if RecoilAnim then
RecoilTrack = MyHumanoid:LoadAnimation(RecoilAnim)
end

if MyMouse then
-- Disable mouse icon
MyMouse.Icon = "http://www.roblox.com/asset/?id=18662154"
MyMouse.Button1Down:connect(OnMouseDown)
MyMouse.Button1Up:connect(OnMouseUp)
MyMouse.KeyDown:connect(OnKeyDown)
end
end


-- Unequip logic here
function OnUnequipped()
LeftButtonDown = false
Reloading = false
MyCharacter = nil
MyHumanoid = nil
MyTorso = nil
MyPlayer = nil
MyMouse = nil
if OnFireConnection then
OnFireConnection:disconnect()
end
if OnReloadConnection then
OnReloadConnection:disconnect()
end
if FlashHolder then
FlashHolder = nil
end
if WeaponGui then
WeaponGui.Parent = nil
WeaponGui = nil
end
if RecoilTrack then
RecoilTrack:Stop()
end
end

local function SetReticleColor(color)
if WeaponGui and WeaponGui:FindFirstChild('Crosshair') then
for _, line in pairs(WeaponGui.Crosshair:GetChildren()) do
if line:IsA('Frame') then
line.BorderColor3 = color
end
end
end
end


Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)

while true do
wait(0.033)
if WeaponGui and WeaponGui:FindFirstChild('Crosshair') and MyMouse then
WeaponGui.Crosshair.Position = UDim2.new(0, MyMouse.X, 0, MyMouse.Y)
SetReticleColor(NeutralReticleColor)

local target = MyMouse.Target
if target and target.Parent then
local player = PlayersService:GetPlayerFromCharacter(target.Parent)
if player then
if MyPlayer.Neutral or player.TeamColor ~= MyPlayer.TeamColor then
SetReticleColor(EnemyReticleColor)
else
SetReticleColor(FriendlyReticleColor)
end
end
end
end
if Spread and not IsShooting then
local currTime = time()
if currTime - LastSpreadUpdate > FireRate * 2 then
LastSpreadUpdate = currTime
Spread = math.max(MinSpread, Spread - AimInaccuracyStepAmount)
UpdateCrosshair(Spread, MyMouse)
end
end
end
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:31 AM
help!
Report Abuse
pinballboy7 is not online. pinballboy7
Joined: 12 Mar 2009
Total Posts: 1485
13 Dec 2015 12:37 AM
Whoa, don't expect me to read the whole script. Also, magazine, not clip.
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:42 AM
:/
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 12:54 AM
All im trying to do its get the fire sound (shooting the gun) and the bullet visible and allow them to do damage server side.
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 01:44 AM
bump
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
13 Dec 2015 01:55 AM
With RemoteEvents and RemoteFunctions, I find it game breaking to try to compensate with the latency they bring. Personally, I wouldn't use FE if you need to use weapons.
Report Abuse
Aethex is not online. Aethex
Joined: 16 Oct 2011
Total Posts: 2193
13 Dec 2015 01:58 AM
fe doesn't really have bad latency unless you use it wrong
Report Abuse
iMung is not online. iMung
Joined: 11 Jul 2013
Total Posts: 328
13 Dec 2015 02:08 AM
I can't read that entire script. If you want to detect when a player clicks. Then you do: player = game.Players.LocalPlayer Mouse = player:GetMouse() Mouse.Button1Down:connect(function() -- do stuff end) Just remember to use a localscript.
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
13 Dec 2015 02:53 AM
FE isn't laggy, but remoteEvents are.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
13 Dec 2015 03:15 AM
uh no
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
13 Dec 2015 04:29 AM
but the wiki has a whole page dedicated to it.
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 02:33 PM
@imung thats not even close to what im trying to do, its that ive never used remote events and have no idea how i would use them so that players can hurt other players etc...
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 05:21 PM
Can anyone help i cant seem to get this to work, if you need i can make a model of the weapon. I just really need help on this!
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
13 Dec 2015 05:28 PM
Have the client fire a remote event that the server responds to by damaging the player you send

--client
remoteevent:FireServer(ENEMY,DAMAGE)

--server
remoteevent.OnServerEvent:connect(function(player,ENEMY,DAMAGE)
ENEMY.Humanoid:TakeDamage(DAMAGE)
end)



#code Instance.new("BodyThrust",SenseiWarrior).position = CFrame.new(SenseiWarrior,YourGirlsDMs)
Report Abuse
Link5659 is not online. Link5659
Joined: 04 Jun 2012
Total Posts: 4525
13 Dec 2015 05:32 PM
And yet still dont understand.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image