Page 1 of 2

Bazaar Search Conversion

Posted: Mon May 10, 2004 11:58 am
by semper
The following is my attempt at converting Driftinsupra's Dumpster dive script. I'm only interested in the bazaar search function using an .ini without the movement so that's all I've included here. I realize my attempt is ridiculously newbie-ish and probably mostly just plain wrong but it's the best I've been able to do given that I really don't know what I'm doing at all. Can I get some hints or examples to assist me in working this out? I wouldn't ask if I hadn't already spent weeks reading and trying to learn how to do this myself.

Old code:

Code: Select all

|Driftinsupra's first usefull macro bazarr.mac 
|Dumpster diving script. Buy from players and sell to merchants for a profit! 

#turbo 

sub main 

/declare file global 
/declare isle global 
/declare counter local 
/declare l1 local 
/declare traderid local 
/declare price local 

/varset file C:\mq2\ini\bazprice.ini 
/varset counter 1 
:mainloop 

/if "$ini(@file,names,val@counter)"=="NOTFOUND" { 
    /echo Starting search over 
    /varset counter 1 
    /goto :mainloop 
    } 
/echo searching for $ini(@file,names,val@counter) 
/bzsrch race any class any $ini(@file,names,val@counter) 

| is request done? 
:loop 
/delay 1  
/if "$bazaar()"=="FALSE" /goto :loop 

/if n $bazaar(count)==0 { 
    /echo $ini(@file,names,val@counter) not found, continuing on... 
    /varadd counter 1 
    /varset counter $int(@counter) 
    /goto :mainloop 
    } 
      
} else { 
    /echo found $bazaar(count) items 
} 

/varset price $bazaar(0,price) 
/varset traderid $bazaar(0,trader) 

/if n $bazaar(count)>1 { 
    /for l1 1 to $calc($bazaar(count)-1) 
        /echo @l1 price $bazaar(@l1,price) 
        /if n @price>$bazaar(@l1,price) { 
            /varset price $bazaar(@l1,price) 
            /varset traderid $bazaar(@l1,trader) 
        } 
    /next l1 
} 
/if n @price>=$ini(@file,prices,val@counter) { 
    /varadd counter 1 
    /varset counter $int(@counter) 
    /echo @counter 
    /goto :mainloop 
    } 
/echo targeting @traderid 
/target id @traderid 
/face

And my attempt...

[code]#turbo

Sub Main 

/declare file global 
/declare counter local 
/declare l1 local 
/declare traderid local 
/declare price local 

/varset file c:\mq2\ini\bazprice.ini 
/varset counter 1
:mainloop 

/if (${ini[${File},${Names},${Val},${Counter}]==[NOTFOUND]}) {
    /echo Starting search over  
    /varset counter 1 
    /goto :mainloop 
    }  
/echo searching for ${ini.file.names.val.counter} 
/bzsrch race any class any ${ini.file.names.val.counter}


| is request done? 
:loop 
/delay 1   
/if (${bazaar()==[FALSE]}) /goto :loop

 
/if (${n{bazaar.count==0}}) {   
    	/echo ${ini{file.names.val.counter}} not found, continuing on…
       /varadd counter 1  
    /varset counter ${int.counter}
	/goto :mainloop 
    } 
      
} else { 
    /echo found ${bazaar.count} items
} 
 
/varset price ${bazaar.0.price}
/varset traderid ${bazaar.0.trader}
/if (${n{bazaar.count>1}}) { 
    /for l1 1 to ${calc{bazaar.count-1}} 
        /echo ${l1} price ${bazaar.l1.price} 
        /if (${n{price>bazaar.l1.price}}) { 
            /varset price ${bazaar.l1.price} 
            /varset traderid ${bazaar.l1.trader} 
        } 
    /next l1 
} 
/if (${n.price>=${ini{file.prices.val.counter}}}) { 
    /varadd counter 1 
    /varset counter ${int{counter}} 
    /echo ${counter} 
    /goto :mainloop 
    } 
/echo targeting ${traderid} 
/target id ${traderid} 
/face


I've gotten very good at searching for "null" and targeting "null" as I'm sure you'll see. :)

Thanks,
Semper

Posted: Tue May 11, 2004 7:52 pm
by semper
closer....maybe

Code: Select all

#turbo

Sub Main 

/declare File outer 
/declare Counter int local 
/declare l1 local 
/declare Traderid local 
/declare Price local 

/varset File c:\mq2\ini\bazprice.ini 
/varset Counter 1
:mainloop 

