This is a project I've been working on the past couple of days but it's something I've always wanted to do I just didn't have the enthusiasm to begin working on it. What this is, is a color record of an entity (NPCs & Players) in-game to give us accurate information of that same entity, like it's actual bounds, an auto-colored TPA, the base point, and so forth. I've only designed this, so far, to keep track of our own player. It's still primitive and restricted, with so much more work to do, but at its current stage it's more accurate than anything we have.
I first got the idea when thinking back on RSPS. If any of you are familiar with them the original engines were quite basic when it came to handling Players and NPCs, as there were class files for both to handle them separately. Later on we took a different approach and created a handler for both NPCs & Players; creatively enough the "EntityHandler". It made sense because both NPCs and Players share many same attributes such as drawn model, walking, animation, health... I always liked this so my plan is to reflect the same principle in SRL to handle on-screen moving entities.
-Possible uses (Player)-
- Could be used to track our player (at any camera angle) only on-screen and exclude others
- Based on our player's true on-screen position determine things like our health, animation, even facing direction
- Find an object/NPC that is truly closest to our player, no more sorting from the middle of the screen
- Determine the damage (and type of damage) our player is receiving
- Determine the camera 'pitch' (also would take a bit of work)
-Possible uses (NPC)-
- Determine which NPCs are currently in combat
- Constantly track a specific NPC while it moves (this will take some work though...)
- Determine if a certain NPC is being attacked (as well as damage type)
-How it works-
Quite simple actually, at the beginning of the scrip the user is asked to hover your mouse over your player's in-game top (not your players head, the top) and the color at that position will be recorded, and every similar color within a 15x20 radius will be recorded. Next you do the same for your player's bottom. After those colors are chosen the similar colors will be merged together (top and bottom are merged separately) to give us a 'best color, tolerance, and Sat/Hue mod). Later when the script calls the 'UpdatePlayer' procedure these colors are found, TPAs merged, split (to exclude nearby unwanted similar colors), and the end result is stored as, what I call, a "TEntity" type. This is what I have so far:
Simba Code:Type
TEntity = record
Bounds : TBox;
BasePnt : TPoint;
tCol,tTol,
bCol,bTol : Integer;
FullTPA : TPointArray;
tHMod,tSMod,
bHMod,bSMod : Extended;
end;
In the future this can include helmet, top, bottom, and the weapon/shield (if any). I plan to take what I have and eventually write an independent file to handle all of this, but as this is still in development I'm not exactly to that point yet. Here below is some examples of what I'm able to do with it so far:
-Debugging basic attributes-
^ Only the mouse position in the last image is set on the player's "BasePoint".
-Finding direction of objects to our player-
^ Note the box is not the actual fishing spot that was found, that's the area in which the script is searching for the fishing spot. The box is only displayed when a fishing spot is found in any direction of the player; dynamics.
-Accurately finding our player's health bar-
^ As you know when you rotate the camera your player is no longer located, on-screen, in the same position as before. Also over time (and map region change) your player also shifts on-screen position. It's for this reason that determining our player's health, while excluding other health bars, is so difficult. But luckily this entity handler searches for the health bar only according to player's model on-screen and not a static search area. What you see above is where the script is searching for the health bar, at all 4 angles.
So I guess that's it for now. I'll continue tweaking this bit by bit and making more snippets that will run off of this system. Of course there's always room for errors and inaccuracies and thinking ahead I believe there always will be. But this is a solid start and a very handy tool for scripters. Oh one more thing, I've only designed this for OSRS as that's all I'm focusing on now days. If you have any questions or comments post away and I'll try to answer to the best of my knowledge.