Jump to content

Multiple Command Handlers


DazzaJay

Recommended Posts

Posted

Basically, back in MTA Race, with mIRC, there were multiple independant scripts that had the same command, such as !info, our old server had 4 independant scripts that responded to !info, MTAMA, PRS, Pothole Emotes, Pothole Scripts.

So basically, can multiple independant LUA scripts in DM have the same command handler, such as /info in a bunch of different scripts?

Posted

This:

  
addCommandHandler("test", 
    function(player,cmd) 
        outputChatBox("I AM A FUNCTION") 
    end 
) 
  
addCommandHandler("test", 
    function(player,cmd) 
        outputChatBox("SO AM I") 
    end 
) 
  

outputs both lines to the chatbox - so yes, you can (assuming there's no difference in having the two test calls in the same resource).

Posted

Well, like that, but in Multiple different recources....

So like this....

Race Gamemode:

addCommandHandler("info", 
    function(player,cmd) 
        outputChatBox("Pothole Studios Race v10.7.1") 
    end 
) 

and say, in some other script in a different recource.

addCommandHandler("info", 
    function(player,cmd) 
        outputChatBox("Some other script V7.11") 
    end 
) 

Would that work like this...

[PS]DazzaJay[AU]: /info

Pothole Studios Race v10.7.1

Some other script V7.11

Posted

Of course that will work! Why don't you try it (or read the documentation)?

http://development.mtasa.com/index.php? ... andHandler

"Multiple command handlers can be attached to a single command, and they will be called in the order that the handlers were attached."

Sure, it doesn't explicitly say that it works with multiple resources, but you can assume that's the case with anything in MTA. Resources have no exclusive rights to anything (except things they might be given exclusive rights to in the ACL, but that's a bit different).

That said, using helpmanager's GUI might be a better way to provide info to the user. We try discourage people outputting anything in the chat box that isn't chat.

Posted

Thats cool, its just cos i remember asking this once before and being told it dosent work, but this was about a day after DP1 was released.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...