/if (${ini{${File},${Names},[${val.Counter}]}==NOTFOUND) {
    /echo Starting search over  
    /varset Counter 1 
    /goto :mainloop 
    }  
/echo searching for ${ini[${File},${Names},${val},${Counter}]} 
/bzsrch race any class any ${ini[${File},${Names},${val},${Counter}]}


| is request done? 
:loop 
/delay 1   
/if (${Bazaar.Done}==FALSE) /goto :loop

 
/if (${n{Bazaar.Count}==0}) {   
    	/echo ${ini[${File},${Names},${val},${Counter}]} not found, 

continuing on…
       /varadd Counter 1  
    /varset Counter ${Int.Counter}
	/goto :mainloop 
    } 
      
} else { 
    /echo found ${Bazaar.Count} items
} 
 
/varset Price ${Bazaar.Item[1].Price}
/varset Traderid ${Bazaar.Item[1].Trader}
/if (${n{bazaar.count>1}}) { 
    /for l1 1 to ${math.calc{Bazaar.Count-1}} 
        /echo ${l1} Price ${Bazaar.l1.Price} 
        /if (${n{price>Bazaar.l1.Price}}) { 
            /varset Price ${Bazaar.l1.Price} 
            /varset Traderid ${Bazaar.l1.Trader} 
        } 
    /next l1 
} 
/if (${n.Price}>=${ini${File},${Prices},${val},${Counter}}) { 
    /vardata Math.Calc[${Counter}+1]
    /varset Counter ${int{Counter}} 
    /echo ${Counter} 
    /goto :mainloop 
    } 
/echo targeting ${Traderid} 
/target id ${Traderid} 
/face

could use a /delay condition

Posted: Wed May 12, 2004 1:42 pm
by Chill
Could use a longer /delay, with a condition to end it early, while waiting on the search:

Code: Select all

| is request done? 
:loop 
/delay 1    
/if (${Bazaar.Done}==FALSE) /goto :loop
Becomes:

Code: Select all

/delay [color=red]10s[/color] ${Bazaar.Done}==TRUE
Could use whatever delay you wanted, of course, in place of the 10s I picked.

Posted: Wed May 12, 2004 4:58 pm
by semper
Agreed Chill, it does search a bit faster than human.
Still searching for and targeting null so I've gone back to the beginning and started from scratch. Read until my eyes starting bleeding again. Couldn't figure out how to draw info from my ini correctly despite trying about a million things and looking for similar examples in other posts. As I said, I'm really stumbling around in the dark with this.
Anyway, here is what I've put together to test to see if I'm on the right track. Can't test it yet due to the patch but any comments?

Code: Select all

Sub Main

/declare File local
/declare Counter int local


/varset File bazprice.ini


/varset Counter 1

