- 0
How to find nearest enemy/obtain a list of units on the same map, etc...
Asked by
Seravy
-
Recently Browsing 0 members
- No registered users viewing this page.
Asked by
Seravy
By using this site, you agree to our Terms of Use and Privacy Policy.
I'm trying to implement a @ command that makes the character have limited autopilot capabilities like, buff or attack the nearest thing. I'm playing the game alone on my server and would like to use multiple characters...but there is a limit to how many I can play actively at a time, and it's not very fun to do it that way. I tried using a bot but it didn't work but then I realized "hey I can just make the server do it for me, even better and I get to code all the AI". Yes, I'm crazy enough to play RO as a single player game, but even then, I'm going to need a party to fight the stronger enemies :)
So I was able to add the command (and tested it actually works by outputting a message), made it get stored in a variable : sd->autopilotmode = 1;, added a new timer to unit.cpp, got as far as
// @autopilot timer int unit_autopilot_timer(int tid, unsigned int tick, int id, intptr_t data) { struct block_list *bl; struct unit_data *ud; int target_id; bl = map_id2bl(id); if (!bl || bl->prev == NULL) return 0; ud = unit_bl2ud(bl); if (!ud) return 0; if (bl->type != BL_PC) // Players are handled by map_quit { ShowError("Nonplayer set to autopilot!"); return 0; } struct map_session_data *sd = (struct map_session_data*)bl; if (sd->status.autopilotmode==0) { return 0; } // Tanking mode is set if (sd->status.autopilotmode == 1) { }although this is mostly guessing so far, but here I'm stuck. How do I find the nearest enemy (or party member, for buffs) to target? Tried searching for other code parts that target monster attacks and similar but it looks way too complicated. It's hard without even knowing what each structure is for. Didn't see any Findnearest kind of functions anywhere either. In fact I don't even know how to access a list of units on the same map. I think I'm going to need to call "clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)" to execute the action but first I need to somehow find a target.
Link to comment
Share on other sites