• This entity won't call PhysicsCollide..
    3 replies, posted
I want this SWEP on my server. I didn't make this, it's something I found. It was made by jaanus Here is the SWEP [code]if ( SERVER ) then AddCSLuaFile( "shared.lua" ) SWEP.HoldType = "melee" end if ( CLIENT ) then SWEP.PrintName = "Shurikens" SWEP.Author = "Jaanus" SWEP.Slot = 1 SWEP.SlotPos = 7 SWEP.ViewModelFOV = 86 SWEP.IconLetter = "x" killicon.Add( "shuricon", "shuriken/deathicon", Color( 180, 0, 0, 255 ) ); killicon.AddAlias( "weapon_shuriken", "shuricon" ); killicon.AddAlias( "ent_shuriken", "shuricon" ); end ------------General Swep Info--------------- SWEP.Author = "Jaanus" SWEP.Contact = "Jaanus@jaanus.cc" SWEP.Purpose = "Kill stuff - Ninja style." SWEP.Instructions = "Left click throws a shuriken." SWEP.Spawnable = true SWEP.AdminSpawnable = true ----------------------------------------------- ------------Models--------------------------- SWEP.ViewModel = "models/jaanus/v_shuriken.mdl" SWEP.WorldModel = "models/jaanus/w_shuriken.mdl" ----------------------------------------------- -------------Primary Fire Attributes---------------------------------------- SWEP.Primary.Delay = 0.9 --In seconds SWEP.Primary.Recoil = 0.5 --Gun Kick SWEP.Primary.Damage = 100 --Damage per Bullet SWEP.Primary.NumShots = 1 --Number of shots per one fire SWEP.Primary.Cone = 0 --Bullet Spread SWEP.Primary.ClipSize = 1 --Use "-1 if there are no clips" SWEP.Primary.DefaultClip = -1 --Number of shots in next clip SWEP.Primary.Automatic = true --Pistol fire (false) or SMG fire (true) SWEP.Primary.Ammo = "none" --Ammo Type -------------End Primary Fire Attributes------------------------------------ -------------Secondary Fire Attributes------------------------------------- SWEP.Secondary.Delay = 0.9 SWEP.Secondary.Recoil = 0 SWEP.Secondary.Damage = 100 SWEP.Secondary.NumShots = 1 SWEP.Secondary.Cone = 0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" -------------End Secondary Fire Attributes-------------------------------- -- function SWEP:Reload() --To do when reloading -- end if ( CLIENT ) then function SWEP:GetViewModelPosition( pos, ang ) pos = pos + ang:Forward()*4 return pos, ang end end function SWEP:Think() -- Called every frame end function SWEP:Initialize() --util.PrecacheSound("physics/flesh/flesh_impact_bullet" .. math.random( 3, 5 ) .. ".wav") util.PrecacheSound("weapons/shuriken/throw1.wav") util.PrecacheSound("weapons/shuriken/throw2.wav") util.PrecacheSound("weapons/shuriken/throw3.wav") util.PrecacheSound("weapons/shuriken/throw4.wav") end function SWEP:PrimaryAttack() self.Weapon:EmitSound("weapons/shuriken/throw"..tostring( math.random( 1, 4 ) )..".wav") self.Weapon:SetNextPrimaryFire(CurTime() + 0.8) self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) if SERVER then local shuriken = ents.Create("ent_shuriken") shuriken:SetAngles(self.Owner:EyeAngles())-- Angle(0,90,0)) shuriken:SetPos(self.Owner:GetShootPos()) shuriken:SetOwner(self.Owner) shuriken:SetPhysicsAttacker(self.Owner) shuriken:Spawn() shuriken:Activate() local function test( data, phys ) for k, v in pairs(player.GetAll()) do v:ChatPrint("FUCK YEAH SHURIKENS HIT SOMETHING") end if self:GetVelocity():Length() < 250 then self:Disable() return end local Ent = data.HitEntity if !(ValidEntity( Ent ) || Ent:IsWorld()) then return end if Ent:IsWorld() then if data.OurOldVelocity:Normalize():Dot( data.HitNormal ) > .5 then self:SetPos( data.HitPos ) self:SetAngles( data.OurOldVelocity:Angle() ) self:GetPhysicsObject():EnableMotion( false ) util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal ) self:EmitSound( self.Hit[math.random(1,#self.Hit)] ); end self:Disable() end if not(Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal ) self:EmitSound( self.Hit[math.random(1,#self.Hit)] ); end Ent:TakeDamage( 18, self:GetOwner() ) self:SetPos( data.HitPos ) self:SetParent( Ent ) Ent:DeleteOnRemove( self ) self:Disable() if (Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then local effectdata = EffectData() effectdata:SetStart( data.HitPos ) effectdata:SetOrigin( data.HitPos ) effectdata:SetScale( 1 ) util.Effect( "BloodImpact", effectdata ) self:EmitSound( self.FleshHit[math.random(1,#self.Hit)] ); self:Remove() --Comment this line out if you want the shurikens to stick in ragdolls/npcs (shittily) end end shuriken:AddCallback("PhysicsCollide", test) local phys = shuriken:GetPhysicsObject() phys:SetVelocity(self.Owner:GetAimVector()*7000) phys:AddAngleVelocity(Vector(0,0,90)) end end [/code] As you can see I added a CallBack to try and get physicscollide to be called. I throw the shuriken and it doesn't print the chat message. Here is the ent_shuriken code. [code] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize() self:SetModel( "models/jaanus/shuriken_small.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) util.PrecacheSound("physics/metal/sawblade_stick3.wav") util.PrecacheSound("physics/metal/sawblade_stick2.wav") util.PrecacheSound("physics/metal/sawblade_stick1.wav") util.PrecacheSound("weapons/shuriken/hit1.wav") util.PrecacheSound("weapons/shuriken/hit2.wav") util.PrecacheSound("weapons/shuriken/hit3.wav") self.Hit = { Sound( "physics/metal/sawblade_stick1.wav" ), Sound( "physics/metal/sawblade_stick2.wav" ), Sound( "physics/metal/sawblade_stick3.wav" ) }; self.FleshHit = { Sound( "weapons/shuriken/hit1.wav" ), Sound( "weapons/shuriken/hit2.wav" ), Sound( "weapons/shuriken/hit3.wav" ) } self:GetPhysicsObject():SetMass( 2 ) end function ENT:Think() self.lifetime = self.lifetime or CurTime() + 20 if CurTime() > self.lifetime then self:Remove() end end function ENT:Disable() self.PhysicsCollide = function()end self.lifetime = CurTime() + 30 end function ENT:PhysicsCollide( data, phys ) for k, v in pairs(player.GetAll()) do v:ChatPrint("FUCK YEAH SHURIKENS HIT SOMETHING") end if self:GetVelocity():Length() < 250 then self:Disable() return end local Ent = data.HitEntity if !(ValidEntity( Ent ) || Ent:IsWorld()) then return end if Ent:IsWorld() then if data.OurOldVelocity:Normalize():Dot( data.HitNormal ) > .5 then self:SetPos( data.HitPos ) self:SetAngles( data.OurOldVelocity:Angle() ) self:GetPhysicsObject():EnableMotion( false ) util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal ) self:EmitSound( self.Hit[math.random(1,#self.Hit)] ); end self:Disable() end if not(Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then util.Decal( "ManhackCut", data.HitPos + data.HitNormal, data.HitPos - data.HitNormal ) self:EmitSound( self.Hit[math.random(1,#self.Hit)] ); end Ent:TakeDamage( 18, self:GetOwner() ) self:SetPos( data.HitPos ) self:SetParent( Ent ) Ent:DeleteOnRemove( self ) self:Disable() if (Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then local effectdata = EffectData() effectdata:SetStart( data.HitPos ) effectdata:SetOrigin( data.HitPos ) effectdata:SetScale( 1 ) util.Effect( "BloodImpact", effectdata ) self:EmitSound( self.FleshHit[math.random(1,#self.Hit)] ); self:Remove() --Comment this line out if you want the shurikens to stick in ragdolls/npcs (shittily) end end [/code] This is the Entity code.. I called ENT:PhysicsCollide here as well. Still no chat message on it. I can throw the entity, and it flies out and has physics and everything. The only problem is the target loses no HP.
Try not setting the physics attacker, sometimes doing stuff like that messes with things in my experience.
[QUOTE=BFG9000;44407426]Try not setting the physics attacker, sometimes doing stuff like that messes with things in my experience.[/QUOTE] I'm guessing you meant in the SWEP after I spawn the Shuriken, but it still it doesn't get called. And is there a reason there is an AddCallback function AND a PhysicsCollide function? Do they both work?
Try cutting the addcallback thing for now, not really a reason why he shouldn't have been using physicscollide.
Sorry, you need to Log In to post a reply to this thread.