Advertisement
Mosmo

Calradia | Command Processor

Jan 15th, 2017
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #If WinActive("GTA:SA:MP")
  2. #If
  3. CMD.SwitchOn()
  4. Class CMD {
  5.     Static Status := 0
  6.     Static List := {}
  7.  
  8.     ; CMD.Register("command","testFunc") - The second parameter is a function
  9.     ; CMD.Register("command","testFunc",testObject) - The second parameter is a method
  10.     Register(Command,Function, Object := "") {
  11.         If ( IsObject(Object) ) {
  12.             Function := ObjBindMethod(Object,Function)
  13.             CMD.List[Command] := Function
  14.             return 0
  15.         } else if ( IsFunc(Function) ) {
  16.             CMD.List[Command] := Function
  17.             return 0
  18.         } else return 1
  19.     }
  20.     SwitchOn() {
  21.         If ( !CMD.Status ) {
  22.             Static Function := ObjBindMethod(CMD,"Check")
  23.             Hotkey, If, WinActive("GTA:SA:MP")
  24.             Hotkey, ~Enter,% Function, On, UseErrorLevel
  25.             CMD.Status := ( ErrorLevel == 0 ) ? "1" : "0"
  26.             return ErrorLevel
  27.         } else return 1
  28.     }
  29.     SwitchOff() {
  30.         If ( CMD.Status != 0 ) {
  31.             Hotkey, If, WinActive("GTA:SA:MP")
  32.             Hotkey, ~Enter, Off, UseErrorLevel
  33.             CMD.Status := ( ErrorLevel == 0 ) ? "0" : "1"
  34.             return ErrorLevel
  35.         } else return 1
  36.     }
  37.     Check() {
  38.         If ( isInChat() ) {
  39.             KeyWait, Enter
  40.             sleep 150
  41.             Input := readString(hGTA, dwSAMP + 0x12D8F8, 256)
  42.             If ( SubStr(Input,1,1) == "/" && RegExMatch(Input,"(\w+)", Command, 2) && CMD.List[Command] ) {
  43.                 writeString(hGTA, dwSAMP + 0x12D8F8, "")
  44.                 Function := CMD.List[Command], Arguments := StrSplit(SubStr(Input,3+StrLen(Command),StrLen(Input)-2-StrLen(Command))," ")
  45.                 While ( Arguments.Length() < IsFunc(Function) )
  46.                     Arguments.Push("")
  47.                 %Function%(Arguments*)
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement