What annoys you.
#38
(05-19-2014, 02:51 PM)roach Wrote: People who claim to code and literally just copy and paste everything for the Gmod wiki.

I'm a crazy good coder, look at this! Not from wiki, k?



Spoiler :
if SERVER then // This is where the init.lua stuff goes.

//This makes sure clients download the file
AddCSLuaFile ("shared.lua")

//How heavy the SWep is
SWEP.Weight = 5

//Allow automatic switching to/from this weapon when weapons are picked up
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

elseif CLIENT then // This is where the cl_init.lua stuff goes

//The name of the SWep, as appears in the weapons tab in the spawn menu(Q Menu)
SWEP.PrintName = "Chair throwing gun"

//Sets the position of the weapon in the switching menu
//(appears when you use the scroll wheel or keys 1-6 by default)
SWEP.Slot = 4
SWEP.SlotPos = 1

//Sets drawing the ammuntion levels for this weapon
SWEP.DrawAmmo = false

//Sets the drawing of the crosshair when this weapon is deployed
SWEP.DrawCrosshair = false

//Ensures a clean looking notification when a chair is undone. How it works:
//When you create an undo, you specify the ID:
// undo.Create("Some_Identity")
//By creating an associated language, we can make the undo notification look better:
// language.Add("Undone_Some_Identity", "Some message...")

language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity")
end

SWEP.Author = "Your Name"
SWEP.Contact = "Your Email Address"
SWEP.Purpose = "What your SWep does."
SWEP.Instructions = "How to operate your SWep"

//The category that you SWep will be shown in, in the Spawn (Q) Menu
//(This can be anything, GMod will create the categories for you)
SWEP.Category = "Category"

SWEP.Spawnable = true -- Whether regular players can see it
SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it

SWEP.ViewModel = "models/weapons/v_RPG.mdl" -- This is the model used for clients to see in first person.
SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl" -- This is the model shown to all other clients and in third-person.


//This determins how big each clip/magazine for the gun is. You can
//set it to -1 to disable the ammo system, meaning primary ammo will
//not be displayed and will not be affected.
SWEP.Primary.ClipSize = -1

//This sets the number of rounds in the clip when you first get the gun. Again it can be set to -1.
SWEP.Primary.DefaultClip = -1

//Obvious. Determines whether the primary fire is automatic. This should be true/false
SWEP.Primary.Automatic = false

//Sets the ammunition type the gun uses, see below for a list of types.
SWEP.Primary.Ammo = "none"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

//When the script loads, the sound ''Metal.SawbladeStick'' will be precached,
//and a local variable with the sound name created.
local ShootSound = Sound("Metal.SawbladeStick")

function SWEP:Reload()
end

function SWEP:Think()
end


function SWEP:throw_attack (model_file)
//Get an eye trace. This basically draws an invisible line from
//the players eye. This SWep makes very little use of the trace, except to
//calculate the amount of force to apply to the object thrown.
local tr = self.Owner:GetEyeTrace()

//Play some noises/effects using the sound we precached earlier
self:EmitSound(ShootSound)
self.BaseClass.ShootEffects(self)

//We now exit if this function is not running serverside
if (!SERVER) then return end

//The next task is to create a physics prop based on the supplied model
local ent = ents.Create("prop_physics")
ent:SetModel(model_file)

//Set the initial position and angles of the object. This might need some fine tuning;
//but it seems to work for the models I have tried.
ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles(self.Owner:EyeAngles())
ent:Spawn()

//Now we need to get the physics object for our entity so we can apply a force to it
local phys = ent:GetPhysicsObject()

//Check if the physics object is valid. If not, remove the entity and stop the function
if !(phys && IsValid(phys)) then ent:Remove() return end

//Time to apply the force. My method for doing this was almost entirely empirical
//and it seems to work fairly intuitively with chairs.
phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.pow(tr.HitPos:Length(), 3))

