HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help with debugging a spell template I made

04-02-2006, 09:32 AM#1
hourglasseye
Hi,

I've been having fun using Vexorian's spell templates, tweaking them here and there and have decided to make a template of my own. I call it the Spray Projectile template. It creates collision missles that... well... i don't know how to describe it... so i'm posting a screenshot at the bottom of this post. I have two spells that use the template I made and they work the way I want them to work. However, the third spell I made won't work. I've tried so many things already just to find out why it doesn't work the way it should but I couldn't find it. I've been working on this template for some two days now... Is anyone interested in helping me?

Umm... if anyone is interested, here is the code:
*Note* The first two spells that use the template, Ice Strafe and Darkness Arrows are the ones that work... The third spell is the problem... I've tried making its fields identical to darkness arrows, but it still won't do any damage and its missiles won't get destroyed either.

Collapse JASS:
//***************************************************************************************************
//*
//*  Spray Projectile Template by hourglasseye
//*  Alternative Spell Templates System and Caster System functions by Vexorian
//*
//*  Requires:
//*      - A triggerer ability (has to be instant object-target order)
//*      - An optional spell to be cast upon collision
//*      - Caster System v13.3 by Vexorian
//*      - The Alternative Spell Templates System by Vexorian
//*      - This Trigger
//*  Art:
//*      - The rawcode spell's area effect art at index 0 will be used as the projectile's models
//*
//***************************************************************************************************

