• Exempting certain ents or classes from duplication?
    4 replies, posted
Hi, I've got a missile-pod entity with a series of missile entities parented to it. The pod spawns these missiles inside itself, parents them to itself and stores them in a table so it can launch them - this is all working great but the missiles should not be able to survive duplication as they should only be created via the pod. Is there any way to mark these missiles as unduplicable? I've checked the duplicator library and found that there's a duplicator.Allow function (and duplicator.IsAllowed("missile") == true), but I haven't found any counterparts to this. Any solution will do as long as it covers the three main duplicators (vanilla, Adv. duplicator 1 + 2) - thanks for any tips.
[url]http://wiki.garrysmod.com/page/ENTITY/PreEntityCopy[/url] ? [editline]15th December 2014[/editline] [url]http://wiki.garrysmod.com/page/ENTITY/PostEntityPaste[/url] ??
Thanks, I can definitely use PostEntityPaste to detect/delete the missiles once pasted, and alter/respawn them according to the rules. Not sure if it's feasible to use PreEntityCopy to block the duplication? Stopping the missiles from entering the dupe altogether would be ideal but the other approach will do too.
[code] function duplicator.Deny( class ) local _, x x = debug.getupvalue( duplicator.Allow, 1 ) x[ class ] = false end [/code] Haven't tested it in-game, but in theory it should work since this does: [code]Q = { } do local x = { } function Q.Allow( f ) x[ f ] = true end function Q.IsAllowed( v ) return x[ v ] end end print( tostring( x ) ) print( tostring( Q.IsAllowed( "happy" ) ) ) Q.Allow( "happy" ) print( Q.IsAllowed( "happy" ) ) print( debug.getupvalue( Q.Allow, 1 ) ) _, x = debug.getupvalue( Q.Allow, 1 ) x[ "happy" ] = false print( Q.IsAllowed( "happy" ) )[/code] [code]nil nil true x table false[/code]
Learning something new every day, that's clever. I feel odd to rely on DuplicateAllowed to be upvalue #1, so even though it'll probably never change I decided to check the upvalue name: [lua]function duplicator.Deny( class ) local name, val local i = 1 while true do name, val = debug.getupvalue( duplicator.Allow, i ) if name == "DuplicateAllowed" then break end if not name then error( "duplicator.Deny could not locate the DuplicateAllowed table!" ) end i = i + 1 end val[ class ] = false end[/lua] While this works, it looks like only Garry's duplicator respects duplicator.IsAllowed, and Adv duplicator 1 and 2 spawn the missile regardless. Garry's duplicator also supports Entity.DoNotDuplicate but AD1+2 also seem to ignore this. The final function ended up looking like this: [lua]function duplicator.Deny( class ) local name, val local i = 1 while true do name, val = debug.getupvalue( duplicator.Allow, i ) if name == "DuplicateAllowed" then break end if not name then error( "duplicator.Deny could not locate the DuplicateAllowed table!" ) end i = i + 1 end val[ class ] = false if AdvDupe2 then AdvDupe2.duplicator.WhiteList[class] = nil end if AdvDupe then AdvDupe.AdminSettings.ChangeDisallowedClass( class, true, true ) end end[/lua] I'll hold onto this code for now, submit this to AD1+2 as a request and hopefully see support for the vanilla options in future.
Sorry, you need to Log In to post a reply to this thread.