//Now for the important part of adding the spawned objects to the undo and cleanup lists.
cleanup.Add(self.Owner, "props", ent)

undo.Create ("Thrown_SWEP_Entity")
undo.AddEntity (ent)
undo.SetPlayer (self.Owner)
undo.Finish()
end


//Throw an office chair on primary attack
function SWEPToungerimaryAttack()
//Call the throw attack function, with the office chair model
self:throw_attack("models/props/cs_office/Chair_office.mdl")
end

//Throw a wooden chair on secondary attack
function SWEP:SecondaryAttack()
//Call the throw attack function, this time with the wooden chair model
self:throw_attack("models/props_c17/FurnitureChair001a.mdl")
end


[Image: XiLkxQo.jpg]


Messages In This Thread
What annoys you. - by Chech - 05-15-2014, 09:03 PM
RE: What annoys you. - by Ms. Mudpie - 05-17-2014, 10:00 PM
RE: What annoys you. - by Joykill - 05-17-2014, 10:02 PM
RE: What annoys you. - by Chech - 05-18-2014, 12:54 AM
RE: What annoys you. - by GRiiM - 05-17-2014, 10:04 PM
RE: What annoys you. - by Barkles - 05-17-2014, 10:13 PM
RE: What annoys you. - by Verzyn - 05-17-2014, 10:38 PM
RE: What annoys you. - by TedInternationalLover - 05-17-2014, 10:39 PM
RE: What annoys you. - by Kpred - 05-17-2014, 11:22 PM
RE: What annoys you. - by Envy - 05-17-2014, 11:38 PM
RE: What annoys you. - by Enzyme - 05-18-2014, 12:57 AM
RE: What annoys you. - by yarrrs - 05-18-2014, 01:23 AM
RE: What annoys you. - by James_Gaff - 05-18-2014, 02:05 AM
RE: What annoys you. - by GRiiM - 05-18-2014, 02:24 AM
RE: What annoys you. - by Theblackshadowofgod - 05-18-2014, 02:30 AM
RE: What annoys you. - by James_Gaff - 05-18-2014, 02:31 AM
RE: What annoys you. - by Enzyme - 05-18-2014, 03:16 AM
RE: What annoys you. - by yarrrs - 05-18-2014, 03:47 AM
RE: What annoys you. - by Labrador - 05-18-2014, 04:19 AM
RE: What annoys you. - by Bowiii - 05-18-2014, 05:39 AM
RE: What annoys you. - by Prosto - 05-18-2014, 09:36 AM
RE: What annoys you. - by Adman - 05-18-2014, 09:51 AM
RE: What annoys you. - by Guy0544 - 05-19-2014, 01:40 PM
RE: What annoys you. - by Imperator - 05-19-2014, 02:49 PM
RE: What annoys you. - by Roachy - 05-19-2014, 02:51 PM
RE: What annoys you. - by bismo - 05-24-2014, 06:03 AM
RE: What annoys you. - by LoneWolf - 05-20-2014, 07:03 PM
RE: What annoys you. - by bismo - 05-20-2014, 09:14 PM
RE: What annoys you. - by TheDoctorâ„¢ - 05-20-2014, 09:22 PM
RE: What annoys you. - by GRiiM - 05-20-2014, 09:40 PM
RE: What annoys you. - by TheDoctorâ„¢ - 05-21-2014, 05:08 AM
RE: What annoys you. - by James_Gaff - 05-20-2014, 09:57 PM
RE: What annoys you. - by Bloodraptor819 - 05-23-2014, 04:43 PM
RE: What annoys you. - by tmes2000 - 05-24-2014, 03:55 AM
RE: What annoys you. - by Trains - 05-24-2014, 04:34 PM
RE: What annoys you. - by aviator - 05-24-2014, 04:37 PM
RE: What annoys you. - by GeorgeTheBoy - 05-24-2014, 06:03 PM
RE: What annoys you. - by Ciryl - 12-14-2014, 11:54 PM
RE: What annoys you. - by Buzz_Aldrin - 05-27-2014, 10:36 PM
RE: What annoys you. - by nonactive1241212 - 05-28-2014, 04:07 PM
RE: What annoys you. - by Floodify - 12-15-2014, 12:03 AM
RE: What annoys you. - by Ciryl - 12-15-2014, 12:50 AM
RE: What annoys you. - by Preditor - 12-15-2014, 12:05 AM
RE: What annoys you. - by Preditor - 12-15-2014, 12:06 AM
RE: What annoys you. - by Floodify - 12-15-2014, 12:21 AM
RE: What annoys you. - by equal - 12-15-2014, 12:48 AM
RE: What annoys you. - by TheImpossibleTruster5 - 12-15-2014, 01:06 AM
RE: What annoys you. - by Jan - 12-15-2014, 01:20 AM
RE: What annoys you. - by Vector - 12-15-2014, 01:48 AM
RE: What annoys you. - by Vauld - 12-15-2014, 02:42 AM
RE: What annoys you. - by Duane - 12-15-2014, 02:43 AM
RE: What annoys you. - by Zamar - 12-15-2014, 12:32 PM
RE: What annoys you. - by Bowiii - 12-15-2014, 02:14 PM
RE: What annoys you. - by Cujo - 12-16-2014, 08:29 PM
What annoys you. - by Obay - 12-15-2014, 02:35 PM
What annoys you. - by Smex - 12-15-2014, 02:39 PM
RE: What annoys you. - by GeorgeTheBoy - 12-15-2014, 08:19 PM
RE: What annoys you. - by Voluptious - 12-15-2014, 03:58 PM
RE: What annoys you. - by Gui - 12-15-2014, 08:50 PM
RE: What annoys you. - by Burnett - 12-15-2014, 09:42 PM
RE: What annoys you. - by General Rickets - 12-15-2014, 10:18 PM
RE: What annoys you. - by Smex - 12-15-2014, 10:42 PM
RE: What annoys you. - by ArcHammer - 12-15-2014, 11:00 PM
RE: What annoys you. - by Jonesy - 12-15-2014, 11:11 PM
RE: What annoys you. - by General Rickets - 12-15-2014, 11:14 PM
RE: What annoys you. - by Smex - 12-15-2014, 11:15 PM
RE: What annoys you. - by Jonesy - 12-15-2014, 11:18 PM
RE: What annoys you. - by Enzyme - 12-15-2014, 11:32 PM
RE: What annoys you. - by Cujo - 12-16-2014, 08:17 PM
RE: What annoys you. - by Feffe - 12-17-2014, 11:13 AM
RE: What annoys you. - by Pinky - 12-17-2014, 12:22 PM
RE: What annoys you. - by Rolorox - 12-17-2014, 09:46 PM
RE: What annoys you. - by GeorgeTheBoy - 12-17-2014, 09:50 PM
RE: What annoys you. - by Smex - 12-17-2014, 10:08 PM
RE: What annoys you. - by Enzyme - 12-18-2014, 01:49 AM
RE: What annoys you. - by Bowiii - 12-18-2014, 01:37 PM
RE: What annoys you. - by Marty - 12-18-2014, 02:59 AM
RE: What annoys you. - by Reefaz - 12-21-2014, 06:19 PM
RE: What annoys you. - by James_Gaff - 12-21-2014, 06:24 PM
RE: What annoys you. - by Decay - 12-22-2014, 09:04 AM
RE: What annoys you. - by livkx - 12-22-2014, 08:59 AM
RE: What annoys you. - by Foxy The Pirate - 12-27-2014, 10:16 AM
RE: What annoys you. - by Suarez - 12-27-2014, 10:22 AM
RE: What annoys you. - by alexxx - 12-27-2014, 10:55 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)