• Addcallback does not work
    12 replies, posted
[code]include("tr_allowed_entities.lua") function tr_touch( selfent, col_data ) print("2") local ent = col_data.HitEntity if ent:IsVehicle() then selfent:Remove() end end hook.Add( "OnEntityCreated", "tr_SetColCheck", function(ent) if trunk_entities[ent:GetClass()] then print("1") ent:AddCallback( "PhysicsCollide", tr_touch ) end end ) [/code] It never prints 2, though it prints 1. What am I doing wrong?
AddCallback almost never works. There's a very narrow range of entities it will work on and I forgot which ones they are.
I remember having the same problem, an illogical fix is just making the function within the AddCallback function, like: [code] ent:AddCallback("PhysicsCollide", function(selfent, col_data) local ent = col_data.HitEntity if ent:IsVehicle() then selfent:Remove() end end ) [/code]
I don't see what that changes.
[QUOTE=BFG9000;48424643]I don't see what that changes.[/QUOTE] The fact it avoids the possibility of tr_touch being overridden somehow. @RedNinja, do print("1", ent) and tell us the entity class.
[QUOTE=Robotboy655;48424659]The fact it avoids the possibility of tr_touch being overridden somehow. @RedNinja, do print("1", ent) and tell us the entity class.[/QUOTE] The entity class is sent_ball, because its the only entity on the table.
It might be that AddCallback doesn't work on scripted entities, could be a bug with the game [editline]10th August 2015[/editline] Or more specifically PhysicsCollide event doesn't work on SENTs because you sort of already have ENT.PhysicsCollide
[QUOTE=Robotboy655;48424792]It might be that AddCallback doesn't work on scripted entities, could be a bug with the game [editline]10th August 2015[/editline] Or more specifically PhysicsCollide event doesn't work on SENTs because you sort of already have ENT.PhysicsCollide[/QUOTE] I tried using a money printer. Does the same thing.
[QUOTE=RedNinja;48424895]I tried using a money printer. Does the same thing.[/QUOTE] Yeah, because that's another SENT
[QUOTE=Robotboy655;48425000]Yeah, because that's another SENT[/QUOTE] Problematic. What do I do now?
[QUOTE=RedNinja;48425080]Problematic. What do I do now?[/QUOTE] if IsScripted then local oldCallback = entity.PhysicsCollide entity.PhysicsCollide = function() mycallback() return oldCallback() end end Something like that for now I guess.
[QUOTE=Robotboy655;48425091]if IsScripted then local oldCallback = entity.PhysicsCollide entity.PhysicsCollide = function() mycallback() return oldCallback() end end Something like that for now I guess.[/QUOTE] Do you mean something like: [code] hook.Add( "OnEntityCreated", "tr_SetColCheck", function(ent) if trunk_entities[ent:GetClass()] then ent:AddCallback("PhysicsCollide", function( self, data ) print("its okay") local ent = data.HitEntity if ent:IsVehicle() then self:Remove() end return self.PhysicsCollide end) end end ) [/code] Because this does not work either. Anyways i'd simply add now a chat command for now.
[QUOTE=Robotboy655;48425091]if IsScripted then local oldCallback = entity.PhysicsCollide entity.PhysicsCollide = function() mycallback() return oldCallback() end end Something like that for now I guess.[/QUOTE] Use this instead of ent:AddCallback [editline]10th August 2015[/editline] For only SENTs
Sorry, you need to Log In to post a reply to this thread.