Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Guild Wars > GW Bots
You last visited: Today at 23:40

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Beginner Bot programming questions

Discussion on Beginner Bot programming questions within the GW Bots forum part of the Guild Wars category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
Beginner Bot programming questions

I am editing a bot and try to learn how it works. But I have an issue:

In between two MoveTo() I use:

$SkillToCast = 1
CastSkill($SkillToCast, -2)

Sometimes it works, sometimes not. I also added a Sleep before and after but that does not work.

Maybe someone can help me with that, what am I doing wrong?

and what is the difference between Sleep() and PingSleep()?

thanks for your help.
dhanvin is offline  
Old 12/19/2023, 12:47   #2
„Ich bin Igneel's Sohn!“




 
Natsu Dragneel's Avatar
 
elite*gold: 1546
The Black Market: 666/0/0
Join Date: Jun 2016
Posts: 13,279
Received Thanks: 2,569
Quote:
Originally Posted by dhanvin View Post
I am editing a bot and try to learn how it works. But I have an issue:

In between two MoveTo() I use:

$SkillToCast = 1
CastSkill($SkillToCast, -2)

Sometimes it works, sometimes not. I also added a Sleep before and after but that does not work.

Maybe someone can help me with that, what am I doing wrong?

and what is the difference between Sleep() and PingSleep()?

thanks for your help.
About Sleeps:
Quote:
Originally Posted by ChatGPT
The difference between Sleep() and PingSleep() functions typically pertains to their behavior in programming, particularly in the context of network programming or multi-threaded environments. Here's a general explanation of each:

1. Sleep():

- Purpose: The Sleep() function is used to pause the execution of a program or a thread for a specified duration. It's commonly used in programming to delay execution, reduce CPU usage, or wait for an external event or resource without consuming CPU cycles actively.

- Behavior: When a function like Sleep() is called, the current thread is put into a non-runnable state for the specified duration. During this time, the thread is not executing any code and not consuming CPU resources. It's a simple, unconditional wait.

- Limitation: While a thread is sleeping, it's not responsive to any events or changes in conditions. If conditions change that would otherwise warrant the thread to wake up and perform actions, it will still remain asleep until the specified duration is over.

2. PingSleep():

- Term Ambiguity: PingSleep() is not a standard function in most programming languages or libraries. However, the name suggests a function that combines sleeping with a "ping" mechanism, likely used in network programming or scenarios where responsiveness during sleep is necessary.

- Hypothetical Behavior: A PingSleep()-like function might allow a thread to sleep but periodically "wake up" to check for certain conditions, such as incoming network data, signals, or other events. It could then either continue sleeping or exit the sleep state based on these checks.

- Use Case: Such a function would be useful in scenarios where a program needs to wait for an event (like a message from a network) but also needs to remain responsive and not miss the event.

In summary, Sleep() is a basic function for pausing execution without responsiveness to external events, while PingSleep() (or a similarly named function) would imply a more sophisticated mechanism where the sleeping process can periodically check for certain conditions and respond accordingly. The exact implementation and behavior of PingSleep() would depend on the specific programming environment or library being used.
Natsu Dragneel is offline  
Thanks
1 User
Old 12/19/2023, 13:47   #3
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
so it makes sense to use PingSleep() when using MoveTo(), so it can check if it is already there at the coordinates.

But not sure why the casting is not working.

/edit

it seems I was using the "wrong" Function, somehow "CastSkill" has more logic in it than what I wanted: "UseSkill"
dhanvin is offline  
Old 12/19/2023, 15:54   #4
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
what are tools / "best way" to code a bot? I'm using autoit with gwa2 files.

How do I find out coordinates? is there a special helper file to find out these things?
dhanvin is offline  
Old 12/19/2023, 19:05   #5
 
Underavelvetmoon's Avatar
 
elite*gold: 0
Join Date: May 2011
Posts: 111
Received Thanks: 94
Quote:
Originally Posted by dhanvin View Post
what are tools / "best way" to code a bot? I'm using autoit with gwa2 files.

How do I find out coordinates? is there a special helper file to find out these things?
AutoIt is all you need. There are some developer tools floating about, but you can simply use GWToolbox to view your coords/mapID/etc which I find the easiest.

