PDA

View Full Version : How to use random solvers in OSR



Ashaman88
04-07-2013, 02:02 PM
Well hello there! I wrote this guide to help people understand both how the solvers work for OSR as well as how to best implement them into your script.


Random Detection

To better understand how the solvers work, how do we detect the randoms?

Talking Randoms

As most of you probably know, a good majority of the random events simply require you to talk to the npc (ex: drunken dwarf). For this, the approach in 2007 and the same we took when rewriting the randoms was to detect your player name being said said in the main screen. So we have a handy function to scan what is said in the mainscreen to figure out if something is talking to you and where the figure is positioned. Later in this guide I will discuss the implications of this.

Combat Randoms

Another good chunk of the randoms are combat related (ex: evil chicken). We found that the best way to handle this was to simply run away (and then back) if we detected your character is in combat. You are probably thinking..what if we are using a combat script? Well then, as a scripter, you can set SRL_COMBATRANDOMS := False; and it will disable the combat random solvers. Otherwise your character will constantly be running away! More discussion on customizing the combat solver is discussed below.

Skill Specific Randoms

For randoms that are skill specific (ex: ent), we are still discussing the best way to handle them. For now, and possibly going forward, it will be the scripters responsibility to detect and solve these.

Remaining Randoms

The remaining randoms use a variety of techniques to detect where you are (missing game tabs, music, inventory makeup, etc.). These solvers will either solve your random or, if disable, log you out and switch to the next character (if there is one). Also worth noting, this is the area where random developers need the most help in getting accounts stuck in randoms and is the category with the most work remaining.


Using and Implementing the Random Solvers

Generally speaking, all of the randoms are solved using findnormalrandoms;. See below for more specifics.


Talking Randoms

As the detection works by scanning for the players name being spoken in the main screen, there are a couple of key things you need to do.

1) Add a value to the .nick field of the player array like so:
Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := ''; // ***Username***
Players[0].Pass := ''; // ***PW***
Players[0].WorldInfo := []; // ***Desired World, leave blank if random***
Players[0].Nick := 'man88'; // ***Portion of display name, IMPORTANT FOR RANDOMS***
Players[0].LampSkill := Skill_Slayer;
Players[0].Active := True;
End;

This will set your nickname for the solver. You should generally just use 3-4 characters from your name (in the above snippet, assuming my name is "Ashaman88", I only put "man88". It must be consecutive characters and you should try and stay away from common 3 letter combos (ex: if your name has "and" in it, probably shouldn't use that, unless you have to). If you do not have anything in here, it WILL cause a runtime error when calling the random solvers. That is why it is important for the scripter to add a failsafe to shutdown the script if there is no value for that (in the future it may be handled by the include).

2) You MUST call declareplayers BEFORE you call setupsrl. setupsrl handles setting the nickname and will also cause a runtime error if you do not do it in that order (this also may be made to be more flexible in the future). If you still get the runtime error, redownload the include!

3) Another key thing to note is that it will only search for your nickname when you call findnormalrandoms. This is very important because the NPC's only say your name for about a second every 10seconds? or so. That means you need to call fnr as often as possible (Ex: if you are wc, in the loop you are waiting for the tree to fall calling fnr every 100ms or so). Another possibility is calling a findtalkwait function (more to be added on the actual function name and use) separately, which pauses your script for however long you tell it to and solely searches for your name.

4) A final important thing to note is that other people near you may cause false positives if they say your name. This is why it is also very important for scripters to set all chats off (or at least public), when starting up the script. You can use the setchat function to do this.

Combat Randoms

As mentioned above, you can disable these randoms by setting SRL_COMBATRANDOMS := False; at the start of your script, but you should only do so if you are using a combat script (or don't want your character to run away when under attack).

Another useful tool we added was to allow the scripter to determine which direction the character will run when it is under attack. This will prevent you from trying to run into an ocean and/or through an enclosed wall. This works by setting SRL_FindRandomRunDirection := ['W', 'N']; (whatever directions you want) at the start of your script. You can set it to just one direction, or all four! If there is more than one direction, the function will randomly select one of the directions to run in. Furthermore, if there are no directions set by the scripter, the function will assume all 4 directions are fair game.

Again combat randoms are solved and detected by findnormalrandoms.

Remaining Randoms

Just call findnormalrandoms :)