//===================================================================================================
// Spray Template Setup
// 
function SprayTemplateSetup takes nothing returns nothing
 local integer D //An integer variable we use later to save the Damage Options so we give them to the templates
 local integer s //An integer variable we use later to save the rawcodes of spells to save some time

 //===================================================================================================
 // Template Info:
 //
 // Template Name Id = "BeamSpellTemplate" (active)
 //
 // real    "speed"      Projectile speed
 // real    "scale"      Projectile scale
 // integer "missiles"   The number of missles fired
 // real    "height"     Projectile flyheight
 // real    "area"       This is the area/distance of effect of the projectiles
 // real    "anglevar"   The distance between the angle of the projectile's paths
 // real    "collision"  The collision size of the projectiles
 //
 // integer "limit"      Determines how many times the missiles can collide with an object before exploding
 //                      Unlimited when set to 0
 // integer "spell"      The spell to cast if an unit is hit by the beam
 // string  "order"      The orderid of that spell
 // integer "type"       If 0, then no spell is casted upon collision. 1 if object-targetable, 2 if object-targetable AoE,
 //                       3 if point-targetable, 4 if not-targetable, 5 for custom script
 // real    "aoe"        If type is 2, area of effect must be specified
 //
 // real    "damage"     The initial damage
 //
 // integer "options"    (Caster System Damage Options in saveable form)
 //

 //===================================================================================================
 // Spray Template Defaults:
 //
    call SetTemplateDefaultInt(   "SpraySpellTemplate","options"    ,CreateDamageOptions(0))//Default target options are null
    call SetTemplateDefaultInt(   "SpraySpellTemplate","color"      ,0xFFFFFFFF)            //Default color is 255,255,255,255
    call SetTemplateDefaultReal(  "SpraySpellTemplate","speed"      ,800.00)                //Make default projectile speed 800
    call SetTemplateDefaultReal(  "SpraySpellTemplate","scale"      ,1.00)                  //Make default scale 1
    call SetTemplateDefaultReal(  "SpraySpellTemplate","collision"  ,30.00)                 //Make default collision 30
    call SetTemplateDefaultReal(  "SpraySpellTemplate","height"     ,15.00)                 //Make default height 15
    call SetTemplateDefaultReal(  "SpraySpellTemplate","area"       ,900.00)                //Default distance is 900
    call SetTemplateDefaultReal(  "SpraySpellTemplate","aoe"        ,300.00)                //Default aoe for type 2 spells is 300
    call SetTemplateDefaultInt(   "SpraySpellTemplate","type"       ,0)                     //Default type is 0, no spell casted
    call SetTemplateDefaultInt(   "SpraySpellTemplate","limit"      ,1)                     //Default limit is 1
    call SetTemplateDefaultString("SpraySpellTemplate","spc"        ,"origin")              //Default Attachment point is origin
    
 //===================================================================================================
 // Ice Strafe ('A02F')
 //
 set s=SetSpellTemplate('A02F',"SpraySpellTemplate")            //The ability Rawcode
 set D=0                                                        //Ice Strafe options
 set D=DamageTypes(ATTACK_TYPE_MAGIC,DAMAGE_TYPE_COLD)          //Magical damage, Cold Type
 set D=D+DamageOnlyEnemies()                                    //Don't harm allies
 set D=CreateDamageOptions(D)                                   //Save the damage options
    
    call SetAbilityDataReal(s,  "damage"  ,0,100.00)        //100 damage
    call SetAbilityDataReal(s,  "anglevar",0,13.00)         //Projectile paths will be 13 points away from each other
    call SetAbilityDataInt(s,   "missiles",0,5)             //Project 5 missiles
    call SetAbilityDataInt(s,   "type"    ,0,1)             //Cast an object-targetable spell upon impact
    call SetAbilityDataInt(s,   "spell"   ,0,'A02H')        //Cast a spell with the id A02H on the object that collided w/ missile
    call SetAbilityDataString(s,"order"   ,0,"thunderbolt") //Cast an object-targetable spell upon impact
    call SetAbilityDataInt(s,   "options" ,0,D)             //Use the damage options saved in D
    
 //===================================================================================================
 // Darkness Arrows ('A02E')
 //
 set s=SetSpellTemplate('A02E',"SpraySpellTemplate")            //The ability Rawcode
 set D=0                                                        //Darkness Arrows options
 set D=DamageTypes(ATTACK_TYPE_MAGIC,DAMAGE_TYPE_SHADOW_STRIKE) //Magical damage, Shadow Strike (?) Type
 set D=D+DamageOnlyEnemies()                                    //Don't harm allies
 set D=CreateDamageOptions(D)                                   //Save the damage options
    
    call SetAbilityDataReal(s,  "damage"  ,0,200.00)        //200 damage
    call SetAbilityDataReal(s,  "anglevar",0,13.00)         //Projectile paths will be 13 points away from each other
    call SetAbilityDataInt(s,   "missiles",0,5)             //Project 5 missiles
    call SetAbilityDataInt(s,   "limit"   ,0,0)             //Pierces are unlimited
    call SetAbilityDataInt(s,   "options" ,0,D)             //Use the damage options saved in D

 //===================================================================================================
 // Multi Strafe ('A002')
 //
 set s=SetSpellTemplate('A002',"SpraySpellTemplate")            //The ability Rawcode
 set D=0                                                        //Multi Strafe options
 set D=DamageTypes(ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL)        //Magical damage, Normal Type
 set D=D+DamageOnlyEnemies()                                    //Don't harm allies
 set D=CreateDamageOptions(D)                                   //Save the damage options
    
    call SetAbilityDataReal(s,  "damage"  ,1,30.00)         //Level 1: 30 damage
    call SetAbilityDataReal(s,  "damage"  ,2,60.00)         //Level 2: 60 damage
    call SetAbilityDataReal(s,  "damage"  ,3,90.00)         //Level 3: 90 damage
    call SetAbilityDataReal(s,  "anglevar",0,15.00)         //Level 1: Projectile paths will be 15 points away from each other
    call SetAbilityDataReal(s,  "anglevar",0,13.00)         //Level 2: Projectile paths will be 15 points away from each other
    call SetAbilityDataReal(s,  "anglevar",0,11.00)         //Level 3: Projectile paths will be 15 points away from each other
    call SetAbilityDataInt(s,   "missiles",0,3)             //Level 1: Project 3 missiles
    call SetAbilityDataInt(s,   "missiles",0,5)             //Level 2: Project 5 missiles
    call SetAbilityDataInt(s,   "missiles",0,7)             //Level 3: Project 7 missiles
    call SetAbilityDataInt(s,   "options" ,0,D)             //Use the damage options saved in D

 //===================================================================================================
 // Ability Preloading
 //
 // Next is unrelated to the templates system, just avoids the first time cast lag, here you 
 // should preload any ability used as auxiliar ability for the template, just to avoid first
 // time cast lag.
 //
    call PreloadAbility('A02F') //Ice Strafe
    call PreloadAbility('A02E') //Darkness Arrows
    call PreloadAbility('A002') //Multistrafe

endfunction

//==================================================================================================

