[AI] cRoot:Get():ForEachMob - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: [AI] cRoot:Get():ForEachMob (/thread-1747.html) Pages:
1
2
|
[AI] cRoot:Get():ForEachMob - wudles - 01-26-2015 I guess this a request more than anything else. How hard would it be to add a function cRoot:Get():ForEachMob that mimics cRoot:Get():ForEachPlayer ? This would be a great start to work on the AI and only require the HOOK_WORLD_TICK as a starting point. RE: [AI] cRoot:Get():FindAndDoWithMob - xoft - 01-26-2015 What would it be "Finding" the mob by? (Find uses fuzzy matching, DoWith uses exact matching.) Once you have the mob's ID, you can call cWorld:DoWithEntityByID(). True, you need to know the correct cWorld. RE: [AI] cRoot:Get():FindAndDoWithMob - wudles - 01-26-2015 (01-26-2015, 04:57 AM)xoft Wrote: What would it be "Finding" the mob by? (Find uses fuzzy matching, DoWith uses exact matching.) Actually, it would be more like "ForEachPlayer" ... so "ForEachMob" ... that way we can loop through each mob and check what we did with it last and what it needs to do next. RE: [AI] cRoot:Get():ForEachMob - xoft - 01-26-2015 There's a cWorld:ForEachEntity() that you can use. Just check if it's a monster as the first thing of the callback RE: [AI] cRoot:Get():ForEachMob - wudles - 01-26-2015 (01-26-2015, 05:21 AM)xoft Wrote: There's a cWorld:ForEachEntity() that you can use. Just check if it's a monster as the first thing of the callback Ok. I'm on it. RE: [AI] cRoot:Get():ForEachMob - wudles - 01-26-2015 (01-26-2015, 01:32 PM)wudles Wrote:(01-26-2015, 05:21 AM)xoft Wrote: There's a cWorld:ForEachEntity() that you can use. Just check if it's a monster as the first thing of the callback Oh, this is cool. I'm using on tick to cycle through the mobs and having them move towards the closest logged in players. Fun, fun, fun. RE: [AI] cRoot:Get():ForEachMob - xoft - 01-26-2015 You might want to dial down on the frequency, otherwise you'll overload the server pretty soon. Only set the target once every second or so, that should be sufficient. Even better, distribute the load into multiple passes - for example four passes per second and pass #N processes entities for which (ID % 4) == N. RE: [AI] cRoot:Get():ForEachMob - wudles - 01-27-2015 (01-26-2015, 06:47 PM)xoft Wrote: You might want to dial down on the frequency, otherwise you'll overload the server pretty soon. Only set the target once every second or so, that should be sufficient. Even better, distribute the load into multiple passes - for example four passes per second and pass #N processes entities for which (ID % 4) == N. That's the plan. I store all the entities in a sqlite3 database, and only update those that have not been updated in the last 2 seconds -- for now. The logic will have to change based on their status ... hunting, walking, combat, etc... But this is a just an attempt to get some smarts into the mobs. RE: [AI] cRoot:Get():ForEachMob - xoft - 01-27-2015 I think SQLite is an overkill for this, going through all the interfaces and all the locking. A simple Lua table would probably be an easier solution. RE: [AI] cRoot:Get():ForEachMob - wudles - 01-27-2015 (01-27-2015, 01:39 AM)xoft Wrote: I think SQLite is an overkill for this, going through all the interfaces and all the locking. A simple Lua table would probably be an easier solution. The problem is that I know sqlite, and I am new to Lua. I'm abstracting the data structure, so I could easily change it once I have it working. Although, this http://lua-users.org/wiki/TablesTutorial makes it seem easy. I guess I'll just use the Lua tables. They will do what I need. |