Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SpellManager.CastSpellByNameOn - Async ? Await ?

Featured Replies

Hello Wrobot Community,

I am currently working on a script for WoW 3.3.5a private server, and I need some assistance in making my function asynchronous to ensure it is executed properly. Here's the code snippet I am using:

 
public static bool WildGrowthHeal(WowPlayerExtended player)
{
    if (CanCast(Main.WildGrowth, player.OriginalPlayer))
    {
        SpellManager.CastSpellByNameOn("Wild Growth", player.OriginalPlayer.Name);
        Logging.WriteDebug($"{player.OriginalPlayer.Name}Wild Growth");
        return true;
    }
    return false;
}

&&

internal static bool CanCast(Spell spell, WoWUnit target, bool canMove = true, bool tank = false)
		{
			// Check if the caster is not stunned, not dead, not casting, the target is alive, the spell is usable,
			// the distance to the target is good, and there is no line of sight issue
			if (!ObjectManager.Me.IsStunned && !ObjectManager.Me.IsDead && !ObjectManager.Me.IsCast && !target.IsDead && spell.IsSpellUsable && spell.IsDistanceGood && !TraceLine.TraceLineGo(target.Position))
			{
				if (target.MaxHealth - target.Health != 0 || tank)
				{
					// Log the spell cast and the target's health percentage
					Logging.WriteDebug($"Cast: {spell.NameInGame} on {target.Name} because life had less than {target.MaxHealth - target.Health} PV and he is a {target.WowClass}");

					// Return true, indicating the spell can be cast
					return true;
				}
			}

			// Return false, indicating the spell cannot be cast
			return false;
		}

 

This function checks if "Wild Growth" can be cast on a player and casts the spell if possible. However, I want to make sure that the function waits for the spell to be cast before proceeding further. I am aware that using Thread.Sleep is not the best solution, as it can block the thread and cause other issues.

Instead, I would like to make this function asynchronous using async and await, but I'm not sure how to do this with the current SpellManager.CastSpellByNameOn method, which is not asynchronous.

Could anyone please provide guidance on how to make this function asynchronous or suggest an alternative way to ensure that the spell is cast before the function proceeds further? Any help would be greatly appreciated

 

Thank you in advance for your assistance!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.