Hi, I have a problem. Before I tell you what the problem is, here's the code:
weapons\myswep\shared.lua
[CODE]
if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
end
SWEP.Base = "SWEP_Rock"
SWEP.Author = ""
SWEP.Instructions = "Rocks"
SWEP.Category = "weapons"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.HoldType = "pistol"
SWEP.PrintName = "SWEP_Rock"
SWEP.Slot = 1
SWEP.ViewModel = "models/weapons/v_Pistol.mdl"
SWEP.WorldModel = "models/weapons/w_Pistol.mdl"
SWEP.Weight = 5
SWEP.DrawCrosshair = false
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 47
SWEP.Primary.Damage = 0
SWEP.Primary.ClipSize = 5
SWEP.Primary.DefaultClip = 5
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.5
SWEP.Primary.Ammo = "357"
SWEP.Primary.Automatic = true
SWEP.Primary.Damage = 0
SWEP.Primary.Delay = 0.5
SWEP.Primary.Force = 3
SWEP.Primary.Spread = 0.1
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Sound = "Weapon_Pistol.Single"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 5
function SWEP:Initialize()
end
function SWEP:Reload()
if self.ReloadingTime and CurTime() <= self.ReloadingTime then return end
if ( self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
self:DefaultReload( ACT_VM_RELOAD )
local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
self.ReloadingTime = CurTime() + AnimationTime
self:SetNextPrimaryFire(CurTime() + AnimationTime)
self:SetNextSecondaryFire(CurTime() + AnimationTime)
end
end
function SWEP:Think()
end
function SWEP:TakePrimaryAmmo( num )
// Doesn't use clips
if ( self:Clip1() <= 0 ) then
if ( self:Ammo1() <= 0 ) then return end
self.Owner:RemoveAmmo( num, self:GetPrimaryAmmoType() )
return end
self:SetClip1( self:Clip1() - num )
end
function SWEP:rock_attack()
if ( !SERVER ) then return end
local ent = ents.Create( "rock" )
self.Owner:SetAnimation(PLAYER_ATTACK1)
ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
end
function SWEP:PrimaryAttack()
if ( self:Clip1() <= 0 ) then
self:EmitSound( "Weapon_Pistol.Empty" )
self:SetNextPrimaryFire( CurTime() + 0.2 )
return false
else
self:rock_attack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:TakePrimaryAmmo(1)
end
end
function SWEP:DrawWorldModel()
self:DrawModel()
end
function SWEP:SecondaryAttack()
end
function SWEP:Deploy()
end
[/CODE]
entities\rock\init.lua
[CODE]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
function ENT:SpawnFunction( ply, tr )
local ent = ents.Create( "rock" )
end
function ENT:Initialize()
self.Entity:SetModel( "models/props_junk/CinderBlock01a.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
end
function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
end
function ENT:Think()
self.Entity:GetPhysicsObject():SetVelocity(self.Entity:GetForward()*1200)
end
function ENT:Touch(ent)
if ent:IsPlayer() then
self.Entity:Remove()
ent:TakeDamage(10, self:GetOwner(), self)
end
end
[/CODE]
okay here's the problem: When I throw rocks and when the player touch them, they will take 10 damage and the rock will remove itself, but they take 60,100,200,10000 damage and sometime instant kill, I'm just want the player take 10 damage from it, not over 500. I have tried almost everything, falldamage, anti prop kill, ect... I need help with this.
And one more thing, when the rock stand still I take 10 damage, but when it move or when it fall down on your head high up then you die instant. (I have tried ApplyForceCenter didn't work)
That's because of physics damage. Same as if a prop was grav gunned into you.
[QUOTE=Robotboy655;42356620]That's because of physics damage. Same as if a prop was grav gunned into you.[/QUOTE]
Okay, is there away to disable it?
[QUOTE=Robotboy655;42356675][url]http://wiki.garrysmod.com/page/GM/ScalePlayerDamage[/url][/QUOTE]
I don't really know where and what I should code there.
[code]hook.Add("ScalePlayerDamage","dadiswork",function(ply,hb,dmg)
if ( IsValid(dmg:GetInflictor( ) ) &&dmg:GetInflictor( ):GetClass()=="rock" )then
dmg:ScaleDamage( 0 )
end
end )[/code]
[QUOTE=Robotboy655;42356675][url]http://wiki.garrysmod.com/page/GM/ScalePlayerDamage[/url][/QUOTE]
It's look like for scale of bullet or something, I can't see where to code for physics scale.
[editline]30th September 2013[/editline]
[QUOTE=Robotboy655;42356963][code]hook.Add("ScalePlayerDamage","dadiswork",function(ply,hb,dmg)
if ( IsValid(dmg:GetInflictor( ) ) &&dmg:GetInflictor( ):GetClass()=="rock" )then
dmg:ScaleDamage( 0 )
end
end )[/code][/QUOTE]
Oh, thanks
[editline]30th September 2013[/editline]
[QUOTE=Robotboy655;42356963][code]hook.Add("ScalePlayerDamage","dadiswork",function(ply,hb,dmg)
if ( IsValid(dmg:GetInflictor( ) ) &&dmg:GetInflictor( ):GetClass()=="rock" )then
dmg:ScaleDamage( 0 )
end
end )[/code][/QUOTE]
In Init file?
[editline]30th September 2013[/editline]
[QUOTE=Robotboy655;42356963][code]hook.Add("ScalePlayerDamage","dadiswork",function(ply,hb,dmg)
if ( IsValid(dmg:GetInflictor( ) ) &&dmg:GetInflictor( ):GetClass()=="rock" )then
dmg:ScaleDamage( 0 )
end
end )[/code][/QUOTE]
I have tried it in init.lua and shared.lua, didn't work
Sorry, you need to Log In to post a reply to this thread.