Nilly's - Auto-pot / Auto-Special if Priest / Auto-Nexus - Code

Posts 115 of 56 · Page 1 of 4
Nilly's - Auto-pot / Auto-Special if Priest / Auto-Nexus - Code
Well raikoug got me interested in doing this when he posted a thread in the request section, http://www.mpgh.net/forum/655-realm-...autonexus.html .

It works a little different from the way he describe what he would like to do in the original post. I found that tying the auto-pot, auto-special, and auto-nexus together, all sharing the same activation point, was dangerous. The problem was that it took time from when the request to use the special ablilty or heal potion and the time when the effects manifested themselves (probably due to server communication). During this time auto-nexus would not activate because there was an alternative (use special or use potion). This caused it to be more risky to use over the normal auto-nexus. What I ended up doing was separating the features, giving all them their own unique activation point (the percentage of health on which to activate). This way auto-nexus will still activate even if there is an alternative available (works just like normal auto-nexus). It's safer this way and I think it works rather well.

Features:
Auto-Special (Priest Only) at 50% health (with auto-magic pot when needed)
Auto-Heal Potion at 35% health
and Auto-Nexus at 20%

This should work with any and all pots that have the Heal or Magic activate property. There is also a check for quiet status effect so it doesn't waste magic pots unnecessarily.

If you want to change the activation points, it should be fairly obvious where to do so in the code.

As a side note, I've experienced kick to character select screen a few times. I think I solved the problem though. Let me know if you are experiencing this and think this code is the culprit.


Here is the code:

Stick this in com.company.assembleegameclient.objects:Player/update function, just before the returnvalue instruction at the end.
Code:
	;--- check if the player object is me ---
	getlocal0
	getlex			QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "player_")
	ifne DONE		; is this the player? end if not true
	
	;--- check to see if player is in nexus
	getlex			QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "name_")
	pushstring		"Nexus"
	ifeq DONE		; is player in nexus? jump if true
	
	;*** get and store health percentage ***
	getlex			QName(PackageNamespace(""), "_-aY")
	convert_d
	getlex			QName(PackageNamespace(""), "_-LT")
	convert_d
	divide
	dup
	dup
	
	;*** determine if time to use special ***
	pushdouble		.50
	ifle			USE_SPECIAL
FINISHED_SPECIAL:
	label
	
	;*** determine if time to use heal potion ***
	pushdouble		.35
	ifle			USE_HEAL_POT
FINISHED_HEAL_POT:
	label
	
	;*** determine if nexus is needed ***
	pushdouble		.20		
	ifle			AUTO_NEXUS
FINISHED_AUTO_NEXUS:
	label
	
	jump			DONE ; finished checks
	
USE_SPECIAL:
	;--- check to see if player is a priest ---
	getlex			QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "player_")
	getproperty		QName(PackageNamespace(""), "objectType_")
	pushint			784
	ifne			FINISHED_SPECIAL ; dont use special if player isn't a priest
	
	;--- attempt to use special ---
	getlocal0
	callproperty	QName(PackageNamespace(""), "use_special"), 0
	
	pushint			2
	ifne			FINISHED_SPECIAL ; check to see if reason special wasn't used was because of magic points
	
	getlocal0
	pushstring 		"Magic"
	callproperty	QName(PackageNamespace(""), "use_potion"), 1 ; attempt to use magic pot
	pop
	jump			FINISHED_SPECIAL
	
USE_HEAL_POT:
	getlocal0
	pushstring 		"Heal"
	callproperty	QName(PackageNamespace(""), "use_potion"), 1
	pop
	jump			FINISHED_HEAL_POT
	
AUTO_NEXUS:
	getlex			QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "gs_")
	getproperty		QName(PackageNamespace(""), "gsc_")
	callpropvoid	QName(PackageNamespace(""), "_-M6"), 0 ; no health pot found, goto nexus
	
	getlex			QName(PackageNamespace(""), "map_")
	pushstring		"Nexus"
	setproperty		QName(PackageNamespace(""), "name_")
	
	jump			FINISHED_AUTO_NEXUS