Conclusion

As you can see, there is still a lot of work to do and improvements to be made on random solvers. Please see here (http://villavu.com/forum/showthread.php?t=98207) for the current status of the solvers, and to also suggest new features, and lend accounts in randoms to developers. I will be adding more to this guide as developments occur as well!


Thanks

Also be sure to give a big thanks to each of the devs who have worked a lot on these solvers and the OSR include in general

Ashaman88; DannyRS; euphemism; J J; Justin; Le Jingle; Ollybest; slushpuppy


Please give feedback and suggestions :)

Justin
04-07-2013, 04:52 PM
Fantastic guide Ashaman, Gives the user very detailed information on how we detect randoms. Can't wait for future updates on this

Physic
04-07-2013, 05:04 PM
It doesnt matter which characters you choose in your nick right?
as long as they are consecutive letters

King
04-07-2013, 05:05 PM
Love the guide, nice read and easy to do! I like how it shows everyone how its done(:

Ashaman88
04-07-2013, 05:12 PM
It doesnt matter which characters you choose in your nick right?
as long as they are consecutive letters

yep :) and generally something not common - like if your name has "and" in it, that is probably not a good pick. I'll add more info

Le Jingle
04-07-2013, 05:38 PM
Very nice thread! :] There's some stuffs in here I didn't know until after reading :)

I suppose with this, I'll abort (for now) the auto nick parser :p

P.S. - [sidenote] I want a leo random :D

Ashaman88
04-07-2013, 05:54 PM
Very nice thread! :] There's some stuffs in here I didn't know until after reading :)

I suppose with this, I'll abort (for now) the auto nick parser :p

P.S. - [sidenote] I want a leo random :D

Don't give up! I've been meaning it respond to that thread ;). Plus it's always good as a backup :)

slushpuppy
04-07-2013, 06:17 PM
Only if hobbit merges my pull request ;d

slushpuppy
04-09-2013, 03:20 PM
Ashaman88;

https://github.com/SRL/SRL-OSR/commit/bc76dab89dbd936b813e922ab5982322a6fa4df5

Template:

{$DEFINE ANTIRANDOM_CUSTOMSETSOLVER}
{$DEFINE SMART}
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}

.....

procedure hatetheserandoms(log : Boolean);
begin
if FindObjDTM(MouseX,MouseY,upStairsDTM) OR FindObjDTM(MouseX,MouseY,downStairsDTM) then
begin
writeln('Hate these randoms');
Mouse(MouseX,MouseY,0,0,mouse_Left);
sleep(300);
end else MakeCompass('n');
FCRWait(2000);
if HPPercent(true) < 50 then
begin
writeln('Disabling script');
while not Logout do sleep(100);
TerminateScript;
end;
if log then
begin
sleep(12000);
while not Logout do sleep(100);
Sleep(5000 + Random(2000));
end;
end;
function AntiRandom_CustomSetSolver(name : String; args : T2DPointArray) : Boolean;
var
box : TBox;
begin
case name of
'Poison Gas':
begin
if (Length(args) > 0) AND FindObjDTM(MouseX,MouseY,upStairsDTM) then
begin
with MiddleTPA(args[0]) do
begin
if Distance(x,y,MSCX,MSCY) < 20 then
begin
writeln('fcking randoms');
hatetheserandoms(false);
sleep(50000);
end;
end;
end;
Result := True;
end;
'Combat Poison':
begin
hatetheserandoms(true);
writeln('Poison detected');
sleep(50000);
Result := True;
end;
'Combat':
begin
writeln('Combat detected')
hatetheserandoms(true);
Result := True;
end;
end;
end;
begin
{$IFDEF SMART}
{$IFDEF SIMBAMAJOR980}
Smart_Server := 72;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ELSE}
// SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
{$ENDIF}


DeclarePlayers;
SetupSRL;
FindNormalRandoms;
SRL_CombatRandoms := False;
repeat
begin
...
FindNormalRandomsCustom([SRL_ThievingRandoms,SRL_CombatRandomsEx]);
...
end;
until(false);

