FANDOM


A fireball spell, released for free by Taz.

          ; tazgame
            ; Date/Time: 11:18:10 PM on 2/18/2009
            ; By Tazco on NADDAZ
          ; Updated sunday april, 19, 2009
          ; Note: Using Actorglobal 2 for magic skill level
          ;Updated sept 28 2010 added wisdom attribute and changed damage/spellcost.

Function Main()
	
	Player = Actor()
	Target = ContextActor()
	Result% = ActorDistance(Player, Target)
    Plvl% = Actorlevel(Player)
	Tlvl% = Actorlevel(Target)
    PHealth% = MaxAttribute(Player, "Health") 
    TargetMagiclvl% = Attribute(Target, "Magic")
	MagicLvl% = Attribute(Player, "Magic")
	ManaLevel% = Attribute(Player, "Mana")
    StaffDmg% = ItemAttribute(ActorWeapon(Player), "Magic") ;Staff damage
    PMana% = MAxAttribute(Player, "Mana") ;using in damage check
  
  
     FireBallDmg% = MagicLvl * 3 + PLvl + AbilityLevel(Player, "FireBall") + StaffDmg + Rand(30, 35)
    Firedmg% = FireBallDmg + Rnd(15, 20) ;total spell damage to be done
	TotFiredmg% = Firedmg 
    
     
  If (TotFiredmg <= 0) ; if damage is not enough since target has good magic resistance then give min damage.
    TotFiredmg% = Rand(10, 25)
 Endif
    
 	TName$ = Name(Target)
 	PName$ = Name(Player)
  
 
   ;Check to see if target is in range	
If (Result > 80) ;check distance of target.
		Output(Player, "You are to far away!", 255, 0, 0)
		Return
Endif

If (Target = 0) ; Check target is valid
  		Output(Player, "select a target for your spell!", 255, 0, 0)
		Return
Endif

     SpellCost% = 25 + Rand(15, 20)

;Mana check
 If (ManaLevel < SpellCost)
 Output(Player, "insufficient mana - spell failed!")  ;tell player they don`t have enough mana
 Return
 
 EndIf
 
 Thealth% = Attribute(Target, "Health") - TotFiredmg ; take damage from target health
 
 PBar% = CreateProgressBar(Player, 5, 85, 155, 0.40, 0.82, 0.2, 0.04, 5, 5, "Casting Fire Ball") ; casting bar
 Ticks% = 5 ;amount of for ticks also change the max and valve number in the PBar above.
 
 CreateEmitter(Player, "Flame", 8, 1800) ; casting emitter 
 DoEvents(300)
 
 AnimateActor(Player, "Spell cast", .5, 2) ;Particles and casting animation
 
 Repeat
 
 Result% = ActorDistance(Player, Target)
 Ticks% = Ticks - 1				;take 1 tick per half a sec
 
 UpdateProgressBar(Player, PBar, Ticks)   ;update progress bar
 
     If (Result > 80) ;make sure the target is still in range for casting
		Output(Player, "Your target is to far away!")
        DeleteProgressBar(Player, PBar) ;delete progressbar
        DoEvents(500)
		Return	
    Endif
 
 ;updated progress bar has to be before actor hp if dead check. Progress bar will update then be deleted if player is dead.

Targethealth% = Attribute(Target, "Health")

If (Targethealth <= TotFiredmg) ;target is dead stop pbar.
	Output(Player, "You have killed " + TName, 255, 0, 0)
    Output(Target, "You have been killed by " + PName + "!", 255, 0, 0)
    Ticks% = 0     
    DeleteProgressBar(Player, PBar) ;delete progressbar
    KillActor(Target, Player)
   Return
 Endif
 
 DoEvents(500)
 
 Until(Ticks = 0) 				;end repeat if ticks = 0
 
    ; PlaySound(Player, 1, 0) ;play fire sound
    SetAttribute(Player, "Mana", ManaLevel - SpellCost)
    AnimateActor(Player, "Spell cast", 2) ;Particles and casting animation
	DeleteProgressBar(Player, PBar) ;delete progressbar
    CreateEmitter(Player, "Flame", 8, 400)
    ;FireProjectile(Player, Target, "FireBall")
       DoEvents(100)
       CreateEmitter(Target, "Fire2", 470, 300)
       SetActorTarget(Target, Player)
       SetActorAIState(Target, 3)
       CreateFloatingNumber(Target, Firedmg, 255, 0, 0) ;red normal attack 

       ;Output(Player, "Your total damage for this spell is " + Totfiredmg, 25, 54, 53)   ;Tell player the amount of damage they did with there spell
     
     DoEvents(100)
  ;Kill target if health is 0 or lower. 
If (Thealth <= 0)
  	Output(Player, "You have killed " + TName, 255, 0, 0)
    Output(Target, "You have been killed by " + PName + "!", 255, 0, 0)
	KillActor(Target, Player)
    Doevents(500)
    Return
 Endif
 
 SetAttribute(Target, "Health", Thealth)          ;Do spell damage
 
 End Function