DONE:
Add this to the Player.class.asasm file. These are functions used by the above code and can be inserted just above the "end ; class" line at the end of the file.
Code:
 trait method QName(PackageNamespace(""), "use_potion")
  method
   refid "com.company.assembleegameclient.objects:Player/use_potion"
   param QName(PackageNamespace(""), "String")
   returns QName(PackageNamespace(""), "int")
   body
    maxstack 8
    localcount 10
    initscopedepth 8
    maxscopedepth 8
    code
	
	; --- TEMP for checking for Quiet status effect ---
	pushstring		"Magic"
	getlocal1
	ifne			SEARCH_4_POTION
	
	getlocal0
	getproperty		QName(PackageNamespace(""), "_-86") ; holds current magic points
	pushbyte		0
	ifne			SEARCH_4_POTION ; current magic points is 0, likely because of quite so don't do anything
	
	findpropstrict QName(PackageNamespace(""), "trace")
	pushstring "Quiet probably active"
	callpropvoid QName(PackageNamespace(""), "trace"), 1
	
	pushint			-1
	returnvalue
	; -------------------------------------------------

SEARCH_4_POTION:	
	pushbyte		4
	setlocal		2 ; index

	getlocal0
	getproperty		QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "player_")
	getproperty		QName(PackageNamespace(""), "inventory")
	getproperty		QName(PackageNamespace(""), "slots_")
	coerce_a
	setlocal		3 ; slot array
	
	jump CHECK_INV
	
