• My first SWEP help me?
    0 replies, posted
So I have made my first SWEP, this is also my first script. It does not work? What is wrong about it? Could somebody explain? Also how do I run it properly afterwards? This contains the shared.lua [CODE]// SWEP Info,contact ect ect... SWEP.Author = "DizzyGhost" // Your name. SWEP.Contact = "Derpfak@gmail.com" // Your E-mail adress. SWEP.Purpose = "Shoot computers to kill." // Purpose of the SWEP. SWEP.Instructions = "Press the left mouse button to shoot computers!" // 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" --------------------------------------------------------------------------------------------------------- // Who can see the SWEP in the Q menu?. SWEP.Spawnable = true -- If regular players can see the SWEP in the Q Menu. SWEP.AdminSpawnable = true -- If Admins can see the SWEP in the Q Menu. --------------------------------------------------------------------------------------------------------- // SWEP Models. SWEP.ViewModel = "v_physcannon.mdl" -- V_ = View model when you wield it. SWEP.WorldModel = "weapons/w_physics.mdl" -- W_ = World model when you see it on the ground. --------------------------------------------------------------------------------------------------------- //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" --------------------------------------------------------------------------------------------------------- //When the script loads, the sound ''Metal.SawbladeStick'' will be precached, //and a local variable with the sound name created. local ShootSound = Sound("Breakable.Metal") --------------------------------------------------------------------------------------------------------- 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:EmiteSound(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(ohys)) 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 SWEP:PrimaryAttack() //Call the throw attack function, with the office chair model self:throw_attack("models/props_lab/monitor02.mdl") end [/CODE] Keep In mind i typed all that over and readed it properly so I could get it more into my head. [editline]26th July 2012[/editline] I noticed that I typed the world and view models of the weapon wrong so fixed that in my real script. Also I jsut started lua and I don't understand half of it.
Sorry, you need to Log In to post a reply to this thread.