SRL Archive - SRL Suggestions

GetWildernessLevel


litoris

2012-10-23 14:59:55

(*
GetWildernessLevel
~~~~~~~~~~~~

.. code-block:: pascal

function GetWildernessLevel: Integer;

Returns the wilderness level. Defaults to -1 if the number can't be read (out of wilderness)

.. note::

by litoris

Example:

.. code-block:: pascal

*)
function GetWildernessLevel : Integer;
var
Lev : String;
begin
Lev := GetNumbers(GetTextAtExWrap(490, 85-50, 508, 102-50, 0, 10, 1, 1939681, 20, XPChars));
if ((Lev <> '') or (Lev <> ' ') or (Lev <> ' ') or (Lev <> ' ')) then
Result := StrToInt(Lev)
else
Result := -1;
end;

I came up with this manually while working on my current script, I was amazed that the include didn't have such a function yet.
Anyway, this function basically read the wilderness level. I tested it at various levels, it works, but I would really like it if some others could also test it. I have to use getnumbers, or else the string will also include a few colons when you are at single-digit levels.
It's uses are twofold: It can both tell you what level you are(useful for teleporting) and tell you whether you are in the wilderness, because it returns -1 if the string is empty. I'll send a pull request after some people test it, don't want a disaster like the last time :P

Nebula

2012-10-23 15:09:16

Seems like a handy function when working in the wilderness. Might I suggest using InRange just to make it look a bit cleaner?
function GetWildernessLevel : Integer;
begin
result := StrToInt(GetNumbers(GetTextAtExWrap(490, 85-50, 508, 102-50, 0, 10, 1, 1939681, 20, XPChars)));
if not InRange(result, 1, 60) then
result := -1;
end;
E: Sorry- I originally just changed it to have InRange instead of that nasty "or" thing. But then I noticed one thing that could be changed and another and another so I guess I kind of ruined it for you.

E2: I appologize for this but
function GetWildernessLevel : Integer;
begin
result := StrToIntDef(GetNumbers(GetTextAtExWrap(490, 85-50, 508, 102-50, 0, 10, 1, 1939681, 20, XPChars)), -1);
end;

Mat

2012-10-23 15:23:59

Nice Idea but can I ask what would the use be?
Mat

Olly

2012-10-23 15:36:14

If not wildernesslevel = 52 then
writeln('we are dead!');

if wildernesslevel = 32 then
walktohere

litoris

2012-10-23 16:14:30

From: Nebula

E2: I appologize for this but
function GetWildernessLevel : Integer;
begin
result := StrToIntDef(GetNumbers(GetTextAtExWrap(490, 85-50, 508, 102-50, 0, 10, 1, 1939681, 20, XPChars)), -1);
end;

Yeah this looks fine, I have never worked with def functions before, but I guess this does exactly what my function did. Can you test it?
From: Ollybest
If not wildernesslevel = 52 then
writeln('we are dead!');

if wildernesslevel = 32 then
walktohere


Exactly. My script, for example, keeps running south until the level is below 20, and then teleports. Saves me from teh trouble of making tons of maps/ODTM paths.

Nebula

2012-10-23 18:04:45

From: litoris
Yeah this looks fine, I have never worked with def functions before, but I guess this does exactly what my function did. Can you test it?


Yeah, Just tested it- works fine.

Rezozo

2012-10-23 19:59:25

I say this is very useful! Great job! ++ for you!

litoris

2012-10-24 02:25:45

Sent pull req with Nebula's version:https://github.com/SRL/SRL-5/pull/99

P1ng

2012-10-24 02:36:45

Looks good litoris! I have no plans for scripting in the wilderness as of yet, but I'm sure this will be handy for those who do :) I'm kind of suprised there wasn't already one too, to be honest.

Ashaman88

2012-10-24 07:36:33

Nice! I'll be sure to use this :) Thanks man!

speedster

2012-10-28 12:18:47

Suggestion to improve reliability : You should take note that when the XP counter is enabled the wildy icon changes places, thus you should search in 2 places.

litoris

2012-10-28 12:21:10

From: speedster
Suggestion to improve reliability : You should take note that when the XP counter is enabled the wildy icon changes places, thus you should search in 2 places.


I'm definitely adding that.
This is pretty much a snippet right now, I'm making a version that gives you both the Wilderness level and tells you whether you are in the wildy or not. I will add a check at the beginning to adjust the function so that it searches in the correct place, thanks for that.

Enslaved

2012-10-28 12:27:19

Good job lit +rep

Edit: sorry cant rep you. [Error MSG]You must pass some reputation around before you can give it to litoris[/Error MSG]

Ian

2012-12-19 00:31:42

Unfortunately this is broken because of the EOC graphical update :(

ssshhhaaa

2012-12-19 02:06:28

This is useful! Can you update it :)

Ian

2012-12-21 04:32:03

Fixed it :)
Function GetWildernessLevel : Integer;   
begin
result := StrToIntDef(GetNumbers(GetTextAtExWrap(490, 35, 508, 175, 0, 10, 1, 1939681, 20, XPChars)), -1);
end;
Tested and working with XP bars and no XP bars.

DrChill

2012-12-21 15:41:57

Awesome, I'll be writing a wildy script soon, and this should come in handy :)