// Enable spells
SetUsingSpells(true)
// Get the player's spellbook if it's equipped
::GetSpellbook <- function(player) {
for (local child = player.FirstMoveChild(); child != null; child = child.NextMovePeer()) {
if (child.GetClassname() == "tf_weapon_spellbook") return child
}
return null
}
// Set the spellbook's current spell and amount of charges
::SetSpell <- function(spellbook, id, amt) {
NetProps.SetPropInt(spellbook, "m_iSelectedSpellIndex", id)
NetProps.SetPropInt(spellbook, "m_iSpellCharges", amt)
}
// Roll a random spell
::RollSpell <- function(player, spells = [[0,2],[1,2],[2,1],[3,1],[4,2],[5,1]], delay = 1) {
local spellbook = ::GetSpellbook(player)
if (!spellbook) return
local spell = spells[RandomInt(0, spells.len()-1)]
::SetSpell(spellbook, -2, 0)
EntFireByHandle(spellbook, "RunScriptCode", "::SetSpell(self,"+spell[0]+","+spell[1]+")", delay, null, null)
}
// Clear spellbooks on round start (otherwise the rolling animation may get stuck)
for (local spellbook; spellbook = Entities.FindByClassname(spellbook, "tf_weapon_spellbook");) {
::SetSpell(spellbook, -1, 0)
}