Hello There, Guest! Login Register


[feature] PROShine | battle trainers on sight | pull requested
#1
Hi everyone,

[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 Smile
  • 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.
[state | pull requested]
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 Wink

[downloads]
[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 Wink
[Image: 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 Smile
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
 
Reply
#2
You sir earn a +1

Works amazing.
can you implement to blissey's?

and push request to official


p.s.
maybe add option ?

put this into main .lua on the top
------------
setOption(1, true)
setOptionName(1, "Fight")
setOptionDescription(1, "Fight or Run.")

-------
put this line into path or into a function that gets called on more then once(start)
    if getOption(1) then enableTrainerBattles() else disableTrainerBattles() end
 
Reply
#3
Great work! I haven't really looked at the code yet, but it seems to be working.

I don't know if caching the guarded areas in memory is really required (any computer should be able to check all NPCs for every movement), but this is an interesting way to optimize.

By the way, all the scripts included with the bot can already handle trainer battles. It is not forbidden to call run() during a trainer fight, the function will just return false.
 
Reply
#4
(2017-08-14, 12:38:54)Silv3r By the way, all the scripts included with the bot can already handle trainer battles. It is not forbidden to call run() during a trainer fight, the function will just return false.

Well this certainly simplifies things! I let the beware statement stand for now though - I had some occasions where the universal scripts just switched pokemon and never attacked, since their if statement tested for isWild() which was never true...
 
Reply
#5
[1:32:05 AM] A Wild Bellsprout Attacks!
[1:32:11 AM] Error during the script execution: System.Exception: chunk_1Sad29,8-86): attempt to call a nil value ---> MoonSharp.Interpreter.ScriptRuntimeException: attempt to call a nil value
at PROBot.Utils.TaskUtils.CallActionWithTimeout(Action action, Action error, Int32 timeout) in D:\workspace\ProCoding\Client\PROShine-master\PROBot\Utils\TaskUtils.cs:line 37
at PROBot.Scripting.LuaScript.CallDynValueFunction(DynValue function, String functionName, Object[] args) in D:\workspace\ProCoding\Client\PROShine-master\PROBot\Scripting\LuaScript.cs:line 392
at PROBot.Scripting.LuaScript.CallFunction(String functionName, Boolean isPathAction, Object[] args) in D:\workspace\ProCoding\Client\PROShine-master\PROBot\Scripting\LuaScript.cs:line 386
at PROBot.Scripting.LuaScript.ExecuteNextAction() in D:\workspace\ProCoding\Client\PROShine-master\PROBot\Scripting\LuaScript.cs:line 100
--- End of inner exception stack trace ---
at PROBot.Scripting.LuaScript.ExecuteNextAction() in D:\workspace\ProCoding\Client\PROShine-master\PROBot\Scripting\LuaScript.cs:line 104
at PROBot.BotClient.ExecuteNextAction() in D:\workspace\ProCoding\Client\PROShine-master\PROBot\BotClient.cs:line 355
[1:32:11 AM] Bot stopped

anything i miss?
 
Reply
#6
(2017-08-14, 17:37:02)selamatkan [1:32:05 AM] A Wild Bellsprout Attacks!
[1:32:11 AM] Error during the script execution: System.Exception: chunk_1: (29,8-86): attempt to call a nil value
anything i miss?

What I'm seeing is that the script calls something that doesn't exist. Either method or variable, during onBattleAction(). Therefore I assume it not being an error from the code I wrote (is never called during battle). But I don't want to reject it just yet.
Check your scripts again. Did they properly run before? Try using the nomal client in the same situation again, does the error still get produced? If so, it's a script error, if not try contacting me again on discord or via pm and we investigate it together. (If it rly is linked to my code I add an entry here later, but since I don't believe so I don't want to spam the thread.) Smile
---------
Update|solved: Selamatkan copied my exemplarary onBattleAction() which used placeholders for an individual implementation. I changed the example a little and added comments to point those out.
 
Reply
#7
(2017-08-14, 17:37:02)selamatkan [1:32:05 AM] A Wild Bellsprout Attacks!
[1:32:11 AM] Error during the script execution: System.Exception: chunk_1Sad29,8-86): attempt to call a nil value ---> MoonSharp.Interpreter.ScriptRuntimeException: attempt to call a nil value
This could be the fact of the pokemon that attacked it. it breaks run function i can tell that by the codes and the way i fixed em

[1:32:05 AM] A Wild Bellsprout Attacks!

if its not the pokemon it could be something dedicated within "run" pre set that needs to be changed?
 
Reply
#8
it crashed when the bot enter route 14 , i think dynamic NPC in this route is the reason make the bot crashed
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)