Hi everyone,
[problem]
in contrast to the game client, the npc trainers in proShine didn't stop you for battles.
[comment]
I asked the community for beta testing previously. Since no complaints were issued, I requested the pull into silv3r's master. Thanks for everyone participating
[downloads]
[functionallity]
In short - it mimics the game behaviour by battling npc trainers that are seeing the bot.
In some detail - PsuedoCode-form:
[example]
Here a short example. Note: this is drawn in illustrator, no visual represenation in proShine integrated at the moment
![[Image: probot_trainerbattlesonsight.png]](https://img3.picload.org/image/rwocpwow/probot_trainerbattlesonsight.png)
legend:
- standard proshine view
- grey boxes = bot view direction + range = guarded fields
- x = pathing crosses npc trainer's view = npc request battle
- circle = path not crossing = no battle request
[integration]
That's the easy part, it is enabled by default, since it is the acutal game client's behaviour. So you don't have to do anything, except upgrading proShine
But if you want to change this setting, I added two lua functions:
[!!beware!!]
Most scripts didn't consider trainerBattles, since it wasn't a thing up until now. Make sure your script properly handles "if not isWildBattle()" in it's onBattleAction().
*note: some universal scripts tend to get into a pokemon switch loop during trainer battles, because of this.
Here an example how one could look like.:
[problem]
in contrast to the game client, the npc trainers in proShine didn't stop you for battles.
[comment]
- I already did a lua script implementation of this feature, but it had some unwanted behaviour due to restrictions created by PROShine's implementation
- when the topic was opened another time, while silv3r was online for the piplup update, we came together. I then started on an PROShine implementation, this is the result
- testing is really hard, since battling can only be done once. If I somehow produced a bug, I wouldn't be able to replicate that scenario. I had to move to a different map and look for the same triggers, which isn't that easy to do. See [state | beta testers] needed for more.
I asked the community for beta testing previously. Since no complaints were issued, I requested the pull into silv3r's master. Thanks for everyone participating

[downloads]
- source code:github project
- compiled project: PROShine2.6.1_battle_trainers.zip
[functionallity]
In short - it mimics the game behaviour by battling npc trainers that are seeing the bot.
In some detail - PsuedoCode-form:
function onMapEntry()
-- fields seen by npc trainers
-- dict: key = guarded_field, value = npc trainer
-- Increases memory and is a little less readable, but allows lookups in O(1) instead of O(n).
calculate guarded_fields
function onMovement()
-- many checks, therefore that guarded_fields dict
if current_position in guarded_fields then
abourt movement
initate trainer battle
remove guarded fields of that npc from dict
else
apply actual movement
[example]
Here a short example. Note: this is drawn in illustrator, no visual represenation in proShine integrated at the moment

![[Image: probot_trainerbattlesonsight.png]](https://img3.picload.org/image/rwocpwow/probot_trainerbattlesonsight.png)
legend:
- standard proshine view
- grey boxes = bot view direction + range = guarded fields
- x = pathing crosses npc trainer's view = npc request battle
- circle = path not crossing = no battle request
[integration]
That's the easy part, it is enabled by default, since it is the acutal game client's behaviour. So you don't have to do anything, except upgrading proShine

But if you want to change this setting, I added two lua functions:
enableTrainerBattles() --game client behaviour
disableTrainerBattles() --old proShine behaviour
[!!beware!!]
Most scripts didn't consider trainerBattles, since it wasn't a thing up until now. Make sure your script properly handles "if not isWildBattle()" in it's onBattleAction().
*note: some universal scripts tend to get into a pokemon switch loop during trainer battles, because of this.
Here an example how one could look like.:
function onBattleAction()
--it's wild battle and we want to catch wild poke
if isWildBattle() and (isOpponentShiny() or not isAlreadyCaught()) then
--placeholder - implement your catch behaviour here. catch() doesn't exist in normal context
return catch()
end
--this is either a trainer battle or a wild one, where we don't want to capture
--as silv3r stated can "runs()" also be used during trainer battle, it just returns false when done though
return attack() or sendUsablePokemon() or run()
end