Well, my friend tried helping me with this.
I'm trying to make a SWEP that should move a prop, but yet it doesn't do anything.
[lua]
SWEP.PrintName = "Dangerous Prop Pusher" // your sweps name
SWEP.Author = "Persious" // Your name
SWEP.AdminSpawnable = false // Is the swep spawnable for admin
SWEP.Spawnable = false // Can everybody spawn this swep ? - If you want only admin keep this false and adminsapwnable true.
SWEP.ViewModelFOV = 64 // How much of the weapon do u see ?
SWEP.ViewModel = "models/weapons/v_pistol.mdl" // The viewModel, the model you se when you are holding it-.-
SWEP.WorldModel = "models/weapons/w_pistol.mdl" // The worlmodel, The model yu when it's down on the ground
SWEP.AutoSwitchTo = false // when someone walks over the swep, chould i automatectly change to your swep ?
SWEP.AutoSwitchFrom = true // Does the weapon get changed by other sweps if you pick them up ?
SWEP.Slot = 1 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.SlotPos = 1 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.HoldType = "Pistol" // How the swep is hold Pistol smg greanade melee
SWEP.FiresUnderwater = true // Does your swep fire under water ?
SWEP.Weight = 5 // Chose the weight of the Swep
SWEP.DrawCrosshair = true // Do you want it to have a crosshair ?
SWEP.DrawAmmo = true // Does the ammo show up when you are using it ? True / False
SWEP.ReloadSound = "sound/bill_reloading.wav" // Reload sound, you can use the default ones, or you can use your one; Example; "sound/myswepreload.waw"
SWEP.base = "weapon_base"
SWEP.Primary.Sound = "sound/fire_gun_test.wav"
SWEP.Primary.Damage = 0
SWEP.Primary.TakeAmmo = 1
SWEP.Primary.ClipSize = 30 // The clipsize
SWEP.Primary.Ammo = "Pistol" // ammmo type pistol/ smg1
SWEP.Primary.DefaultClip = 30 // How much ammo does the swep come with `?
SWEP.Primary.Spread = 0.1 // Does the bullets spread all over, if you want it fire exactly where you are aiming leave it o.1
SWEP.Primary.NumberofShots = 1 // How many bullets you are firing each shot.
SWEP.Primary.Automatic = false // Is the swep automatic ?
SWEP.Primary.Recoil = 10 // How much we should punch the view
SWEP.Primary.Delay = 3 // How long time before you can fire again
SWEP.Primary.Force = 1000 // The force of the shot
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
self:SetWeaponHoldType( self.HoldType )
end
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local ent = self.Owner:GetEyeTrace().Entity
if !ent:IsValid() then return end
if !ent:GetClass() == "worldspawn" then return end
if !ent:GetPhysicsObject():IsValid() then return end
if !ent:GetMoveType() == MOVETYPE_VPHYSICS then return end
if ent:IsPlayer() then return end
ent:GetPhysicsObject():ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * 600)
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
local rnda = self.Primary.Recoil * -1
local rndb = self.Primary.Recoil * math.random(-1, 1)
self:ShootEffects()
self:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
end
[/lua]
It says if the entity is not not worldspawn then do stuff
Well, it's for props.
Shouldn't [lua]if !ent:GetClass() == "worldspawn"[/lua] be [lua]if ent:GetClass() != "worldspawn"[/lua]
Last I remember, if you did it how you have it now, it doesn't run properly. That line doesn't make sense anyway..
Well, I'm new to SWEP's so I'll try what you told me.
[editline]1st May 2011[/editline]
I tried that, but it still doesn't do anything.
[editline]1st May 2011[/editline]
gotskilz4u helped me a bit, and made this for me:
[lua]
local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*80)
tracedata.filter = {self, self.Owner}
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
local phys = trace.Entity:GetPhysicsObject()
if ValidEntity(phys) then
phys:ApplyForceCenter(ang * 8000*100)
end
end
[/lua]
That makes me move, but not the prop. Any clues?
That's not what I sent you.
thats way to ugly to be his
Well you sent me this:
[lua]
local phys = trace.Entity:GetPhysicsObject()
if ValidEntity(phys) then
phys:ApplyForceCenter(ang * 8000*100)
end
[/lua]
And I asked if that trace was the right thing to do and you said yes.
This is what I got now:
[lua]
local ent = self.Owner:GetEyeTrace().Entity
if !ent:IsValid() then return end
if !ent:GetPhysicsObject():IsValid() then return end
if !ent:GetMoveType() == MOVETYPE_VPHYSICS then return end
if ent:IsPlayer() then return end
local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*80)
tracedata.filter = {self, self.Owner}
local trace = util.TraceLine(tracedata)
local phys = trace.Entity:GetPhysicsObject()
if ValidEntity(phys) then
phys:ApplyForceCenter(ang * 8000*100)
end
[/lua]
But it returns
[@gamemodes\test\entities\weapons\test_gun\shared.lua:66] Tried to use a NULL entity!
[editline]1st May 2011[/editline]
I'm shooting at a container, but still returns the same.
[editline]1st May 2011[/editline]
Works now. Thanks gotskilz4u.
[QUOTE=Persious;29538463]Well, it's for props.[/QUOTE]
Yeah, and props are [b]not[/b] worldspawn, not [b]not not[/b] worldspawn.
[editline]2nd May 2011[/editline]
[QUOTE=Fleamonji;29539231]Shouldn't [lua]if !ent:GetClass() == "worldspawn"[/lua] be [lua]if ent:GetClass() != "worldspawn"[/lua]
Last I remember, if you did it how you have it now, it doesn't run properly. That line doesn't make sense anyway..[/QUOTE]
Thats what I meant.
Sorry, you need to Log In to post a reply to this thread.