SRL Archive - OSR Help

Get Amount OSR


Sk1nyNerd

2013-04-14 15:56:48

Im trying to get the amount of some stackable items but the GetAmout(x,y) doesnt return 0's and the FindCoins(x,y,inv) wont return coin amounts greater then 99,999. I thought i read some where how to fix the GetAmount but cant find the thread.

Help?
Thanks

Le Jingle

2013-04-14 16:13:24

have you tried using, GetAmountBox function?

DannyRS

2013-04-14 16:37:21

Post some full client screenshots of coins, in loss-less format, that don't return right values, and I'll look into it for you,

Edit - in Fonts folder, does your "0" in StatChars07 look the this?

Sk1nyNerd

2013-04-14 17:36:19

From: Le Jingle
have you tried using, GetAmountBox function?

i believe that only works if the Invtentory spot is defined, but that isnt very "free" of user input if you know what i mean. the less they have to do the better :P

From: DannyRS
Post some full client screenshots of coins, in loss-less format, that don't return right values, and I'll look into it for you,

Edit - in Fonts folder, does your "0" in StatChars07 look the this?


yes, it looks exactly like that "0". sorry but whats loss-less format? still rather new to simba lol

EDIT: heres my code for the coins

procedure FindCoinAmount;
begin
if FindCoins(x, y, 'inv') then
begin
writeln('Coins found: '+ ToStr(GetAmount(x, y)));
end
else
writeln('Coins not found! Logging out...');
Logout;
terminatescript;
end;

and for the get item

procedure FindTicketAmount;
begin
if FindObjEx(i, j, ['se','rchery', 'icket'], [ticketcolor1, ticketcolor2, ticketcolor3], 5, 50, MIX1, MIY1, MIX2, MIY2) then
begin
MMouse(i,j,5,5);
ticketintial := GetAmount(i,j);
writeln('You have ' + ToStr(GetAmount(i,j)) + ' tickets.');
end
else
begin
ticketintial := 0;
writeln('You have 0 tickets.');
end;
end;

rj

2013-04-14 17:40:46

From: ibot_dung11
i believe that only works if the Invtentory spot is defined, but that isnt very "free" of user input if you know what i mean. the less they have to do the better :P



yes, it looks like exactly like that "0". sorry but whats loss-less format? still rather new to simba lol


.png so the image isn't deluded

DannyRS

2013-04-14 18:10:32

From: ibot_dung11
i believe that only works if the Invtentory spot is defined, but that isnt very "free" of user input if you know what i mean. the less they have to do the better :P


Post a screenshot of Smart with tickets in inventory, and I'll write you a function to return amount without any user input or mouse moving ;)

Sjoe

2013-04-14 18:37:45

From: ibot_dung11
saaaweet! :D haha



thanks
the coin function appears to be working now.


maybe remove your username :)


also
GetAmountBox(Invbox(i)) works better imo. i = slotplace. example: Slot 1 = InvBox(1)

Sk1nyNerd

2013-04-14 19:28:03

From: Sjoe
maybe remove your username :)


also
GetAmountBox(Invbox(i)) works better imo. i = slotplace. example: Slot 1 = InvBox(1)

shit haha please remove, ill update pic in a bit, at the gym. also I want the item to be free and not localized

Sk1nyNerd

2013-04-15 00:52:46

[ATTACH=CONFIG]20701[/ATTACH]

so sometimes it finds the amount of coins and sometimes it does not :frusty: also as you can see it returns the number of tickets without the zeros

Le Jingle

2013-04-15 01:54:49

Made an alternative solution based off the image you posted:


function GetAmountBox2(b: TBox): Integer;
var
i, m, x, y: Integer;
s: string; // string transformed into Integer
c: TIntegerArray; // Colors of gold money text
begin
Result := 0;
if not FindColor(x, y, SRL_OUTLINE_BLACK, b.X1, b.Y1, b.X2, b.Y2) then
Exit;

c := [65535, 65278, 16777215, 8453888];
for i := 0 to high(c) do
begin
s := GetTextAtExWrap(b.X1, b.Y1, b.X2, b.Y2, 0, 5, 2, c[i], 0, StatChars);
if (Length(s) > 0) then
Break;
end;
// Multiply result if there's a K or M (ex. 500K or 50M)
if (Pos('K', s) > 0) then
m := 1000
else if (Pos('M', s) > 0) then
m := 1000000;
// Replace mis-read o's or O's with zero's.
s := ReplaceRegExpr('[oO]', s, '0', True);
s := ReplaceRegExpr('[^0-9]', s, '', True); // Trim non-numbers from string
// Thus
Result := (StrToIntDef(GetNumbers(s), 1) * m);
end;

Works from my tests, to account for the mis-read zero's as upper case O's.

