HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Jass Script Not Working

07-16-2007, 08:41 AM#1
deadlysheep_1
Hi guys.

I have made a CreateEffectLine function, which is a function which lets you create a certain amounts of a special effect of your choice from location start to location finish. This is the trigger which I am using the function in, but it doesn't work properly. Btw I will quickly explain the 7 parameters. whichModel is the special effects model, location start is where the effects start from, location finish is where the special effects finish, integer amount is the amount of special effects made between the two points, real time is the amount of time that it waits between each of the special effects being made, real duration is the time that the effects last for. These are the two problems:
1) It does not create the line of special effects to point b properly. It starts at location start, but does not go to the location finish. Instead, it starts at location start, and the function always uses a point somewhere near the centre of the map as location finish.

2) It does not remove the special effects, so they stay there for ever.

Collapse JASS:
function IceFieldRawcode takes nothing returns integer
return 'A006'
endfunction

function Trig_Ice_Field_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == IceFieldRawcode() ) ) then
        return false
    endif
    return true
endfunction

function CreateEffectLine takes string whichModel, location start, location finish, integer amount, real time, real duration returns nothing
local string a = whichModel
local location b = start
local location c = finish
local integer d = amount
local real e = time
local real f = DistanceBetweenPoints(b,c)
local effect g
local integer i = 0
local real j = AngleBetweenPoints(b,c)
local effect array k
local real l = duration-(e*d)
set f = f/d
loop
exitwhen i == d
set g = AddSpecialEffectLoc(a,b)
set k[i] = GetLastCreatedEffectBJ()
set b = PolarProjectionBJ(b,f,j)
call TriggerSleepAction(e)
set i = i+1
endloop
call TriggerSleepAction(l)
call RemoveLocation(start)
call RemoveLocation(finish)
call RemoveLocation(b)
call RemoveLocation(c)
set i = 0
loop
exitwhen i == d
call DestroyEffect(k[i])
set i = i+1
endloop
endfunction

function Trig_Ice_Field_Actions takes nothing returns nothing
local unit a = GetTriggerUnit()
local unit b = GetSpellTargetUnit()
local location c = GetUnitLoc(a)
local location d = GetUnitLoc(b)
call CreateEffectLine("units\\critters\\SpiderCrab\\SpiderCrab.mdl", c,d,10,0.1, 5)
endfunction

//===========================================================================
function InitTrig_Ice_Field takes nothing returns nothing
    set gg_trg_Ice_Field = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ice_Field, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Ice_Field, Condition( function Trig_Ice_Field_Conditions ) )
    call TriggerAddAction( gg_trg_Ice_Field, function Trig_Ice_Field_Actions )
endfunction

Thanks in advance.
07-16-2007, 09:30 AM#2
Pyrogasm
I really must ask, why oh why do you take arguments and then create locals that equal the arguments, but instead of having useful names are now reduced to "a, b, c, d, etc." for no apparent reason?

What's the point?
07-16-2007, 09:08 PM#3
Silvenon
If you're gonna use JASS, please learn to use coordinates as quickly as possible. Also, don't use BJs(example: GetLastCreatedEffectBJ() = bj_lastCreatedEffect). Learning how to prevent leaks is also important when making stuff in JASS:

Collapse JASS:
loop
exitwhen i == d
set g = AddSpecialEffectLoc(a,b)
set k[i] = GetLastCreatedEffectBJ()
set b = PolarProjectionBJ(b,f,j)
call TriggerSleepAction(e)
set i = i+1
endloop
call TriggerSleepAction(l)
call RemoveLocation(start)
call RemoveLocation(finish)
call RemoveLocation(b)
call RemoveLocation(c)

Instead of destroying it after the loop, you should destroy it in it:

Collapse JASS:
loop
exitwhen i == d
set g = AddSpecialEffectLoc(a,b)
set k[i] = GetLastCreatedEffectBJ()
set b = PolarProjectionBJ(b,f,j)
call RemoveLocation(b)
call TriggerSleepAction(e)
set i = i+1
endloop
call TriggerSleepAction(l)
call RemoveLocation(start)
call RemoveLocation(finish)
call RemoveLocation(c)

Sorry for these corrections, but I couldn't resist. Now, your problem: I found the reason why the effects aren't destroyed, use AddSpecialEffectLocBJ() instead of AddSpecialEffectLoc(), otherwise GetLastCreatedEffectBJ() would be null (nothing). I don't see the cause of the first problem yet......
07-17-2007, 01:06 AM#4
deadlysheep_1
Thank you both for your responses. Although I haven't changed the script yet, i'm sure that is why the special effects aren't being destroyed.

@pyrogasm thank you for that, I will now change the script accordingly. I'm not sure why, but I had some thought in my head that was telling me that using the things that the function takes is slower than setting a local to them and then using the locals. I will fix that now.

Hmm, does anyone have any idea why it always makes the effects go towards that same point all the time? If you want, I can attach the map and you can see for yourself.
+rep to both of you, and i will also +rep anyone else who can help improve my function or fix the first problem that I wrote in the first post.
07-17-2007, 01:30 AM#5
Pyrogasm
Upload the map.
07-18-2007, 01:12 AM#6
deadlysheep_1
kk. When you test the map, the spell that you cast which creates the special effects is Holy Blast, which the hero with the mountain king model has. Since I changed a couple things that you and Silvenon pointed out, It doesn't even create the effects properly. It makes them all in the same place, in the position of the hero. But at least the effects get destroyed, unlike the old version of it. Btw, the trigger which has the function in it is called Icy Blast.
Attached Files
File type: w3xDeadlySheep_1's Spell Map.w3x (36.6 KB)