HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help: Multi-Instanceable Countdown Doom Spell

05-15-2006, 11:41 AM#1
buttoxide
First of all I am using the GUI, I still haven't grasped JASS yet, so please forgive my noobishness. Tried searching these forums too but I can't find any thread on this, although I thought something like this would have been thought of by now.

I'm currently trying to make a spell that gives the victim X seconds left to live before he gets killed. So for example, if X is 10 seconds, on top of him, it will show floating texts 10, 9, 8 ..... all the way to 1 with a 1 seconds interval in-between, then the guy blows up.

I did manage to get it working, but the problem is that I want the spell to be multi-instanceable. My current triggers are:

Event:
Unit starts effect of ability

Action:
local unit VICTIM
Set VICTIM = Target unit of ability being cast
For Integer Y from 1 to X do:
-Display floating text of seconds left
-Wait 1 sec
Unit - Kill VICTIM

From what I've gathered from these forums I can't seem to make the loop multi-instanceable. Is there any way I edit this, preserving the floating text effect and yet make it MUI? Thanks in advance!
05-15-2006, 02:23 PM#2
The)TideHunter(
To make this leak free and multi-instancable, i would use timers, they are much more officent and accurate than TriggerSleepAction or Wait
Give me 5 mins and i will have it ready for you
...(Opens JassCraft)
05-15-2006, 02:29 PM#3
Vuen
You need to write:

local unit udg_VICTIM

The udg_ needs to be there anywhere you use Custom Script. If this line is wrong, it's like not having it at all; the rest of the trigger is using the global variable and not the local one, which is why it's not MUI. This should fix it.
05-15-2006, 03:09 PM#4
The)TideHunter(
Vuen, he has no problems, he just wants to make the spell multi-instancable.
05-15-2006, 03:13 PM#5
Vuen
Exactly. The way he wrote it is multi-instanceable in the first place, except he screwed up the local variable declaration. If he fixes that, the spell will become multi-instanceable.
05-15-2006, 03:24 PM#6
iNfraNe
Also, be sure to get the case of the variable the same as the global, since jass is case sensitive.
05-15-2006, 03:28 PM#7
The)TideHunter(
Damnit! i just wrote a hour of code for 'Nothing' then, il post it anyways, may come in handy for learning etc.

Im not 100% sure if this is leak free or it works lol, but it had no errors and i see why not.

Here it is:

First we need handle variables and a gamecache called "GC" (codename udg_GC)

These are just the 1s you need, put them in your map script section
Collapse JASS:
// Game Cache Return
function GC takes nothing returns gamecache
    if(udg_GC == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

// Handle Variables
function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Unit takes integer I returns unit
    return I
    return null
endfunction

function I2TextTag takes integer I returns texttag
    return I
    return null
endfunction

And heres the actual code, it required no variables:

Collapse JASS:
//**********
// AddUnitDeath_Child(unit whichUnit, integer SecsToLive)
//
function AddUnitDeath_Adult takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit target = I2Unit(GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_Unit"))
    local integer TimeLeft = GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive")
    local texttag currentTag
    if(GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag") == 0) then
        set currentTag = CreateTextTag()
        call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag", H2I(currentTag))
    else
        set currentTag = I2TextTag(GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag"))
    endif
    if(TimeLeft == 0) then
        call KillUnit(target)
        call FlushStoredMission(GC(), I2S(H2I(t)))
        call DestroyTextTag(currentTag)
        call DestroyTimer(t)
        set t = null
        set currentTag = null
    else
        call SetTextTagText(currentTag, I2S(TimeLeft), 50.)
        call SetTextTagPosUnit(currentTag, target, 50.)
        call SetTextTagColor(currentTag, 100, 100, 100, 0) 
        call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive", TimeLeft - 1)
        call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag", H2I(currentTag))
        call TimerStart(t, 1., false, function AddUnitDeath_Adult)
    endif
    set TimeLeft = 0         
endfunction

function AddUnitDeath_Child takes unit whichUnit, integer timeToLive returns nothing
    local timer t = CreateTimer()
    call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_Unit", H2I(whichUnit))
    call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive", timeToLive)
    call TimerStart(t, 1., false, function AddUnitDeath_Adult)
endfunction

To use it, you just need to type:

Collapse JASS:
call AddUnitDeath_Child(MyUnit, TimeLeft)

EDIT: sorry if this is really really confusing, you havent grasped Jass yet, so i shouldent have really gone this far, hopefully it will work though

EDIT2: i just realised the floating text has NO colour whatsoever, il quickly change it

EDIT3: ok the line is added, it will be black text i think, (100, 100, 100, 0)

EDIT4: the floating text isent even being created, il fix it now

EDIT5: ok fixed

EDIT6: sorry for all the edits, but i just tested it and it works great, its just not showing the floating text ATM, im gonna get it working
05-16-2006, 06:02 AM#8
buttoxide
Wow! I didn't expect so much help.

Thanks for all your feedback. I'll try to wade my way through this JASS and learn it.