end.

Ashaman88
04-09-2013, 03:26 PM
Ashaman88;

https://github.com/SRL/SRL-OSR/commit/bc76dab89dbd936b813e922ab5982322a6fa4df5

Template:

{$DEFINE ANTIRANDOM_CUSTOMSETSOLVER}
{$DEFINE SMART}
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}

.....

procedure hatetheserandoms(log : Boolean);
begin
if FindObjDTM(MouseX,MouseY,upStairsDTM) OR FindObjDTM(MouseX,MouseY,downStairsDTM) then
begin
writeln('Hate these randoms');
Mouse(MouseX,MouseY,0,0,mouse_Left);
sleep(300);
end else MakeCompass('n');
FCRWait(2000);
if HPPercent(true) < 50 then
begin
writeln('Disabling script');
while not Logout do sleep(100);
TerminateScript;
end;
if log then
begin
sleep(12000);
while not Logout do sleep(100);
Sleep(5000 + Random(2000));
end;
end;
function AntiRandom_CustomSetSolver(name : String; args : T2DPointArray) : Boolean;
var
box : TBox;
begin
case name of
'Poison Gas':
begin
if (Length(args) > 0) AND FindObjDTM(MouseX,MouseY,upStairsDTM) then
begin
with MiddleTPA(args[0]) do
begin
if Distance(x,y,MSCX,MSCY) < 20 then
begin
writeln('fcking randoms');
hatetheserandoms(false);
sleep(50000);
end;
end;
end;
Result := True;
end;
'Combat Poison':
begin
hatetheserandoms(true);
writeln('Poison detected');
sleep(50000);
Result := True;
end;
'Combat':
begin
writeln('Combat detected')
hatetheserandoms(true);
Result := True;
end;
end;
end;
begin
{$IFDEF SMART}
{$IFDEF SIMBAMAJOR980}
Smart_Server := 72;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ELSE}
// SRL_SixHourFix := True;
Smart_FixSpeed := True;
{$ENDIF}
{$ENDIF}


DeclarePlayers;
SetupSRL;
FindNormalRandoms;
SRL_CombatRandoms := False;
repeat
begin
...
FindNormalRandomsCustoms([SRL_ThievingRandoms,SRL_CombatRandomsEx]);
...
end;
until(false);

end.




Sweet it finally went through! I'll add that section

Hoodz
04-11-2013, 06:18 PM
so we dont need to call: SetScreenName(Players[CurrentPlayer].Nick); ?

Haxz
04-11-2013, 06:20 PM
so we dont need to call: SetScreenName(Players[CurrentPlayer].Nick); ?

It's in the last line of SetupSRL.

Hoodz
04-11-2013, 06:22 PM
It's in the last line of SetupSRL.

okay thanks!

samerdl
04-14-2013, 01:19 PM
Lovely, how does this sound, split the none-teleportation randoms into two functions that a user can choose from(except sandwich lady and that guy miels/niels):
A) solve the none-teleportation randoms, genie, the captain, dwarf, strange plant, Jekyll etc..
B) Run away from them.

So it would be like this



Const
Flee := True; // If both are true script will terminate giving the error You cant have both solve and flee from random events on, choose one.
Solverandoms := False;


procedure players...;
begin....
Players[0].Nick := 'man88'; // ***Portion of display name, IMPORTANT FOR RANDOMS***
Players[0].LampSkill := Skill_Slayer;
Players[0].FleeRandoms := Flee;
Players[0].SolveRandoms := Solverandoms;
Players[0].Active := True;
End;


its just a thought

EngageTheRage
04-23-2013, 11:06 PM
heyyy ... so in my script i tried to use the FindNonInventoryRandoms most of the time and then threw in a few FindNormalRandoms ... however, it came up with an error when a random popped up ...

20885

sorry if im being stupid or something ... :)

got it again ... this is where the issue was ...

20899

Kevin
05-31-2013, 05:47 PM
I don't script OSR, I don't bot OSR, I don't even play OSR.

Buuuuut, I definitely think it's awesome the amount of work you guys have all put forth towards the OSR include and what you've all done for the community! Good job!