Sk1nyNerd

2013-04-16 19:49:33

From: Le Jingle
have you tried using, GetAmountBox function?

tried it just to see and it doesnt return the 0's either
From: Le Jingle
Made an alternative solution based off the image you posted:


function GetAmountBox2(b: TBox): Integer;
var
i, m, x, y: Integer;
s: string; // string transformed into Integer
c: TIntegerArray; // Colors of gold money text
begin
Result := 0;
if not FindColor(x, y, SRL_OUTLINE_BLACK, b.X1, b.Y1, b.X2, b.Y2) then
Exit;

c := [65535, 65278, 16777215, 8453888];
for i := 0 to high(c) do
begin
s := GetTextAtExWrap(b.X1, b.Y1, b.X2, b.Y2, 0, 5, 2, c[i], 0, StatChars);
if (Length(s) > 0) then
Break;
end;
// Multiply result if there's a K or M (ex. 500K or 50M)
if (Pos('K', s) > 0) then
m := 1000
else if (Pos('M', s) > 0) then
m := 1000000;
// Replace mis-read o's or O's with zero's.
s := ReplaceRegExpr('[oO]', s, '0', True);
s := ReplaceRegExpr('[^0-9]', s, '', True); // Trim non-numbers from string
// Thus
Result := (StrToIntDef(GetNumbers(s), 1) * m);
end;

Works from my tests, to account for the mis-read zero's as upper case O's.

cool! so I could see this procedure actually being done would I do writeln(Result); ? and to use this for tge tickets I would just change the colors?
the goal of the coins is to make sure there's enough to play a competition so greater than 200gp else logout and the tickets is to determine the exp gained and tickets gained. will there be a osr update that fixes this or should I replace the above function with the default coinamount for future reference. ill obviously have to put this in my code so it works for others aswell

Le Jingle

2013-04-16 20:35:50

From: ibot_dung11
tried it just to see and it doesnt return the 0's either

cool! so I could see this procedure actually being done would I do writeln(Result); ? and to use this for tge tickets I would just change the colors?
the goal of the coins is to make sure there's enough to play a competition so greater than 200gp else logout and the tickets is to determine the exp gained and tickets gained. will there be a osr update that fixes this or should I replace the above function with the default coinamount for future reference. ill obviously have to put this in my code so it works for others aswell


The above function reads the text colors of all stacks of items (not just coins) - at least that's what it should do afaik.
So, you shouldn't have to change any ``colors'' in it, as it should read them already. (if it doesn't let me know and post a .png of the non read stacked item)

As for an update to OSR, I'll look into it more and potentially yes to having this function replaced/update the current one.

-Lj

Sk1nyNerd

2013-04-16 21:01:23

From: Le Jingle
The above function reads the text colors of all stacks of items (not just coins) - at least that's what it should do afaik.
So, you shouldn't have to change any ``colors'' in it, as it should read them already. (if it doesn't let me know and post a .png of the non read stacked item)

As for an update to OSR, I'll look into it more and potentially yes to having this function replaced/update the current one.

-Lj

k, I understand this now. b is the inventory slot the item is located in then? like the orginal getamountbox

Sk1nyNerd

2013-04-16 22:38:01

From: Le Jingle
The above function reads the text colors of all stacks of items (not just coins) - at least that's what it should do afaik.
So, you shouldn't have to change any ``colors'' in it, as it should read them already. (if it doesn't let me know and post a .png of the non read stacked item)

As for an update to OSR, I'll look into it more and potentially yes to having this function replaced/update the current one.

-Lj


so I played around with all the options and yours worked but it did not work for values that did not have a K or M, just a simple math mistake.
if m doesnt equal 1000 or 1000000 then it must be 0 so the result s was being multiplied by 0. the edit version is below.
thanks Lj! :D :)

when s does not contain a K or M
[ATTACH=CONFIG]20737[/ATTACH]

when s does contain a K or M (notice the orginal GetAmountBox works correctly because there are no 0's in the coins but does not for the tickets which has 0's)
[ATTACH=CONFIG]20742[/ATTACH]

my edit, when s does not contain a K or M
[ATTACH=CONFIG]20739[/ATTACH]


my easy edit
function GetAmountBox2(b: TBox): Integer;
var
i, m, x, y: Integer;
s: string; // string transformed into Integer
c: TIntegerArray; // Colors of gold money text
begin
Result := 0;
if not FindColor(x, y, SRL_OUTLINE_BLACK, b.X1, b.Y1, b.X2, b.Y2) then
Exit;

