• hogwarts roleplay physics crash
    4 replies, posted
I have a hogwarts roleplay server and my problem is when the server is crowded like 55 players, physics get crashed randomly because I guess high amounts of spells thrown. Props fell through ground, collision things not work and much more. I cant find the reason why does it happen. Heres my all 'ShouldCollide' hooks. What should I look for? hook.Add("ShouldCollide", "hpwrewrite_spell_oldangvel", function(self, v) if not ignore_ents[v:GetClass()] then local phys = v:GetPhysicsObject() if phys:IsValid() then v.HpwRewriteOldVelocity = phys:GetAngleVelocity() end end end) -- hook.Add("ShouldCollide", "hpwrewrite_protego_physhandler" .. s:EntIndex(), function(ent1, ent2) if IsValid(s) then if ent1 == s then if ent2:IsWorld() then return false end if ent2.SpellData and ent2.SpellData.Unforgivable then return false end if ent2:IsPlayer() then return false end sound.Play("weapons/physcannon/energy_bounce" .. math.random(1, 2) .. ".wav", ent2:GetPos(), 60, math.random(110, 150))  end else hook.Remove("ShouldCollide", "hpwrewrite_protego_physhandler" .. s:EntIndex()) end end) wiki says it can crash in some certain conditions but what conditions.. I need help on that, thanks in advance.
The thing about ShouldCollide is that the entities being queried can theoretically appear in any argument order. As I recall, the physics instability happens when there is a mismatch in the return values between ShouldCollide(ent1, ent2) and ShouldCollide(ent2, ent1). The code you posted only accounts for one possible argument order, and doesn't consider the reverse.
Thank you very much for trying to help, so as I get it you say I should do the if ent1 == s then if ent2:IsWorld() then return false end if ent2.SpellData and ent2.SpellData.Unforgivable then return false end if ent2:IsPlayer() then return false end sound.Play("weapons/physcannon/energy_bounce" .. math.random(1, 2) .. ".wav", ent2:GetPos(), 60, math.random(110, 150)) end part for ent2 too right? I guess like this; if ent2 == s then if ent1:IsWorld() then return false end if ent1.SpellData and ent1.SpellData.Unforgivable then return false end if ent1:IsPlayer() then return false end sound.Play("weapons/physcannon/energy_bounce" .. math.random(1, 2) .. ".wav", ent1:GetPos(), 60, math.random(110, 150)) end
same did you solve your problem
The conditionals here are fairly complex, so I would try to solve it with a simpler solution. Identify which entity is the one you are interested in, and change the argument order to a consistent, expected order. function my_shouldcollide_hook(ent1, ent2)     -- I am interested in changing the collisions on prop_myentity     -- identify which one is prop_myentity, if any     local mine, other          if ent1:GetClass() == "prop_myentity" then         mine = ent1         other = ent2     elseif ent2:GetClass() == "prop_myentity" then         mine = ent2         other = ent1     end          -- Insert collision logic here     if IsValid(s) then         if mine == s then             if other:IsWorld() then return false end             if other.SpellData and other.SpellData.Unforgivable then return false end             if other:IsPlayer() then return false end             sound.Play("weapons/physcannon/energy_bounce" .. math.random(1, 2) .. ".wav", other:GetPos(), 60, math.random(110, 150))         end     else         hook.Remove("ShouldCollide", "hpwrewrite_protego_physhandler" .. s:EntIndex())     end end Note that this example is only meant to demonstrate the idea. You will need to adjust it.
Sorry, you need to Log In to post a reply to this thread.