Here use this:
code:
speedFile = "15|10|20";
heroSpeeds = speedFile.split("|");
i = 0;
fps = 12;
counter = 2*fps;
attacking = false;
function selectAttack() {
_root["hero"+i].attack = chosenAttack;
if(_root["hero"+i].attack) {
i++;
}
//^ Waits to give every "hero" an attack ;
for(j=0; j<i; j++) {
if(j == i-1) {
if(_root["hero"+j].attack) {
startBattle();
}
}
}
//^ If all heros have an attack, start battle ;
}
function startBattle() {
counter -= 1;
m = heroSpeeds.length-1;
if(counter <= 0) {
heroTurn = heroSpeeds.sortOn();
//^ Originally posted by slight
for(k=0; k<i; k++) {
_root["hero"+k+"speed"] = heroSpeeds[k];
if(_root["hero"+k+"speed"] == heroTurn[m]) {
turnAttack = true;
}
}
if(turnAttack && !attacking) {
heroAttack(_root["hero"+k]);
attacking = true;
m--;
}
counter = 2*fps;
}
//^ This is the meat of the engine. It checks if its
// the "hero"'s turn to attack and then it does so.
// If the hero is "attacking" then it does not continue.
}
function heroAttack(hero) {
if(hero.attack == "spear") {
// Blah Blah make the hero do something to attack ;
}
if(hero.attack == "sword") {
// Blah Blah make the hero do something to attack ;
}
attacking = false;
}
this.onEnterFrame = function() {
selectAttack();
}
and thats basicly it....
EDIT: fixed some bugs and now I'm almost postive it works.




Reply With Quote