c := [65535, 65278, 16777215, 8453888];
for i := 0 to high(c) do
begin
s := GetTextAtExWrap(b.X1, b.Y1, b.X2, b.Y2, 0, 5, 2, c[i], 0, StatChars);
//Multiply result by 1 if there is not a K or M (ex. 10)
if (Length(s) > 0) then
m := 1;
Break
end;
// Multiply result if there's a K or M (ex. 500K or 50M)
if (Pos('K', s) > 0) then
m := 1000
else if (Pos('M', s) > 0) then
m := 1000000;
// Replace mis-read o's or O's with zero's.
s := ReplaceRegExpr('[oO]', s, '0', True);
s := ReplaceRegExpr('[^0-9]', s, '', True); // Trim non-numbers from string
// Thus
Result := (StrToIntDef(GetNumbers(s), 1) * m);
end;

EDIT:
there for, the GetAmount(x,y) is now GetAmount2(x,y)
function GetAmount2(x, y: integer): integer;
begin
result := getAmountBox2(invBox(coordsToItem(x, y)));
end;

Sk1nyNerd

2013-04-17 01:11:15

From: DannyRS
Post a screenshot of Smart with tickets in inventory, and I'll write you a function to return amount without any user input or mouse moving ;)


how would you return the amount with out any mouse moving?? it moves the mouse to the item location every time and its sketchy up the wall

DannyRS

2013-04-17 04:03:31

From: ibot_dung11
how would you return the amount with out any mouse moving?? it moves the mouse to the item location every time and its sketchy up the wall


Post a screenshot I can write it, and I'll show you, it's hard to explain, I'd rather just show you

Shatterhand

2013-04-17 04:16:47

GetAmountBox works fine for me, make sure it uses StatChars07, not StatChars. To get the box use InvSlotToBox (or whatever its called).

Sk1nyNerd

2013-04-17 09:41:20

From: DannyRS
Post a screenshot I can write it, and I'll show you, it's hard to explain, I'd rather just show you


use one from above? :P

Sk1nyNerd

2013-04-21 19:48:38

so i think ive come to the conclusion if i want to find a specific object anywhere in my inventory and get that amount without the mouse moving over the object i have to use a findobjtpamulti type deal with the getamount. would this work? just curious before i start to pull my hair out if it doesnt lol
thanks

Le Jingle

2013-04-21 20:11:29

I forget what, but I've tested it and it works fine for me.

I think what shatterhand said is spot on, I forget if I ended up changing the zero in the statchars07 file or not, but it should work as long as the statchars07 is properly used in the includes.

Sk1nyNerd

2013-04-21 20:20:28

ya the getamount works but im trying to see if an item is in my inventory or not so ive been using the FindObjEx function so it can find the object anywhere in my inv, but it moves my mouse to the obj if it finds it and checks the uptext, so im wondering if i use the findobjtpamulti if it would produce the same result without moving my mouse to the object. its unnecssary for me to check the uptext

EDIT: noticed the findobjtpamulti uses uptext also… stopped bein an idiot and trying to over engineer it and just used a DTM. thanks

Sk1nyNerd

2013-05-27 18:24:01

i was having troubles with the P07 include and using the previous GetAmountBox, developed earlier in the thread, with it but I was able to edit it some more and now it works in the P07 include when ran with smart8- if anyone is intrested. sorry if grave digging, thought it would be useful to post on a relavent topic. idk maybe dannyrs will put it in the P07 include even though its about dead but i just called it GetAmountBox2

function GetAmountBox2(b: TBox): Integer; //Author Le Jingle, edited by ibot_dung11
var
i, m, x, y: Integer;
s: string; //String transformed into Integer
c: TIntegerArray; //Colors of gold money text
begin
Result := 0;
if not FindColor(x, y, 65536, b.X1, b.Y1, b.X2, b.Y2) then
Exit;

c := [65535, 65278, 16777215, 8453888];

for i := 0 to high(c) do
begin
s := GetTextAtExWrap(b.X1-2, b.Y1-2, b.X2+3, b.Y2+2, 0, 5, 2, c[i], 0, StatChars); //A box to read the 5 possible digits

if (Length(s) > 0) then
begin
m := 1; //Multiply result by 1 if there is not a K or M (ex. 100)
if (Pos('K', s) > 0) then //Multiply result if there's a K or M (ex. 500K or 50M)
m := 1000;
if (Pos('M', s) > 0) then
m := 1000000;
Break;
end;
end;

s := ReplaceRegExpr('[oO]', s, '0', True); //Replace mis-read o's or O's with zero's.
s := ReplaceRegExpr('[^0-9]', s, '', True); //Trim non-numbers from string

Result := (StrToIntDef(GetNumbers(s), 1) * m); //Thus
end;

function GetAmount2(x, y: integer): integer; //Author: Coh3n, edited by ibot_dung11
begin
result := GetAmountBox2(invBox(coordsToItem(x, y)));
end;