Server.HookNetworkMessage: already hooked error
I'm trying to hook the "MutePlayer" network message, and I am getting an error in my server console:
Error: The message MutePlayer was already hooked
I could modify function OnCommandMutePlayer in 'NetworkMessages_Server.lua' and get the functionality I want, but I am trying to find a way to do this without modifying the stock NS2 files.
Any ideas?
Error: The message MutePlayer was already hooked
I could modify function OnCommandMutePlayer in 'NetworkMessages_Server.lua' and get the functionality I want, but I am trying to find a way to do this without modifying the stock NS2 files.
Any ideas?
Comments
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local OriginalOnCommandMutePlayer = OnCommandMutePlayer
function OnCommandMutePlayer(client, message)
// My code running before the call here
OriginalOnCommandMutePlayer(client, message)
// My code running after the call here
end<!--c2--></div><!--ec2-->
Code not tested.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local OriginalOnCommandMutePlayer = OnCommandMutePlayer
function OnCommandMutePlayer(client, message)
// My code running before the call here
OriginalOnCommandMutePlayer(client, message)
// My code running after the call here
end<!--c2--></div><!--ec2-->
Code not tested.<!--QuoteEnd--></div><!--QuoteEEnd-->
I don't think that will work because the function is declared and passed to Server.HookNetworkMessage in the same Lua file
<a href="http://www.unknownworlds.com/ns2/wiki/index.php/Lua/Libraries/Client/HookNetworkMessage" target="_blank">http://www.unknownworlds.com/ns2/wiki/inde...kNetworkMessage</a>
If not, try hooking Server.HookNetworkMessage itself in the same manner but so that when messageName is "MutePlayer", just pop your function in there as the callback instead of the one provided. :)
My code comes before NetworkMessages_Server.lua is loaded, so the hook in there overrides mine.
<!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->If not, try hooking Server.HookNetworkMessage itself in the same manner but so that when messageName is "MutePlayer", just pop your function in there as the callback instead of the one provided. :)<!--QuoteEnd--></div><!--QuoteEEnd-->
I did just that. Works, but seems a little odd.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> local originalOnMutePlayer
local function OnMutePlayer(client, message)
originalOnMutePlayer(client, message)
// My code here
end
local originalHookNetworkMessage = Server.HookNetworkMessage
Server.HookNetworkMessage = function(networkMessage, callback)
if networkMessage == "MutePlayer" then
originalOnMutePlayer = callback
callback = OnMutePlayer
end
originalHookNetworkMessage(networkMessage, callback)
end<!--c2--></div><!--ec2-->
Any ideas?