As for the best way, just get stuck in. Download some working bots, see how they work, where they break, and build on it.
Underavelvetmoon is offline  
Thanks
2 Users
Old 12/21/2023, 12:21   #6
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
my bot crashes when using `TargetNearestEnemy()`

in GWA2 it is:

Code:
;~ Description: Target the nearest enemy.
Func TargetNearestEnemy()
	Return PerformAction(0x93, 0x1E)
EndFunc   ;==>TargetNearestEnemy
what am I missing?

I also have the issue that the quest is in state 0 even if I have the quest and it is not in rewards state:

Code:
    Local $lQuestState = DllStructGetData(GetQuestByID(<myId>), 'LogState')
Code:
;~ Description: Returns quest struct.
Func GetQuestByID($aQuestID = 0)
	Local $lQuestStruct = DllStructCreate('long id;long LogState;byte unknown1[12];long MapFrom;float X;float Y;byte unknown2[8];long MapTo;long Reward;long Objective')
	Local $lQuestPtr, $lQuestLogSize, $lQuestID
	Local $lOffset[4] = [0, 0x18, 0x2C, 0x534]

	$lQuestLogSize = MemoryReadPtr($mBasePointer, $lOffset)

	If $aQuestID = 0 Then
		$lOffset[1] = 0x18
		$lOffset[2] = 0x2C
		$lOffset[3] = 0x528
		$lQuestID = MemoryReadPtr($mBasePointer, $lOffset)
		$lQuestID = $lQuestID[1]
	Else
		$lQuestID = $aQuestID
	EndIf

	Local $lOffset[5] = [0, 0x18, 0x2C, 0x52C, 0]
	For $i = 0 To $lQuestLogSize[1]
		$lOffset[4] = 0x34 * $i
		$lQuestPtr = MemoryReadPtr($mBasePointer, $lOffset)
		DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lQuestPtr[0], 'ptr', DllStructGetPtr($lQuestStruct), 'int', DllStructGetSize($lQuestStruct), 'int', '')
		If DllStructGetData($lQuestStruct, 'ID') = $lQuestID Then Return $lQuestStruct
	Next
EndFunc   ;==>GetQuestByID
dhanvin is offline  
Old 12/26/2023, 18:05   #7
 
Underavelvetmoon's Avatar
 
elite*gold: 0
Join Date: May 2011
Posts: 111
Received Thanks: 94
Quote:
Originally Posted by dhanvin View Post
my bot crashes when using `TargetNearestEnemy()`

in GWA2 it is:

Code:
;~ Description: Target the nearest enemy.
Func TargetNearestEnemy()
	Return PerformAction(0x93, 0x1E)
EndFunc   ;==>TargetNearestEnemy
what am I missing?

I also have the issue that the quest is in state 0 even if I have the quest and it is not in rewards state:

Code:
    Local $lQuestState = DllStructGetData(GetQuestByID(<myId>), 'LogState')
Code:
;~ Description: Returns quest struct.
Func GetQuestByID($aQuestID = 0)
	Local $lQuestStruct = DllStructCreate('long id;long LogState;byte unknown1[12];long MapFrom;float X;float Y;byte unknown2[8];long MapTo;long Reward;long Objective')
	Local $lQuestPtr, $lQuestLogSize, $lQuestID
	Local $lOffset[4] = [0, 0x18, 0x2C, 0x534]

	$lQuestLogSize = MemoryReadPtr($mBasePointer, $lOffset)

	If $aQuestID = 0 Then
		$lOffset[1] = 0x18
		$lOffset[2] = 0x2C
		$lOffset[3] = 0x528
		$lQuestID = MemoryReadPtr($mBasePointer, $lOffset)
		$lQuestID = $lQuestID[1]
	Else
		$lQuestID = $aQuestID
	EndIf

	Local $lOffset[5] = [0, 0x18, 0x2C, 0x52C, 0]
	For $i = 0 To $lQuestLogSize[1]
		$lOffset[4] = 0x34 * $i
		$lQuestPtr = MemoryReadPtr($mBasePointer, $lOffset)
		DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lQuestPtr[0], 'ptr', DllStructGetPtr($lQuestStruct), 'int', DllStructGetSize($lQuestStruct), 'int', '')
		If DllStructGetData($lQuestStruct, 'ID') = $lQuestID Then Return $lQuestStruct
	Next
