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:
Simba Code: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 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