Help with this code

Ask gaming related questions (AHK v1.1 and older)
Vladik23041
Posts: 5
Joined: 04 Dec 2022, 05:17

Help with this code

Post by Vladik23041 » 04 Dec 2022, 05:21

Code: Select all

#singleinstance force
#include samp-udf.ahk
#include cmd.ahk
;#If WinActive("GTA:SA:MP")

CMD.Register("test","test") ; +
exit

test()
{
    str = Hello World
    SendMessage(str) 
}
Why is this code not working? All include are connected. In the game, when I write a command, it just doesn't do anything

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with this code

Post by mikeyww » 04 Dec 2022, 09:18

1. See if it works when you are not in the game.
2. https://www.autohotkey.com/boards/viewtopic.php?f=7&t=11084

Vladik23041
Posts: 5
Joined: 04 Dec 2022, 05:17

Re: Help with this code

Post by Vladik23041 » 06 Dec 2022, 15:33

mikeyww wrote:
04 Dec 2022, 09:18
1. See if it works when you are not in the game.
2. viewtopic.php?f=7&t=11084
Can you help with the code test not in the game? I do not know how to implement on pc verification.

Attached the code "cmd.Register"

Code: Select all

#If WinActive("GTA:SA:MP")
#If
CMD.SwitchOn()
Class CMD {
	Static Status := 0
	Static List := {}

	; CMD.Register("command","testFunc") - The second parameter is a function
	; CMD.Register("command","testFunc",testObject) - The second parameter is a method
	Register(Command,Function, Object := "") {
		If ( IsObject(Object) ) {
			Function := ObjBindMethod(Object,Function)
			CMD.List[Command] := Function 
			return 0
		} else if ( IsFunc(Function) ) {
			CMD.List[Command] := Function
			return 0
		} else return 1
	}
	SwitchOn() {
		If ( !CMD.Status ) {
			Static Function := ObjBindMethod(CMD,"Check")
			Hotkey, If, WinActive("GTA:SA:MP")
			Hotkey, ~Enter,% Function, On, UseErrorLevel
			CMD.Status := ( ErrorLevel == 0 ) ? "1" : "0"
			return ErrorLevel
		} else return 1
	}
	SwitchOff() {
		If ( CMD.Status != 0 ) {
			Hotkey, If, WinActive("GTA:SA:MP")
			Hotkey, ~Enter, Off, UseErrorLevel
			CMD.Status := ( ErrorLevel == 0 ) ? "0" : "1"
			return ErrorLevel
		} else return 1
	}
	Check() {
		If ( isInChat() ) {
			KeyWait, Enter
			sleep 150 
			Input := readString(hGTA, dwSAMP + 0x141A78, 256)
			If ( SubStr(Input,1,1) == "/" && RegExMatch(Input,"(\w+)", Command, 2) && CMD.List[Command] ) {
				writeString(hGTA, dwSAMP + 0x141A78, "")
				Function := CMD.List[Command], Arguments := StrSplit(SubStr(Input,3+StrLen(Command),StrLen(Input)-2-StrLen(Command))," ")
				While ( Arguments.Length() < IsFunc(Function) )
					Arguments.Push("")
				%Function%(Arguments*)
			}
		}
	}
}

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with this code

Post by mikeyww » 06 Dec 2022, 15:44

I'm not very skilled with methods & classes, but others here on the forum are! Perhaps some of them will have a look.

Vladik23041
Posts: 5
Joined: 04 Dec 2022, 05:17

Re: Help with this code

Post by Vladik23041 » 06 Dec 2022, 16:00

@boiler

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Help with this code

Post by boiler » 06 Dec 2022, 16:17

mikeyww wrote: I'm not very skilled with methods & classes, but others here on the forum are! Perhaps some of them will have a look.
Vladik23041 wrote: @boiler
I'm not either!

Post Reply

Return to “Gaming Help (v1)”