SRL Archive - Test corner

Gather & Store Inventory Information


Nadeem

2009-06-28 06:39:33

Hi,

I've thought of a new way of making accurate decisions for inventory related features, not sure though if its already been done and possible failed?

Anyway, what it does it first, grab a count of black colors inside the inventory spot and also choose 1 random color that is not related to the brown background, and counts the number of those colors and saves that. Then when you can relocate your items to what ever spots, and using the color indexes it will locate the item we are looking for, and I chose black and a random color as a failsafe kinda thing.

It can almost be like color reflection, since all the items have static colors, we can like store color arrays for the items and load em up. We don't necessarily have to add the exact amount aswell, we can make it a range of -3, +3, and if its between that range it 'assumes' and if it is wrong it will update it self :)

I've been already using it for my new script, and works pretty much flawlessly.
You don't gotta try it unless you wanna, I've just copied and pasted from what I'm using right now so you can see whats being done.

Please let me know what you think :) ~ Thanks!


function CountColorEx(BCol, BTol: Integer; B: TBox; var Col: Integer): Integer;
var
P: TPoint;
label
NewPoint;
begin
NewPoint:
P.x := RandomRange(B.x1, B.x2);
P.y := RandomRange(B.y1 + 19, B.y2);
Col := GetColor(P.x, P.y);
if (SimilarColors(BCol, Col, BTol) or (Col = 65536)) then goto NewPoint;

Result := CountColor(Col, B.x1, B.y1 + 19, B.x2, B.y2);
ns_Debug('CountColorEx', ' | Point.x: ' + IntToStr(P.x) +
' | Point.y: ' + IntToStr(P.y) +
' | Color: ' + IntToStr(Col) +
' | Result: ' + IntToStr(Result));
end;

function GetInventory: TStringArray;
var
B: TBox;
I, R, T: Integer;
begin
T := GetSystemTime;
for I := 1 to 28 do
if ExistsItem(I) then
begin
MMouseItem(I);
Wait(100 + Random(100));
with Fighter[Tzhaar.Player] do
begin
B := InvBox(I);
Inven[R].ID := I;
Inven[R].Item := Capitalize(Between(' ', ' /', rs_GetUpText));
Inven[R].ColRec := CountColor(16 shl 12, B.x1, B.y1 + 19, B.x2, B.y2);
Inven[R].PColRec := CountColorEx(3424328, 19, B, Inven[R].PCol);
SetLength(Result, R + 1);
Result[R] := Inven[R].Item;
ns_Debug('GetInventory', 'Result[' + IntToStr(R) + '] = ' + Result[R] +
' | ColRec = ' + IntToStr(Inven[R].ColRec));
R := R + 1;
end;
end;
ns_Debug('GetInventory', 'List Took: ' + IntToStr(GetSystemTime - T) + 'ms');
end;

function GetWeapons: TStringArray;
var
G: TStringArray;
I, II, R: Integer;
begin
G := GetInventory;
for I := 0 to High(G) - 1 do
begin
for II := 0 to High(Fighter[Tzhaar.Player].Weapons) do
begin
if (pos(Fighter[Tzhaar.Player].Weapons[II], G[I]) > 0) then
begin
SetLength(Result, R + 1);
Result[R] := G[I];
R := R + 1;
end;
end;
end;

for I := 0 to R - 1 do
ns_Debug('GetWeapons', 'Result[' + IntToStr(I) + ']: ' + Result[I]);
end;



~NS

ian.

2009-06-28 06:41:35

Can't test it without all the other procs/functions you use ;] (ns_Debug).

Nadeem

2009-06-28 06:49:40

From: Nadeem

you don't gotta try it unless you wanna, i've just copied and pasted from what i'm using right now so you can see whats being done.


From: 99_
can't test it without all the other procs/functions you use ;] (ns_debug).


;)



~ns

ian.

2009-06-28 06:57:18

I know, but you never said you can't test it at all :p

Nadeem

2009-06-28 07:08:37

lol kk I removed ns_debug and copied + pasted my type records, too lazy/busy to remove the unneeded ones so don't push me :p


type
TParamChoice = (Error, Report, Debug, Other);
TMonster = (Hur, Mej, Xil, Ket, Cave, Any);
TAction = (Nothing, LClick, RClick);
TSkills = (att, str, def, con, acc, rap, lon, dsp, spe);