/echo ${String["Searching for [$ini{File,Names,${val${Counter}}}]"]
bzsrch race any class any ${String["$ini{File,Names,{val${Counter}}}"]


| is request done? 
:loop 
/delay 1   
/if (${Bazaar.Done}==FALSE) /goto :loop

/endmacro

If it works like I want it to it should echo: Searching for [the first entry in my ini] and then search for that item once and stop. The only thing before this that seemed to work correctly is that last part from :loop on down.

Posted: Wed May 12, 2004 5:36 pm
by Chill

Code: Select all

/delay [color=green]MaxTimeToWaitForSearch[/color] ${Bazaar.Done}==TRUE | (Edit in your own desired [color=green]Search Time[/color])
Still looks a whole lot smoother to me than:

Code: Select all

| is request done? 
:loop 
/delay 1    
/if (${Bazaar.Done}==FALSE) /goto :loop
They added a condition to end a delay early on May 9th:
Lax wrote:09 May 2004 by Lax:
- Added optional parameter to /delay.
Usage: /delay <time> [condition to end early]
This lets you use a delay that has a possibility to end early. For example...
/keypress forward hold
/delay 1s ${Spawn[1234].Distance}<${Spawn[1234].MaxMeleeTo}
/keypress forward
No reason not to use it, imo.

Posted: Wed May 12, 2004 9:15 pm
by semper
Ty! I'll give that a go. :)

Posted: Wed May 12, 2004 11:36 pm
by semper
Well, no, I suck again. Another hundred variations with the same results. Can someone point me at a reference for how to handle .ini files (set to variable and then read values from it)? Every variation I've tried gives me "Searching for Null" or unable to parse.

How about a hint? Is it the /varset? /echo? /bzrsch? All of them?

My only bright note, this:

Code: Select all

/varset Counter 1
val${Counter}
gives me val1 as I want it to.

--Semper

Posted: Thu May 13, 2004 4:17 am
by mpmq
/echo ${String["Searching for [$ini{File,Names,${val${Counter}}}]"]

Is wrong. Try:

/echo Searching for ${ini[${File},Names,val${Counter}]}

Posted: Thu May 13, 2004 5:50 am
by ml2517
mpmq wrote:/echo ${String["Searching for [$ini{File,Names,${val${Counter}}}]"]

Is wrong. Try:

/echo Searching for ${ini[${File},Names,val${Counter}]}

*hint* make sure your case is correct when using commands. IE: ini = Ini

Posted: Thu May 13, 2004 7:07 am
by mpmq
Oops....typo on my part there....should start out ${Ini....

Thats what I get for posting after being up all night....

Posted: Thu May 13, 2004 12:14 pm
by semper
First of all ty!! The test was successful! Now for the strange part. When I went to paste the suggested change to the /echo line in the .mac file it was already there exactly as you suggested. It looks like I got the /echo part right accidentally at the end last night. I hadn't yet changed the bzsrch line to match and I think I had the /varset line screwed up with failed combos too. With the /echo line as known good the rest fell into place quickly (thanks to your help). Here is the successful test code:

Code: Select all

Sub Main

/declare File local
/declare Counter int local



/varset File Bazprice.ini
/varset Counter 1



/echo Searching for ${Ini[${File},Names,val${Counter}]}


/bzsrch race any class any ${Ini[${File},Names,val${Counter}]}


| is request done? 
:loop 
/delay 1   
/if (${Bazaar.Done}==FALSE) /goto :loop
Chill, I'll be putting in your suggestion for the delay line soon. Was kinda afraid to screw around with that part till I got the other working.

mpmq, ml2517, u rock!

Posted: Thu May 13, 2004 6:20 pm
by semper
Encouraged by my partial success, I plowed thru more of the code. After about |40 I'm still working on it:

Code: Select all

Sub Main

/declare File local
/declare Counter int local
/declare l1 int local 
/declare Traderid local 
/declare Price local
/declare Iniprice int local

/varset File Bazprice.ini
/varset Counter 1

:mainloop

|/if (!${${Ini[${File},Names,val${Counter}]}.Equal[NOTFOUND]}) {
	|/echo Starting search over
	|/varset Counter 1
	|/goto :mainloop
	|}

|20   

/echo Searching for ${Ini[${File},Names,val${Counter}]}


/bzsrch race any class any ${Ini[${File},Names,val${Counter}]}


| is request done? 
:loop 
/delay 10   
/if (${Bazaar.Done}==FALSE) /goto :loop

/if (${Bazaar.Count}==0) {
	/echo ${Ini[${File},Names,val${Counter}]} not found, continuing 

on...


	/varcalc Counter ${Counter}+1

|40	
	/goto :mainloop
	}
} else {
	/echo found ${Bazaar.Count} items
}
/varset l1 1
/varset Price ${Bazaar.Item[1].Price} 
/varset Traderid ${Bazaar.Item[${l1}].Trader}
/if (${Bazaar.Count}>1) {
	/for l1 1 to ${math.calc${Bazaar.Count}-1}
	/echo ${l1} Price ${Bazaar.Item[${l1}].Price}
	/if (${Price}>${Bazaar.Item[${l1}].Price}) {
		/varset Price ${Bazaar.Item[${l1}].Price}
		/varset Traderid ${Bazaar.Item[${l1}].Trader}
	}
	/next l1
}
/varset Iniprice ${Ini[${File},Prices,val${Counter}]}
/if (${Price}>=${Iniprice})  {
	/varcalc Counter ${Counter}+1
	/varset Counter int${Counter}
	/echo ${Counter}
	/goto :mainloop
	}
/echo Targeting ${Traderid}
/target id ${Traderid}
/face

/endmacro

Before I started screwing with the price comparison section (after |40, doesn't work yet) it was searching nicely thru the ini till it made a positive match. Oddly enough, after everything so far I'm having trouble getting it to do a simple math problem (numeric comparison) and also the /for loop is messed up but I don't understand those yet or how they interact with the search window.

As for the end, the targetting feature is targetting the nearest pc or npc but I think I know how to fix that part.
Always open for suggestions )

Posted: Thu May 13, 2004 8:06 pm
by mpmq
For targetting, try:

/varset Traderid ${Bazaar.Item[${l1}].Trader.ID}
....
/target id ${Traderid}

${Bazaar.Item[${l1}].Trader.Name} will give you the name of the trader.

Posted: Thu May 13, 2004 8:34 pm
by Still_a_newb

Code: Select all

${Bazaar.Item[x].Trader}
Returns the traders NAME, not the traders ID. So instead of

Code: Select all

/target id ${Traderid}
you should just use

Code: Select all

/target ${Traderid}

Posted: Thu May 13, 2004 10:51 pm
by semper
ack, wish i had checked here earlier. just spent a few hours of reading and trying combos and came up with:

Code: Select all

/declare Traderid local
/declare l1 int local
/varset l1 1
/varset Traderid ${Bazaar.Item[{l1}].Trader}
/echo Targeting ${Spawn[${Traderid}]}
/target ${Spawn[${Traderid}]}

It appears to do what I want anyway. Like watching a newb-child learning to walk huh?