CHECK_INV_LOOP:	
	label
	getlocal		3
	getlocal		2
	nextvalue
	coerce			QName(PackageNamespace("com.company.assembleegameclient.ui"), "_-E6")
	dup
	setlocal		4 ; holds slot item
	
	getproperty		QName(PackageNamespace(""), "objectType_")
	dup
	setlocal		5 ; holds item type
	pushint			-1
	ifeq			CHECK_INV ; goto next slot, no itme exist in current slot
	
	getlex			QName(PackageNamespace("com.company.assembleegameclient.objects"), "ObjectLibrary")
	getproperty		QName(PackageNamespace(""), "_-QF")
	getlocal		5
	getproperty		MultinameL([PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#0"), PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#1"), PackageNamespace(""), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-09j"), StaticProtectedNs("_-09j"), StaticProtectedNs("_-0-I")])
	dup
	setlocal		6 ; holds item xml data
	
	pushstring		"Potion"
    callproperty	Multiname("hasOwnProperty", [PrivateNamespace("*", "com.company.assembleegameclient.objects:_-Od/iinit#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:_-Od/iinit#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-V"), StaticProtectedNs("_-V")]), 1
	pushfalse
	ifeq			CHECK_INV ; goto next slot if item isn't a potion
	
	;----- start inner loop to check potion for heal/magic activation -----
	pushbyte		0
	setlocal		7 ; index for inner loop

	getlocal		6
	getproperty		Multiname("Activate", [PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-iX"), StaticProtectedNs("_-iX"), StaticProtectedNs("_-TE"), StaticProtectedNs("_-iP"), StaticProtectedNs("_-0-I")])
	coerce_a
	setlocal		8 ; holds activate array
	
	jump			CHECK_POT

CHECK_POT_LOOP:
	label
	getlocal		8
	getlocal		7
	nextvalue
	coerce			QName(PackageNamespace(""), "XML")
	dup
	setlocal		9 ; holds activate line
	
	callproperty	Multiname("toString", [PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-iX"), StaticProtectedNs("_-iX"), StaticProtectedNs("_-TE"), StaticProtectedNs("_-iP"), StaticProtectedNs("_-0-I")]), 0
	getlocal1
	ifne			CHECK_POT ; jump to next attribute if desired attribute not found
	
	findpropstrict QName(PackageNamespace(""), "trace")
	pushstring "Using "
	getlocal1
	add
	pushstring " Pot"
	add
	callpropvoid QName(PackageNamespace(""), "trace"), 1
	
	getlocal		4
	callpropvoid	QName(PackageNamespace(""), "attemptUse"), 0 ; use potion
	kill			8
	kill			7
	kill			3
	kill			2
	
	getlocal		9
	getproperty		MultinameA("amount", [PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-iX"), StaticProtectedNs("_-iX"), StaticProtectedNs("_-TE"), StaticProtectedNs("_-iP"), StaticProtectedNs("_-0-I")])
		; ^^ sends back amount of health/magic gained
	jump			DONE
	  
CHECK_POT:
	hasnext2		8, 7
	iftrue			CHECK_POT_LOOP
	kill			8
	kill			7
	;----------------------------------------------------------------------
	
CHECK_INV:
	hasnext2		3, 2
	iftrue			CHECK_INV_LOOP
	kill			3
	kill			2
	pushint			-1 ; no suitable potion found
	
DONE:
	returnvalue
    end ; code
   end ; body
  end ; method
 end ; trait
  
 trait method QName(PackageNamespace(""), "use_special")
  method
   refid "com.company.assembleegameclient.objects:Player/use_special"
   returns QName(PackageNamespace(""), "int")
   body
    maxstack 8
    localcount 10
    initscopedepth 8
    maxscopedepth 8
    code
	
	;--- get player's special stats ---
	getlocal0
	getproperty		QName(PackageNamespace(""), "_-zq")
	pushbyte		1
	getproperty		MultinameL([PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#0"), PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#1"), PackageNamespace(""), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-09j"), StaticProtectedNs("_-09j"), StaticProtectedNs("_-0-I")])
	dup
	setlocal		1 ; holds special objectType
	pushint			-1
	ifne			CHECK_MAGIC ; end if no special equiped
	
	pushint			1 ; means no special equipped
	returnvalue
	
CHECK_MAGIC:
	;--- check to see if player has enough magic to cast special ---	
	getlex			QName(PackageNamespace("com.company.assembleegameclient.objects"), "ObjectLibrary")
	getproperty		QName(PackageNamespace(""), "_-QF")
	getlocal		1
	convert_i
	getproperty		MultinameL([PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#0"), PrivateNamespace("*", "com.company.assembleegameclient.objects:Projectile#1"), PackageNamespace(""), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-09j"), StaticProtectedNs("_-09j"), StaticProtectedNs("_-0-I")])
	dup
	setlocal		2 ; holds xml of special
	findpropstrict	QName(PackageNamespace(""), "int")
	swap
	getproperty		Multiname("MpCost", [PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-iX"), StaticProtectedNs("_-iX"), StaticProtectedNs("_-TE"), StaticProtectedNs("_-iP"), StaticProtectedNs("_-0-I")])
	callproperty	QName(PackageNamespace(""), "int"), 1
	dup
	setlocal		3 ; holds mp cost
	getlocal0
	getproperty		QName(PackageNamespace(""), "_-86")
	ifle			COOLDOWN_CHECK ; jump if player has enough mana
	
	pushint			2 ; means not enough mana
	returnvalue
	
COOLDOWN_CHECK:
	;--- check to see if cooldown is up ---
	findpropstrict	QName(PackageNamespace("flash.utils"), "getTimer")
	callproperty	QName(PackageNamespace("flash.utils"), "getTimer"), 0
	dup
	setlocal		4 ; holds current time
	getlocal0
	getproperty		QName(PackageNamespace(""), "_-0m") ; _-0m holds time at which cooldown is up
	ifge			RESET_TIMER ; jump if cooldown is up
	
	pushint			3 ; means cooldown not up
	returnvalue

RESET_TIMER:
	;--- reset timer ---
	getlocal0
	findpropstrict	QName(PackageNamespace(""), "Number")
	getlocal		2
	getproperty		Multiname("Cooldown", [PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#0"), PackageNamespace(""), PrivateNamespace("*", "com.company.assembleegameclient.objects:Player#1"), PackageNamespace("com.company.assembleegameclient.objects"), PackageInternalNs("com.company.assembleegameclient.objects"), Namespace("http://adobe.com/AS3/2006/builtin"), ProtectedNamespace("_-iX"), StaticProtectedNs("_-iX"), StaticProtectedNs("_-TE"), StaticProtectedNs("_-iP"), StaticProtectedNs("_-0-I")])
	callproperty	QName(PackageNamespace(""), "Number"), 1
	convert_i
	pushint			1000
	multiply ; cool down time
	dup
	pushbyte		0
	ifne			SET_COOLDOWN:
	pop
	pushint			500
	
SET_COOLDOWN:
	getlocal		4
	add
	setproperty		QName(PackageNamespace(""), "_-0m")
	
	;--- use special ---
	findpropstrict QName(PackageNamespace(""), "trace")
	pushstring "Using Special"
	callpropvoid QName(PackageNamespace(""), "trace"), 1
	
	getlocal0
	getproperty		QName(PackageNamespace(""), "map_")
	dup
	dup
	getproperty		QName(PackageNamespace(""), "mouseX")
	swap
	getproperty		QName(PackageNamespace(""), "mouseY")
	callproperty	QName(PackageNamespace(""), "pSTopW"), 2
	coerce			QName(PackageNamespace("flash.geom"), "Point")
	setlocal		5
	getlocal0
	getproperty		QName(PackageNamespace(""), "map_")
	getproperty		QName(PackageNamespace(""), "gs_")
	getproperty		QName(PackageNamespace(""), "gsc_")
	getlocal		4
	getlocal0
	getproperty		QName(PackageNamespace(""), "objectId_")
	pushbyte		1
	getlocal		1
	getlocal		5
	getproperty		QName(PackageNamespace(""), "x")
	getlocal		5
	getproperty		QName(PackageNamespace(""), "y")
	callpropvoid	QName(PackageNamespace(""), "useItem"), 6
	
	pushbyte		0 ; means use special succeeded
	returnvalue
    
	end ; code
   end ; body
  end ; method
 end ; trait
This code is made to work for v123.5.1
Great stuff @nilly, especially when it isn't a high level programming language.

I guess I don't need to code it into my proxy anymore
Quote Originally Posted by flyrocket View Post
Great stuff @nilly, especially when it isn't a high level programming language.

I guess I don't need to code it into my proxy anymore
Thanks.

Your proxy still could use it (the advantage is obvious). Maybe a little less priority tho.
inb4 nelsonstutorial releases a client as his own
Quote Originally Posted by UltraN00b View Post
inb4 DanZ releases a client as his own
Corrected

Thanks, this code is awesome but i didnt understand clearly how he check if its a MP/HP pot in use_potion..
I see a check to 'Potion' but... well, nevermind
Quote Originally Posted by JustAnoobROTMG View Post
Corrected

Thanks, this code is awesome but i didnt understand clearly how he check if its a MP/HP pot in use_potion..
I see a check to 'Potion' but... well, nevermind
What it basically does is looks at the item in inventory. Gets the objectType_. If it's -1 moves on to next inventory slot (-1 means no item). The objectType can then be used with ObjectLibrary get the the XML data of the item. It then checks for a potion tag (to make sure it's a potion). Lastly, it looks for "Heal" or "Magic" in the activation tag(s) of the XML data.
Didn't you see how nelsonstutorials had the guts to copy my client for his youtube channel in my days at SG?
yes i saw that "a long time" ago.. In fact i would have to strike nelsontutorial in my quote, but i didnt found the BB code ..


---------- Post added at 11:20 AM ---------- Previous post was at 10:47 AM ----------

Replacing the code on a untouched client and hacked cleint...compile fine..
Results : It never use my pots and i always D/c.. ...WTF

I think i know ho to use nilly's codes but this time i have troubles..
awesome, better than I expected!!

---------- Post added at 01:01 PM ---------- Previous post was at 12:35 PM ----------

Ok, now you have to say that nilly: how the hell you know priest is 784!?!?!?
I already said you'r great... I've to say it again... and again...
In the xml files you'll find this,

<Object type="0x0310" id="Priest">

Convert that hex number (0x0310) to decimal and you have 784.
Doesn't work for me. Am I doing something wrong?...
I did everything just like the guide said.
Well if you miss placed some code, that can cause it to not work. Although more times than not it will crash if you done something like that. So assuming you did the changes like the guide said and you loaded up your client and realized that it doesn't have the auto-special/heal-pot/nexus functionality it probably means you didn't compile it back together correctly. After adding the code to the .asasm file you need to rabcasm the code back into an .abc file then abcreplace the original .abc file in the swf with the one you just compiled.
sorry for beeing a noob.. but where do you put the code:O?
Posts 115 of 56 · Page 1 of 4

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?