TTzhaar = record
Player, BeginRun, EndRun: Integer;
Load: procedure(New: Boolean);
Find: function(Monster: TMonster; Action: TAction): Boolean;
FindEx: function(var x, y: Integer; Color, Tol, Limit: Integer;
Lum: Byte; St: string): Boolean;
end;

TInven = record
Item: string;
ID, ColRec, PCol, PColRec: Integer;
end;

TFighter = record
Weapon, Weapons: TStringArray;
Inven: array [0..27] of TInven;
Skill: array of TSkills;
Fight: array of TMonster;
BeginCB, EndCB: Integer;
FoodTab, WeaponTab: Integer;
BeginWork, EndWork, TotalWork: Integer;
Logins, Slept, BankTrips, EnteredCave: Integer;
FoodAte, SafeSpotted, Failsafes, AntiBans: Integer;
BeginLevel, EndLevel, BeginExp, EndExp: array of Integer;
EstHPGain, EstDamage, EstKills, EstGain: array [0..5] of Integer;
end;

var
Tzhaar: TTzhaar;
Fighter: array of TFighter;

function CountColorEx(BCol, BTol: Integer; B: TBox; var Col: Integer): Integer;
var
P: TPoint;
label
NewPoint;
begin
NewPoint:
P.x := RandomRange(B.x1, B.x2);
P.y := RandomRange(B.y1 + 19, B.y2);
Col := GetColor(P.x, P.y);
if (SimilarColors(BCol, Col, BTol) or (Col = 65536)) then goto NewPoint;

Result := CountColor(Col, B.x1, B.y1 + 19, B.x2, B.y2);
end;

function GetInventory: TStringArray;
var
B: TBox;
I, R, T: Integer;
begin
T := GetSystemTime;
for I := 1 to 28 do
if ExistsItem(I) then
begin
MMouseItem(I);
Wait(100 + Random(100));
with Fighter[Tzhaar.Player] do
begin
B := InvBox(I);
Inven[R].ID := I;
Inven[R].Item := Capitalize(Between(' ', ' /', rs_GetUpText));
Inven[R].ColRec := CountColor(16 shl 12, B.x1, B.y1 + 19, B.x2, B.y2);
Inven[R].PColRec := CountColorEx(3424328, 19, B, Inven[R].PCol);
SetLength(Result, R + 1);
Result[R] := Inven[R].Item;
R := R + 1;
end;
end;
end;

function GetWeapons: TStringArray;
var
G: TStringArray;
I, II, R: Integer;
begin
G := GetInventory;
for I := 0 to High(G) - 1 do
begin
for II := 0 to High(Fighter[Tzhaar.Player].Weapons) do
begin
if (pos(Fighter[Tzhaar.Player].Weapons[II], G[I]) > 0) then
begin
SetLength(Result, R + 1);
Result[R] := G[I];
R := R + 1;
end;
end;
end;
end;



~NS

ian.

2009-06-28 07:10:38

Haha sorry =X didn't mean to be annoying about it </3

Nadeem

2009-06-28 07:23:18

lolz dun wry bout it ;)



~NS

Sir R. M8gic1an

2009-06-29 23:29:47

Many systems like these have been done, but were never succesful / reliable enough. The first one that comes to my mind is Boreas' Black List Browsing.

If you implement an INI file into it, you could store items through script runs, and add items etc, where the changes would be save. It is a very good idea, i use it myself although slightly differently (dtm + color) and it works wonders.

If you develop a complex enough system, with basic but needed functions such as ItemCounting etc, i'll put it up in dev forums :)

~RM

Nadeem

2009-06-30 00:16:52

From: Rasta Magician
Many systems like these have been done, but were never succesful / reliable enough. The first one that comes to my mind is Boreas' Black List Browsing.

If you implement an INI file into it, you could store items through script runs, and add items etc, where the changes would be save. It is a very good idea, i use it myself although slightly differently (dtm + color) and it works wonders.

If you develop a complex enough system, with basic but needed functions such as ItemCounting etc, i'll put it up in dev forums :)

~RM


Hi,

I was actually thinking like an update from a server. We'll use a INI file thats OK, but when updates are needed, it can report back to our server and update records and automatically put up for and update download, so that the next time that user is about to use this plugin again it'll notify for an update for the INI file and update it. This way we won't have to manually keep updating everything and no need of collecting colors ourselves, the script can auto update with correct color ratios when needed :)

I'm ready to build something like this, right after I finish some other pending work :p



~NS