• TTT Override radio commands
    4 replies, posted
I wrote a small addon to overwrite the radio function. I did this so I can prevent people saying that they're with someone in spectator deathmatch or someone who is cloaked. It works perfectly when I overwrite the gamemode files, but I can't when I run it as an addon it doesn't work. I get this error when it runs [CODE] [ERROR] addons/radiofix/lua/autorun/radiofix.lua:3: attempt to index global 'RADIO' (a nil value) 1. fn - addons/radiofix/lua/autorun/radiofix.lua:3 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [/CODE] I completely understand that RADIO is undefined in this file, but shouldn't I be able to use RADIO because its declared globally in cl_voice.lua? [CODE] RADIO = {} [/CODE] Heres the code for my addon. I modify the filter to skip the ghosts in deathmatch (another addon) and then I replace someones name with "someone who is cloaked" for someone using a cloaking device. [CODE] hook.Add( "Initialize", "SpecCalloutOverride", function() function RADIO:GetTargetType() if not IsValid(LocalPlayer()) then return end --local trace = LocalPlayer():GetEyeTrace(MASK_SHOT) local tab = util.GetPlayerTrace( LocalPlayer() ) tab.filter = function(ent) if ent:IsPlayer() and ent:IsSpec() then return false elseif ent == LocalPlayer() then return false else return true end end local trace = util.TraceLine(tab) if not trace or (not trace.Hit) or (not IsValid(trace.Entity)) then return end local ent = trace.Entity if ent:IsPlayer() then if ent:GetNWBool("disguised", false) then return "quick_disg", true elseif ent:GetNWBool("cloaked", false) then return "someone who is cloaked.", true else return ent, false end elseif ent:GetClass() == "prop_ragdoll" and CORPSE.GetPlayerNick(ent, "") != "" then if DetectiveMode() and not CORPSE.GetFound(ent, false) then return "quick_corpse", true else return ent, false end end end end) [/CODE]
You're probably calling RADIO before it's defined (the hook is running to early). You could just define it in the Init hook before the function uses it, then comment out the other definition. That, or load it after RADIO is defined.
[QUOTE=code_gs;45917545]You're probably calling RADIO before it's defined (the hook is running to early). You could just define it in the Init hook before the function uses it, then comment out the other definition. That, or load it after RADIO is defined.[/QUOTE] Thanks, do you know a way that I can insure that RADIO isn't called before its defined? I am trying to avoid editing the gamemode since I don't want an update causing potential errors.
Use a different hook or a timer to make sure that RADIO is defined first.
Thanks a lot, I used a different hook and it works perfectly now. Heres the completed addon if you're interested [url]https://github.com/KoalityGaming/RadioFix[/url]
Sorry, you need to Log In to post a reply to this thread.