[Proof of concept, C#] Using async for scripting in main thread menu

Shout-Out

User Tag List

Results 1 to 5 of 5
  1. #1
    Kryso's Avatar Active Member
    Reputation
    40
    Join Date
    Jul 2009
    Posts
    97
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Proof of concept, C#] Using async for scripting in main thread

    So I've managed to bend async to execute code between yields in single thread and thought I'd share Similar thing can be achieved with `yield return`, but this looks quite better.

    Using this concept scripts can be written like this (fake code, just an example):


    Code:
    private async Task KillMob(Mob mob)
    {
        mob.Target();
    
        while (mob.Alive)
        {
            if (mob.Distance > World.Player.MeleeDistance)
                await World.Player.MoveTo(mob);
    
            if (!World.Player.IsAttacking(mob))
                World.Player.Attack(mob);
    
            Task.Yield();
        }
    }
    
    [Executable]
    public async Task KillAllTheThings()
    {
        Mob mob;
        while ((mob = World.Mobs.Where(m => m.Attackable).OrderBy(m => m.Distance).FirstOrDefault()) != null)
        {
            await KillMob(mob);
        }
    
        Script.Print("Everything is dead");
    }
    while running only within main thread. Njoy

    Some testing code: https://gist.github.com/anonymous/0a250e25486d1cb16b6b
    Tea and cake or death?!

    [Proof of concept, C#] Using async for scripting in main thread
  2. #2
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is really cool. I'd love to do something like that, but how would you handle a mob that is attacking you while approaching another mob? You don't really have a chance to account for all prioritized actions each time step if you are in the middle of a long running task. So while it makes your code dead simple and predominantly elegant, you'd be better off if you go down the behavior tree every tick.

    Don't get me wrong: I really admire what you did

  3. #3
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wooot, Kryso. You're still in the game? I've been wondering ever since PyMode lol. Very neat stuff, been looking for a way like this forever.

  4. #4
    Kryso's Avatar Active Member
    Reputation
    40
    Join Date
    Jul 2009
    Posts
    97
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bananebrot: I know - my tool originally worked somewhat like that, but I like to try different things I think you could even use this within your BT to simlify some logic.. or maybe not

    miceiken: Nah, I stopped playing wow when cata came. I wrote this for eve online, but the concept should be useful in any game I'm glad someone remembers PyMode tho
    Tea and cake or death?!

  5. #5
    redcatH's Avatar Member
    Reputation
    2
    Join Date
    Sep 2012
    Posts
    29
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First Thank you @Kryso Contribution
    Last edited by redcatH; 10-01-2013 at 10:24 AM.

Similar Threads

  1. Problem for WD Farming (Using the given script for WD) In Royal Crypts
    By 102030448 in forum Diablo 3 Bots Questions & Requests
    Replies: 0
    Last Post: 06-09-2012, 04:12 PM
  2. [Misc] Fun and useful display ids for scripting or general fun
    By thebigman in forum World of Warcraft Emulator Servers
    Replies: 0
    Last Post: 04-30-2012, 08:09 PM
  3. Replies: 0
    Last Post: 10-20-2011, 09:20 PM
  4. New use for script bug (YOU NEED TWO ACCOUNTS)
    By citykid199 in forum World of Warcraft Exploits
    Replies: 25
    Last Post: 10-03-2007, 05:46 PM
  5. Replies: 11
    Last Post: 10-18-2006, 12:23 AM
All times are GMT -5. The time now is 08:19 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search