function Spray_CollideActions takes nothing returns nothing
    local unit missile
    local unit target
    local integer spelltype
    local integer spellid
    local integer limit
    local integer level
    local string order
    local real x
    local real y
    local real radius
    local player owner
    set owner = GetOwningPlayer(GetAttachedUnit(GetTriggerCollisionMissile(),"caster"))
    if( IsUnitEnemy( GetTriggerUnit(), owner ) == true ) then
        set missile = GetTriggerCollisionMissile()
        set target = GetTriggerUnit()
        set spelltype = GetAttachedInt(missile,"type")
        set level = GetAttachedInt(missile,"level")
        set limit = GetAttachedInt(missile,"limit")
        if(spelltype != 0) then
            set spellid = GetAttachedInt(missile,"spell")
            set order = GetAttachedString(missile,"order")
            if(spelltype == 1) then
                call CasterCastAbilityLevel(owner,spellid,level,order,target,true)
            elseif(spelltype == 2) then
                set x = GetUnitX(target)
                set y = GetUnitY(target)
                set radius = GetAttachedReal(missile,"aoe") * 0.5
                call CasterCastAbilityLevelAOE(owner,spellid,level,order,x,y,radius,false,true)
            elseif(spelltype == 3) then
                set x = GetUnitX(target)
                set y = GetUnitY(target)
               call CasterCastAbilityLevelPoint(owner,spellid,level,order,x,y,true)
            elseif(spelltype == 4) then
                call CasterCastAbilityLevel(owner,spellid,level,order,null,true)
            endif
        endif
        call DamageUnitByOptions( GetAttachedUnit(missile,"caster"), target, GetAttachedReal(missile,"dmg"), GetAttachedInt(missile,"dmgopt") )
        if(limit > 0) then
            if(limit == 1) then
                call CleanAttachedVars(missile)
                call CollisionMissile_Destroy(missile)
            else
                set limit = limit - 1
                call AttachInt(missile,"limit",limit)
            endif
        endif
    endif
endfunction

function SpraySpellTemplate takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local location target = GetSpellTargetLoc()
    local integer abilid = GetSpellAbilityId()
    local integer abillvl = GetUnitAbilityLevel(caster,abilid)
    local real facing = GetUnitFacing(caster)
    local real angledist = GetAbilityDataReal(abilid,abillvl,"anglevar")
    local integer missiles = GetAbilityDataInt(abilid,abillvl,"missiles")
    local real spawnang = facing + angledist * missiles * 0.5
    local real speed = GetAbilityDataReal(abilid,abillvl,"speed")
    local real maxdist = GetAbilityDataReal(abilid,abillvl,"area")
    local real collision = GetAbilityDataReal(abilid,abillvl,"collision")
    local real dmg = GetAbilityDataReal(abilid,abillvl,"damage")
    local real height = GetAbilityDataReal(abilid,abillvl,"height")
    local real aoe = GetAbilityDataReal(abilid,abillvl,"aoe")
    local location casterloc = GetUnitLoc(caster)
    local location spawnpt
    local string model = GetAbilityEffectById(abilid,EFFECT_TYPE_AREA_EFFECT,0)
    local integer launched = 0
    local integer dmgopt = GetAbilityDataInt(abilid,abillvl,"options")
    local unit lastcreated
    local integer spelltype = GetAbilityDataInt(abilid,abillvl,"type")
    local integer spell
    local string spellorder
    local integer limit = GetAbilityDataInt(abilid,abillvl,"limit")
    if(spelltype != 0) then
        set spell = GetAbilityDataInt(abilid,abillvl,"spell")
        set spellorder = GetAbilityDataString(abilid,abillvl,"order")
    endif
    loop
        exitwhen(missiles == launched)
        set spawnpt = PolarProjectionBJ(casterloc,20,spawnang)
        set launched = launched + 1
        set lastcreated = CollisionMissile_CreateLoc(model,spawnpt,spawnang,speed,0,maxdist,30.00,true,collision,function Spray_CollideActions)
        call AttachReal(lastcreated,"dmg",dmg)
        call AttachInt(lastcreated,"dmgopt",dmgopt)
        call AttachObject(lastcreated,"caster",caster)
        if(spelltype != 0) then
            call AttachInt(lastcreated,"type",spelltype)
            call AttachInt(lastcreated,"spell",spell)
            call AttachInt(lastcreated,"level",abillvl)
            call AttachInt(lastcreated,"limit",limit)
            call AttachString(lastcreated,"order",spellorder)
            if(spelltype == 2) then
                call AttachReal(lastcreated,"aoe",aoe)
            endif
        endif
        set spawnang = spawnang - angledist
        call RemoveLocation(spawnpt)
    endloop
    call RemoveLocation(target)
    call RemoveLocation(casterloc)
endfunction

function InitTrig_Spray_Template takes nothing returns nothing
    call ExecuteFunc("SprayTemplateSetup")
endfunction

Here is that screenshot:

04-02-2006, 11:20 AM#2
Vexorian
would be much easier if you included a map ...
04-02-2006, 11:37 AM#3
hourglasseye
Oh. Ok. I'll pm you.
EDIT: Btw, how do i send stuff over the forum?