Server.HookNetworkMessage: already hooked error

kormendikormendi Join Date: 2003-05-26 Member: 16726Members, Constellation, NS2 Playtester
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?

Comments

  • lwflwf Join Date: 2006-11-03 Member: 58311Members, Constellation
    You could hook the OnCommandMutePlayer function.

    <!--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.
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    <!--quoteo(post=2053926:date=Jan 1 2013, 12:10 AM:name=lwf)--><div class='quotetop'>QUOTE (lwf @ Jan 1 2013, 12:10 AM) <a href="index.php?act=findpost&pid=2053926"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->You could hook the OnCommandMutePlayer function.

    <!--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
  • lwflwf Join Date: 2006-11-03 Member: 58311Members, Constellation
    Drat. Well, are you sure it doesn't work despite the error message? The documentation for Client.HookNetworkMessage (none for Server unfortunately) says your call should override the first one.

    <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. :)
  • kormendikormendi Join Date: 2003-05-26 Member: 16726Members, Constellation, NS2 Playtester
    <!--quoteo(post=2053937:date=Dec 31 2012, 07:37 PM:name=lwf)--><div class='quotetop'>QUOTE (lwf @ Dec 31 2012, 07:37 PM) <a href="index.php?act=findpost&pid=2053937"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->your call should override the first one.<!--QuoteEnd--></div><!--QuoteEEnd-->

    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-->
  • kormendikormendi Join Date: 2003-05-26 Member: 16726Members, Constellation, NS2 Playtester
    This was working great before v238, and now Server.HookNetworkMessage will not override.

    Any ideas?
  • kormendikormendi Join Date: 2003-05-26 Member: 16726Members, Constellation, NS2 Playtester
    kormendi wrote: »
    This was working great before v238, and now Server.HookNetworkMessage will not override.

    Any ideas?
    False alarm... its working fine.
Sign In or Register to comment.