Introduction to Weapons: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Clockwork
No edit summary
>Clockwork
No edit summary
(No difference)

Revision as of 18:29, 25 June 2007


This is a Basic, Weapon related tutorial.


Introduction

This is a basic beginner's introduction to weapons. It explains to you the structure of weapons and why they work.

Weapon Structure

The structure of a weapon looks something like this.

[Tool Name]
  |-Sounds
  |-Weapon Script
  |-Projectile Script
  |-Local Gui
  |-Handle
  |   |-Mesh

The next few sections explain what this is.

Tool

The tool is the big thing at the top. It goes into people's backpacks and shows up in their screen. Tools have scripts, parts, and meshes that direct what the tool does. The only thing you really need to change in the tool is the name and the GripPos if you're trying to change how the player grips the weapon.

Handle

The handle is the part that contains the mesh. Meshes can't be put into the game except under a part that defines its general shape (called the bounding box). The handle is the part that has a mesh in it that shows what the weapon looks like. Each weapon has its own mesh that it uses. Usually, if you want to make a new weapon, you should copy another existing weapon and change the script only so that you don't have to copy the mesh URLs and GripPos on the tool over.

Weapon Script

The weapon script is usually called something related to the weapon name, such as "Server Launcher" for the Rocket Launcher and "Slingshot" for the slingshot. It dictates what the weapon does when its fired.

Projectile Script

The projectile script is attached to the projectile and handles what the projectile does when it flies out of the weapon. Usually it just handles what happens when it hits something.

Local Gui

The Local Gui is a LocalScript that deals with cursors on the client. It changes the cursor to a target when you switch to a weapon and adds the "reloading" text onto the cursor after firing. Usually there is nothing that needs to be changed in this script except for the reload time.

Sounds

You can't add sounds to your weapon, but you can take sounds from the other weapons.

How does the weapon work?

Here's a step by step process of what happens when you select and use the rocket launcher. The rocket launcher tree looks like this:

[LinkedRocketLauncher]
  |-Explosion - Sound
  |-Swoosh - Sound
  |-RocketScript - Projectile Script
  |-Server Launcher - Weapon Script
  |-Local Gui
  |-Handle
  |   |-Mesh


Client Script
Select the rocket from your weapons. Local Gui:
Tool.Equipped:connect(onEquippedLocal)
This adds a listener that changes the cursor to a target cursor. The listener waits for "Equipped" and then goes to the "onEquippedLocal" function.
mouse.Icon = "rbxasset://textures\\GunCursor.png"

The function changes the mouse icon.

Click on a target. Local Gui:

The onButton1Down function has a Debounce system that keeps it from repeatedly activating.

mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"  
wait(12)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
Changes the cursor to "reloading," waits until the weapon is done reloading (12 seconds) and then changes the cursor back to the regular one.

Server Launcher:

The script at the top makes the rocket but it doesn't fire it yet.
script.Parent.Activated:connect(onActivated)
This causes "onActivated" to run when the script.Parent, or the Rocket Launcher, is run. onActivated uses Debounce as well.
local targetPos = humanoid.TargetPoint
fire(targetPos)
This gets what the target is and then calls the fire function that will actually shoot the rocket. I won't go into what the fire function actually does, but the key things are:
local missile = Rocket:clone()
missile.RocketScript.Disabled = false
missile.Parent = game.Workspace

This makes a new missile from the Rocket at the top, activates its script (the projectile script) and puts it into the game.

Rocket flies out and makes a whooshing noise. RocketScript:
swoosh:play()

This will play the sound that the rocket makes.

fly()

This causes the rocket to keep flying forward without falling due to gravity.

RocketScript:

Rocket hits target, explodes, and blows up a person.

connection = shaft.Touched:connect(blow)

This causes the rocket to blow up when it touches something by calling the blow function.

explosion = Instance.new("Explosion")
explosion.Position = shaft.Position
explosion.Parent = game.Workspace

This makes the explosion.