• Please help lua newbie make basic SWep!
    0 replies, posted
I am relatively new to lua (have experience with python, html) and I am trying to make a SWep for the AVP 2010 Predator PlayerModels addon. I would like to make a SWep which throws the BattleDisk(?) model and sticks into whatever it hits. Here is what I've got so far using a basic SWep layout with some modifications: [CODE]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 = "BattleDisk" --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 language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity") end -- =====INFO===== SWEP.Author = "dr1p" SWEP.Contact = "lmao" SWEP.Purpose = "Predator Combat Disk SWEP" SWEP.Instructions = "Sights: Line visible blade up with target" --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 = "Predator Weapons" -- =====SPAWN PERMISSION===== SWEP.Spawnable = true -- Whether regular players can see it SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it -- =====VIEW MODEL/SIGHT===== SWEP.HoldType = "knife" SWEP.ViewModelFOV = 112.56281407035 SWEP.ViewModelFlip = false SWEP.UseHands = false SWEP.ViewModel = "models/predatorbattledisc.mdl" SWEP.WorldModel = "models/predatorbattledisc.mdl" SWEP.ShowViewModel = true SWEP.ShowWorldModel = true SWEP.ViewModelBoneMods = { ["battledisc_root"] = { scale = Vector(0.996, 0.996, 0.996), pos = Vector(11.666, -8.705, -8.705), angle = Angle(-178.89, -132.223, -3.333) } } -- =====PRIMARY-FIRE SETTINGS===== SWEP.Primary.ClipSize = 10 SWEP.Primary.DefaultClip = 10 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "XBowBolt" SWEP.Primary.Damage = 100 -- =====UNUSED FUNCTIONS===== function SWEP:Reload() end function SWEP:Think() end -- =====SOUNDS===== --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") -- =====THROW FUNCTIONS===== 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 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 -- =====ATTACK FUNCTIONS===== --Throw a battledisk on primary attack function SWEP:PrimaryAttack() --Call the throw attack function, with the battledisk model self:throw_attack("models/predatorbattledisc.mdl") end [/CODE] The viewmodel spawns large and in my head, the worldmodel does not spawn, and I have no clue how to even begin to make it stick into terrain/models. Any help would be appreciated :).
Sorry, you need to Log In to post a reply to this thread.