• 2 Questions.
    20 replies, posted
Don't ban me for undescriptive topic. 1. Prop dissapearing in 1 minute. How to do it? 2. Prop sticking to everything as entity, not as thrown with GravyGun. How to do it? Code of weapon: [code]SWEP.AdminSpawnable = true SWEP.ViewModelFOV = 80 SWEP.ViewModel = "models/weapons/XIIIArms/v_Harpoon.mdl" SWEP.WorldModel = "models/weapons/w_tomgun.mdl" SWEP.AutoSwitchTo = true SWEP.Slot = 3 SWEP.HoldType = "smg1" SWEP.PrintName = "Harpoon Rifle" SWEP.Author = "" SWEP.Spawnable = true SWEP.AutoSwitchFrom = true SWEP.FiresUnderwater = false SWEP.Weight = 5 SWEP.DrawCrosshair = true SWEP.Category = "XIII" SWEP.SlotPos = 2 SWEP.DrawAmmo = true SWEP.ReloadSound = ("v_tomgun/reload.wav") SWEP.Instructions = "" SWEP.Contact = "" SWEP.Purpose = "" SWEP.base = "weapon_base" SWEP.Primary.Sound = ("v_tomgun/machgF1b.wav") SWEP.Primary.Reload = ("v_tomgun/reload.wav") SWEP.Primary.Damage = 0 SWEP.Primary.TakeAmmo = 1 SWEP.Primary.ClipSize = 1 SWEP.Primary.Ammo = "pistol" SWEP.Primary.DefaultClip = 1 SWEP.Primary.Spread = 0 SWEP.Primary.NumberoFShots = 0 SWEP.Primary.Automatic = true SWEP.Primary.Recoil = 0.5 SWEP.Primary.Delay = 0.5 SWEP.Primary.Force = 10 //SWEP:Initialize()\\ function SWEP:Initialize() util.PrecacheSound("v_tomgun/machgF1b.wav") util.PrecacheSound("v_tomgun/reload.wav") if ( SERVER ) then self:SetWeaponHoldType( "smg1" ) end end //SWEP:Initialize()\\ function SWEP:Deploy() self.Weapon:SendWeaponAnim(ACT_VM_DRAW) end function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end 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.Owner:FireBullets( bullet ) self.Weapon:EmitSound(Sound(self.Primary.Sound)) self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) self:TakePrimaryAmmo(self.Primary.TakeAmmo) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 ) self:ThrowHarpoon( "models/weapons/XIIIArms/Harpoon.mdl" ) end function SWEP:SecondaryAttack() end function SWEP:ThrowHarpoon() if ( CLIENT ) then return end local ent = ents.Create( "prop_physics" ) if ( !IsValid( ent ) ) then return end ent:SetModel( "models/weapons/XIIIArms/Harpoon.mdl" ) ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 36 ) ) ent:SetAngles( self.Owner:EyeAngles() ) ent:Spawn() local phys = ent:GetPhysicsObject() if ( !IsValid( phys ) ) then ent:Remove() return end local velocity = self.Owner:GetAimVector() velocity = velocity * 100000 velocity = velocity + ( VectorRand() * 10 ) phys:ApplyForceCenter( velocity ) cleanup.Add( self.Owner, "props", ent ) undo.Create( "Harpoon" ) undo.AddEntity( ent ) undo.SetPlayer( self.Owner ) undo.Finish() end /*--------------------------------------------------------- Reload ---------------------------------------------------------*/ function SWEP:Reload() if !( ( self.Weapon:Clip1() ) < ( self.Primary.ClipSize ) ) then return end self.Weapon:DefaultReload( ACT_VM_RELOAD ) self:EmitSound( "v_tomgun/reload.wav" ) end[/code] Prop's QC: [code]$modelname "weapons/XIIIArms/Harpoon.mdl" $body mybody "Arrow.smd" $staticprop $surfaceprop metal $cdmaterials "models\XIIIArms" $sequence idle "ragdoll.smd" $collisionmodel "Arrow.smd" { $mass 50 $concave 1 } $keyvalues { prop_data { base metal.Medium allowstatic 1 mass 50 } physgun_interactions { onworldimpact stick onfirstimpact stick onlaunch spin_none } }[/code]
To answer your first question, you can put [lua]timer.Simple( 60, function() self:Remove() end )[/lua] in your ENT:Deploy
Huh, that's what I have: [code] [ERROR] lua/weapons/xiii_harpoon/shared.lua:112: attempt to index global 'ENT' (a nil value) 1. unknown - lua/weapons/xiii_harpoon/shared.lua:112 [/code] Dumb me, I'm bad at lua.
Sorry, after your ent:Spawn(). [editline]4th November 2013[/editline] And it should be ent:Remove()
That gives the same error.
Or on creation of the entity you could do something like [code]timer.Create( "deleteent_" .. ent:EntIndex(), 1, 60, function() if ( IsValid( ent ) ) then ent:Remove(); end end );[/code]
That's not an entity, that's just a prop, check the code. OK, I feel like an idiot now. Just a bit sleepy..
[QUOTE=Garfield.;42753388]That's not an entity, that's just a prop, check the code.[/QUOTE] [LUA] function SWEP:ThrowHarpoon() if ( CLIENT ) then return end local ent = ents.Create( "prop_physics" ) if ( !IsValid( ent ) ) then return end ent:SetModel( "models/weapons/XIIIArms/Harpoon.mdl" ) ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 36 ) ) ent:SetAngles( self.Owner:EyeAngles() ) ent:Spawn() local phys = ent:GetPhysicsObject() if ( !IsValid( phys ) ) then ent:Remove() return end local velocity = self.Owner:GetAimVector() velocity = velocity * 100000 velocity = velocity + ( VectorRand() * 10 ) phys:ApplyForceCenter( velocity ) timer.Create( "deleteent" .. ent:EntIndex(), 1, 60, function() if ( ent:IsValid() ) then ent:Remove(); end end ); cleanup.Add( self.Owner, "props", ent ) undo.Create( "Harpoon" ) undo.AddEntity( ent ) undo.SetPlayer( self.Owner ) undo.Finish() end [/LUA] and for your second question you really need to clarify that doesn't make any sense
You can add the FVPHYSICS_WAS_THROWN flag when punted with the gravity gun. That way, you can check in the collision hook if it was shot or thrown.
Vexx, how?
By the way, I need it to stick to ragdolls too, and make them not fly across all the map when hit ( Like, they'd still get damage while Harpoon has low mass ).
This needs a bump too.
Ok so you're trying to make a harpoon gun? Sounds like SetParent is your friend
And to make it stick to NPCs or ragdolls, should I use SetParentPhysNum?
Hell if I know, I've never really messed around with ragdolls and player corpses. I know of an NPC that does something similar to what you're trying to do; the Hydra. Once it sees a target, it spears it on its... tail? head?... thing, gets the model of the target and creates a ragdoll while at the same time removing the clientside ragdoll created by NPCs and players on death. Somehow. I haven't looked in the code itself so I don't know the method.
This would be too messy. I have seen the Kabar knife swep that sticked to ragdolls and stuff, but it's deleted from workslop now.
Do you still have the .gma of the knife swep?
[QUOTE=code_gs;42778834]Do you still have the .gma of the knife swep?[/QUOTE] Exactly, you should still have the gma AS LONG AS you haven't reinstalled gmod at some point between then and now.
Nope, I don't have it anymore.
do you know of a garrysmod.org version?
Nope, it was never released on gaymod.org.
Sorry, you need to Log In to post a reply to this thread.