var castInterval = new Array()
var cooldownInterval = new Array()
var casting_prog = false ;
var time = new Array() ;
function startCast(time_cast,cooldown,spell_id)
{
time[spell_id] = time_cast
if (casting_prog == false)
{
casting_prog = true ;
clearInterval(castInterval[spell_id])
clearInterval(cooldownInterval[spell_id])
castInterval[spell_id] = setInterval('casting()',time[spell_id])
$("castbar").style.display = "" ;
$("cast_border").style.display = "" ;
$("cast"+spell_id).disabled = true ;
$("width").value = 0 ;
$("cast"+spell_id).value = cooldown
cooldownInterval[spell_id] = setInterval("startCooldown("+spell_id+")",1000)
}
else
{
$("logger").innerHTML = "Allready casting a spell!!" ;
}
}
function startCooldown(spell_id)
{
time[spell_id] = parseInt($("cast"+spell_id).value)
if (time[spell_id] > 1)
{
time[spell_id] = time[spell_id] - 1
$("cast"+spell_id).value = time[spell_id]
}
else
{
stopCooldown(spell_id)
}
}
function stopCooldown(spell_id)
{
$("cast"+spell_id).disabled = false ;
$("cast"+spell_id).value = spell_id ;
clearInterval(castInterval[spell_id])
clearInterval(cooldownInterval[spell_id])
time[spell_id] = false;
}
function stopCast()
{
$("castbar").style.display = "none" ;
$("cast_border").style.display = "none" ;
casting_prog = false
}
function casting()
{
var width = $("width").value ;
if (width < 100)
{
var new_width = parseInt(width)+1
$("castbar").style.width = new_width
$("width").value = new_width
}
else
{
stopCast();
}
}
Beste Mensen ik heb 1 probleem met bovenstaande code. Ik zal het probleem uitleggen maar eerst even wat de code hoort te doen :
startCast :
Dit is de cast begin functie. Hij set de interval variabele (afhankelijk van de casttime
casting :
Deze kleine functie loopt zolang de spell bezig is met casten. Het enige van belang dat hij eigenlijk doet is de castbar gelijkmatig laten vollopen
stopCast :
Deze functie word aangeroepen als de spell klaar is en alle variabelen gereset moeten worden
startCooldown :
Word aangeroepen door startCast en is verantwoordelijk voor de cooldown van de spell en er ook verantwoordlijk voor dat een spell niet eerder gebruikt kan worden dan dat de cooldown verlopen is.
stopCooldown :
Word aangeroepen als de cooldown verlopen is en alle gerelateerde variabelen gereset moeten worden.
belangrijke variabelen :
spell_id : id van de spell die op dat moment gecast word.
time_cast : de tijd in ms die de spell nodig heeft om te casten
cooldown : De cooldown van de spell in seconden.
Probleem is vast heel simpel maar ik zie het even niet. Het probleem is dat een spell steeds sneller gecast word.