Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

Spell Cast Status (CanUseSpell) - How it works


  • Please log in to reply
2 replies to this topic

#1
jouzuna

jouzuna

    Advanced Member

  • Contributor
  • 73 posts

The spellcaststatus (the value returned by CanUseSpell(unit, slot)) has changed a some patches ago and no longer returns a constant

 

the function now returns a dword where each bit represents a certain state. This means that instead only being able to check if the spell is ready or on cooldown etc, we can now check multiple states (if the spell is on cooldown and the cost is too high, you can know)

 

I am not so good at explaining things so here is image to help:

 

OU17Lsh.png

 

so this is an example of the value returned represented in a base2 (binary) format

the example if a spell which is on cooldown. if you call CanUseSpell(myHero, _Q) and the spell is on cooldown it will return 32

if the spell if on cooldown but you are not enough mana to cast the function will return 96 which is 0110 0000. as you can see both the cooldown and outofmana set are both set

 

below is a sample code (add this to your common folder http://lua.tips/down...bit32/bit32.lua)

local bit32 = require("Common.bit32")

SpellCastStatus = function(unit, slot)
  return setmetatable({ }, { __index = function(t, k)
    local bitIndex = ({ ready = -1, notexist = 2, disabled = 3, notlearned = 4, cooldown = 5, outofmana = 6 })

    if bitIndex[k] then
      local status = CanUseSpell(unit, slot)

      if bitIndex[k] > -1 then
        local a_mask = bit32.band(status, bit32.lshift(1, bitIndex[k]))
        return bit32.rshift(a_mask, bitIndex[k]) == 1
      else
        return status == 0x00000000
      end
    end
  end })
end

-- Example:
local Q = SpellCastStatus(GetMyHero(), _Q)

if Q.ready then
  PrintChat("ready")
else
  if Q.notexist then
    -- This flag is only used for items which have not been purchased
    PrintChat("notexist")
  end

  if Q.notlearned then
    -- This flag is used for spells which are level 0
    PrintChat("notlearned")
  end

  if Q.disabled then
    -- This flag is used when you cannot cast a spell like when you are suppressed
    PrintChat("disabled")
  end

  if Q.cooldown then
    PrintChat("cooldown")
  end

  if Q.outofmana then
    PrintChat("outofmana")
  end
end

  • 0

#2
Platypus

Platypus

    Bitcoin and Paysafecard payments are now available

  • Banned
  • PipPipPip
  • 1,289 posts

so what does this all mean?

 

not much really

 

>kann weg


  • 0

#3
Lelouch

Lelouch

    ?

  • Members
  • 464 posts

 

so what does this all mean?

 

not much really

 

>kann weg

 

:fappa:


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users