EndFunc   ;==>GetQuestByID
I use TargetNearestEnemy in my current bots and its working fine, so I can only assume that you are using an outdated GWA2. Otherwise try using TargetNextEnemy or a similar function to see if that crashes also.

I never use quest data, but as far as I know the state of a quest can ONLY be read when the quest log is actually open because its visual data rather than readable data. Thats why most bots simple reset the quest (abandon and take it again) if they need it.

Hope that helps.
Underavelvetmoon is offline  
Old 12/29/2023, 12:46   #8
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
Quote:
Originally Posted by Underavelvetmoon View Post
I use TargetNearestEnemy in my current bots and its working fine, so I can only assume that you are using an outdated GWA2. Otherwise try using TargetNextEnemy or a similar function to see if that crashes also.

I never use quest data, but as far as I know the state of a quest can ONLY be read when the quest log is actually open because its visual data rather than readable data. Thats why most bots simple reset the quest (abandon and take it again) if they need it.

Hope that helps.
Seems that I have an outdated GWA2. Both TargetNearestEnemy and TargetNextEnemy are not working.

I searched in here for many bots and I have different gwa2 files but it seems they all are outdated, anyone likes to share a "current" gwa2 file with me?
dhanvin is offline  
Old 12/31/2023, 21:40   #9

 
elite*gold: 258
Join Date: Jan 2021
Posts: 132
Received Thanks: 142
Quote:
Originally Posted by dhanvin View Post
Seems that I have an outdated GWA2. Both TargetNearestEnemy and TargetNextEnemy are not working.

I searched in here for many bots and I have different gwa2 files but it seems they all are outdated, anyone likes to share a "current" gwa2 file with me?
Probably one of the most up to date public ones you'll find:
Mrjambix is offline  
Thanks
1 User
Old 01/11/2024, 17:24   #10
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
thanks, it seems to work now.
dhanvin is offline  
Old 01/15/2024, 00:39   #11
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
Is anyone able to help me get my Salvage code to work?

I have the following but it crashes when using it:

Code:
$aitem = GetItemBySlot(1, 1)
Local $lItemID = DllStructGetData($aitem, 'ID')
$itemStruct = GetItemByItemID($lItemID)
Local $lItemName = GetItemName($itemStruct)
StartSalvage($aitem)
Code:
;~ Description: Starts a salvaging session of an item.
Func StartSalvage($aItem, $aExpert = False)
	Local $lOffset[4] = [0, 0x18, 0x2C, 0x690]
	Local $lSalvageSessionID = MemoryReadPtr($mBasePointer, $lOffset)

	If IsDllStruct($aItem) = 0 Then
		Local $lItemID = $aItem
	Else
		Local $lItemID = DllStructGetData($aItem, 'ID')
	EndIf

	Local $lSalvageKit = 0
	If $aExpert Then
		$lSalvageKit = FindExpertSalvageKit()
	Else
		$lSalvageKit = FindSalvageKit()
	EndIf
	If $lSalvageKit = 0 Then Return

	logFile($lSalvageKit)

	DllStructSetData($mSalvage, 2, $lItemID)
	DllStructSetData($mSalvage, 3, $lSalvageKit)
	DllStructSetData($mSalvage, 4, $lSalvageSessionID[1])

	Enqueue($mSalvagePtr, 16)
EndFunc   ;==>StartSalvage
dhanvin is offline  
Old 01/17/2024, 11:33   #12
 
elite*gold: 0
Join Date: Jun 2023
Posts: 13
Received Thanks: 21
Are you sure you do have GetItemName($...) in your GWA2 or botfile?
Else delete it. Honestly delete it anyway, because its not needed for salvaging.
Young Signorino is offline  
Old 01/19/2024, 17:37   #13

 
elite*gold: 258
Join Date: Jan 2021
Posts: 132
Received Thanks: 142
Quote:
Originally Posted by dhanvin View Post
Is anyone able to help me get my Salvage code to work?

I have the following but it crashes when using it:

Code:
$aitem = GetItemBySlot(1, 1)
Local $lItemID = DllStructGetData($aitem, 'ID')
$itemStruct = GetItemByItemID($lItemID)
Local $lItemName = GetItemName($itemStruct)
StartSalvage($aitem)
Code:
;~ Description: Starts a salvaging session of an item.
Func StartSalvage($aItem, $aExpert = False)
	Local $lOffset[4] = [0, 0x18, 0x2C, 0x690]
	Local $lSalvageSessionID = MemoryReadPtr($mBasePointer, $lOffset)

	If IsDllStruct($aItem) = 0 Then
		Local $lItemID = $aItem
	Else
		Local $lItemID = DllStructGetData($aItem, 'ID')
	EndIf

	Local $lSalvageKit = 0
	If $aExpert Then
		$lSalvageKit = FindExpertSalvageKit()
	Else
		$lSalvageKit = FindSalvageKit()
	EndIf
	If $lSalvageKit = 0 Then Return

	logFile($lSalvageKit)

	DllStructSetData($mSalvage, 2, $lItemID)
	DllStructSetData($mSalvage, 3, $lSalvageKit)
	DllStructSetData($mSalvage, 4, $lSalvageSessionID[1])

	Enqueue($mSalvagePtr, 16)
EndFunc   ;==>StartSalvage
What specific crash error are you encountering?
Did you check header values for ItemSalvage are accurate?
I don't see any issue with the Function from your GWA2. Your call function can be a bit simpler but it does the job with no issues.
Mrjambix is offline  
Old 01/21/2024, 17:57   #14
 
elite*gold: 0
Join Date: Dec 2023
Posts: 15
Received Thanks: 0
Quote:
Originally Posted by Mrjambix View Post
What specific crash error are you encountering?
Did you check header values for ItemSalvage are accurate?
I don't see any issue with the Function from your GWA2. Your call function can be a bit simpler but it does the job with no issues.
Code:
;GAME_CMSG_ITEM_SALVAGE_MATERIALS
Global Const $HEADER_SALVAGE_MATS = 0x78			;Salvages materials from item
;GAME_CMSG_ITEM_SALVAGE_UPGRADE
Global Const $HEADER_SALVAGE_MODS = 0x79			;Salvages mods from item
;GAME_CMSG_ITEM_SALVAGE_SESSION_OPEN
Global Const $HEADER_SALVAGE_SESSION = 0x75			;Salvages mods from item
the client freezes.

How do I find the current gwa2 Headers? Is there a way to find it via gwtoolbox?
dhanvin is offline  
Old 01/21/2024, 20:15   #15

 
elite*gold: 258
Join Date: Jan 2021
Posts: 132
Received Thanks: 142
Quote:
Originally Posted by dhanvin View Post
Code:
;GAME_CMSG_ITEM_SALVAGE_MATERIALS
Global Const $HEADER_SALVAGE_MATS = 0x78			;Salvages materials from item
;GAME_CMSG_ITEM_SALVAGE_UPGRADE
Global Const $HEADER_SALVAGE_MODS = 0x79			;Salvages mods from item
;GAME_CMSG_ITEM_SALVAGE_SESSION_OPEN
Global Const $HEADER_SALVAGE_SESSION = 0x75			;Salvages mods from item
the client freezes.

How do I find the current gwa2 Headers? Is there a way to find it via gwtoolbox?
The headers are accurate, are you trying to ONLY Salvage? or is there more functions to this? Post the entire script so we can take a look at it.
Mrjambix is offline  
Reply


Similar Threads Similar Threads
beginner in private server programming
11/14/2014 - CO2 Private Server - 3 Replies
Hello, I'm daniel and I'm a c# and vb.net programmer (well everything I write in a language i can manage and write it in the other language). I am not a professional since I am a self taught orgrammmer. I've downloaded Redux source by pro4never and successfully ran the server. Well it was pretty easy to figure out how to add new npc and these basic stuff but for example when I go to the function or the procedure of writing the NPC I don't understand most of the code written inside them. In...
Beginner sucht Beginner
04/04/2014 - Starcraft 2 - 7 Replies
Moinmoin, Suche einen "Beginner", d.H erstmal gegen K.I üben, wenn man das nachher dann abgehakt hat, vllt mal gegen echte Spieler. Zu mir: 17 Jahre alt, Headset vorhanden, im Moment viel Zeit. Zu euch: Mindestens über 18 und Stimmlich bitte weit über 18... Headset solltet ihr ein Funktionstüchtiges haben, zum quatschen und absprechen. Könnt mich ja mal in Steam adden, oder eine PM an mich, dann gebe ich euch Battle.net ID und Code Steam ID: DLIKP, habe ein Engelsbild



All times are GMT +1. The time now is 23:40.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.