Changing collision rules within a callback is likely to cause crashes!
2 replies, posted
Hello there.
I think this kind of error is common and might've been mentioned somewhere in the past, but I couldn't find something recent regarding this issue.
So basically I have two entities, which are objects that behave in one way or another when they hit something, they are a Thrown rock, and an Arrow. Obviously I had to tamper with the collision functions in order to do this, but this message keeps appearing whenever the collision occurs.
It's not something that gets in the way, since I haven't had any crashes (nor slow downs), but since it's a public addon which I'll realase I want to have as little problems as possible since it says that it MIGHT cause crashes.
Is there anyway to change the collision rules of a SEnt avoiding as much trouble as possible (and as a result, get rid of the message)?
Thanks in advance.
[CODE]
AddCSLuaFile();
--[[--------------------------------------------------------------------
SHARED
]]----------------------------------------------------------------------
DEFINE_BASECLASS("base_anim")
ENT.PrintName = "Thrown rock"
ENT.Category = "Desolation"
ENT.Author = "Argochamber Interactive"
ENT.Purpose = "To hurt"
ENT.Instructions = "Throw it with the rock weapon"
ENT.Spawnable = false
--[[--------------------------------------------------------------------
SERVERSIDE
]]----------------------------------------------------------------------
ENT.Hit = Sound( "Flesh.ImpactHard" )
if SERVER then
function ENT:Initialize()
-- Physics initialize.
self:SetModel("models/props_junk/rock001a.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetRenderMode( RENDERMODE_TRANSALPHA )
self:SetColor(Color(255,255,255,255))
local phys = self:GetPhysicsObject()
phys:Wake()
self.Used = false
self.Impact = false
self.Damage = 10
end
function ENT:PhysicsCollide(data, phys)
if !self.Impact then
self:CollisionRulesChanged()
if data.HitEntity:IsPlayer() or data.HitEntity:IsNPC() then
local tr = {}
tr.start = data.HitPos
tr.endpos = data.HitPos + (data.OurOldVelocity * 25)
tr.filter = self
local trace = util.TraceLine(tr)
DESOLATION:EntityDamagePlayer(data.HitEntity, trace.HitGroup, self.Damage*data.OurOldVelocity:Length()/1500)
local effectdata = EffectData()
effectdata:SetStart(data.HitPos)
effectdata:SetOrigin(data.HitPos)
effectdata:SetScale(1)
util.Effect("BloodImpact", effectdata)
self:EmitSound(self.Hit)
end
self.Impact = true
else
return false
end
end
function ENT:Use(activator, caller, SIMPLE_USE)
if activator:IsPlayer() and (DESOLATION:GetInvOccupied(activator) < DESOLATION:GetMaxInvSpace(activator)) then
if !self.Used then
DESOLATION:AddInvItem(activator, "res.stone", 1)
self:Remove()
self.Used = true
end
end
end
end
[/CODE]
[CODE]
AddCSLuaFile();
--[[--------------------------------------------------------------------
SHARED
]]----------------------------------------------------------------------
DEFINE_BASECLASS("base_anim")
ENT.PrintName = "Arrow"
ENT.Category = "Desolation"
ENT.Author = "Argochamber Interactive"
ENT.Purpose = "To hurt"
ENT.Instructions = "Use the bow to launch them"
ENT.Spawnable = false
--[[--------------------------------------------------------------------
SERVERSIDE
]]----------------------------------------------------------------------
ENT.Hit = Sound( "Flesh.ImpactHard" )
if SERVER then
function ENT:Initialize()
-- Physics initialize.
self:SetModel("models/dawnguardd/weapon_dawnguardcrossbow_dawnguardbolt.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetRenderMode( RENDERMODE_TRANSALPHA )
self:SetColor(Color(255,255,255,255))
self:GetPhysicsObject():SetMass(50)
self.Impact = false
self.Damage = 20
end
function ENT:HitDamage()
return self.Damage or 20
end
function ENT:PhysicsCollide(data, phys)
if !self.Impact then
self:GetPhysicsObject():SetVelocity(Vector(0,0,0))
self:SetMoveType(MOVETYPE_NONE)
if data.HitEntity:IsPlayer() or data.HitEntity:IsNPC() then
local tr = {}
tr.start = data.HitPos
tr.endpos = data.HitPos + (data.OurOldVelocity * 25)
tr.filter = self
local trace = util.TraceLine(tr)
DESOLATION:EntityDamagePlayer(data.HitEntity, trace.HitGroup, self:HitDamage()*(data.OurOldVelocity:Length()/2500))
local effectdata = EffectData()
effectdata:SetStart(data.HitPos)
effectdata:SetOrigin(data.HitPos)
effectdata:SetScale(1)
util.Effect("BloodImpact", effectdata)
self:EmitSound(self.Hit)
self:Remove()
end
self.Impact = true
end
self:CollisionRulesChanged()
end
function ENT:Use(activator, caller, SIMPLE_USE)
DESOLATION:ObtainResource(activator, "res.arrow", 1)
self:Remove()
end
end
[/CODE]
Store the physics data in physicscollide and do it next frame or another hook (Think or something). Just make memory changes in physicscollide only.
[QUOTE=Unib5;52205824]Store the physics data in physicscollide and do it next frame or another hook (Think or something). Just make memory changes in physicscollide only.[/QUOTE]
I'll give that a shot whenever I can, thanks for the reply!
Totally works! Many thanks!
Sorry, you need to Log In to post a reply to this thread.