Page 2 of 2

Re: JASS and vJASS questions thread

PostPosted: Thu Jul 30, 2009 10:08 am
by Drain_Pipe
is it stable?

[edit]. mkay so the old version, this time, worked when i added it in. So I'm gonna stick with that, I guess, until, 1.23b is accepted.


k so I'm looking at an example of dusks idds and I'm just confused about those 3 private values:

First of all, what are they used for?
Secondly, what does the 0x100000 mean?
Thirdly, what does the H2I function do?

I'm Trying to clean up my damage display system using his damage detection system, but I want to know why he did these things first.

Code: Select all
scope CriticalStrike initializer Init
    private constant integer MAX_HANDLE_NO = 8190
    private constant integer MIN_HANDLE_ID = 0x100000
    private boolean array Flag[MAX_HANDLE_NO]

private function H2I takes handle h returns integer
    return h
    return 0

private function Conditions takes nothing returns boolean
    return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and Flag[H2I(GetTriggerDamageSource())-MIN_HANDLE_ID] and GetUnitAbilityLevel(GetTriggerDamageSource(), 'AOcr') > 0 and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE)

private function Actions takes nothing returns nothing
    local unit u = GetTriggerDamageSource()
    local unit t = GetTriggerDamageTarget()
    local integer lvl = GetUnitAbilityLevel(u, 'AOcr')
    local integer pr = GetTriggerPriority(GetTriggeringTrigger())
    local texttag te = CreateTextTag()
    local real d = GetTriggerDamage()
    //Deals +100%/200%/300%/etc damage
    debug call BJDebugMsg("Critical Strike has a |cff00ffff"+I2S(pr)+"|r priority which should fire a |cff00ffff5|r-PR trigger!")
    call UnitDamageTargetEx(u, t, d*(lvl+1), ATTACK_TYPE_HERO, DAMAGE_TYPE_EXTRA, true)
    call SetTextTagText(te, I2S(R2I(d*(lvl)))+"!", 0.024)
    call SetTextTagPos(te, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(te, 255, 0, 0, 255)
    call SetTextTagVelocity(te, 0, 0.04)
    call SetTextTagVisibility(te, true)
    call SetTextTagFadepoint(te, 2)
    call SetTextTagLifespan(te, 5)
    call SetTextTagPermanent(te, false)
    set Flag[H2I(u)-MIN_HANDLE_ID] = false
    set te = null
    set u = null
    set t = null

private function Atk_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), 'AOcr') > 0 and not IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE)

private function Atk_Actions takes nothing returns nothing
    local unit u = GetAttacker()
    if GetRandomInt(1, 100) <= 30 then
        call SetUnitAnimation(u, "attack slam")
        call QueueUnitAnimation(u, "stand ready")
        set Flag[H2I(u)-MIN_HANDLE_ID] = true
        set Flag[H2I(u)-MIN_HANDLE_ID] = false
    set u = null

private function Init takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, function Actions)
    call TriggerAddCondition(trg, Condition(function Conditions))
    call TriggerRegisterDamageEvent(trg, 1)
    set trg = CreateTrigger()
    call TriggerAddAction(trg, function Atk_Actions)
    call TriggerAddCondition(trg, Condition(function Atk_Conditions))
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_ATTACKED)
    set trg = null

Re: JASS and vJASS questions thread

PostPosted: Fri Jul 31, 2009 12:27 am
by Fledermaus
MAX_HANDLE_NO is used to define the array's size (in this case, no bigger than a normal array)
MIN_HANDLE_ID is, as the name would suggest, the minimum handle id. It is used to index the units for the array (will explain later).
Flag is an array that stores if a unit has landed a critical attack (true for critting, false for not).

0x100000 is the first handle index, it (the constant MIN_HANDLE_ID) is used so that you can store data corresponding to a handle (a unit in this case) in an array without going over the 8192(?) limit.

H2I takes a handle and "converts" it to an integer, essentially getting its unique index. It will also be in the 0x###### form so subtracting MIN_HANDLE_ID from it should return a number less than 8192 so that it can fit into an array.

I think that all makes sense? I'm kinda bad at explaining these things.

All the "H2I(GetTriggerDamageSource())-MIN_HANDLE_ID" stuff would be replaced by GetUnitId if you use a Unit Indexing System.

Re: JASS and vJASS questions thread

PostPosted: Fri Jul 31, 2009 1:55 pm
by Drain_Pipe
Ah I see. It's still a little fuzzy but I think I get the jist of things. And I will be creating my own unit indexing eventually, so hopefully I can set that up and not require the use of that.

Re: JASS and vJASS questions thread

PostPosted: Fri Jul 31, 2009 5:48 pm
by Drain_Pipe
Mk after many hours of tweaking, since I don't quite know what the fuck i'm doing here, I've managed to convert my damage display system over into JASS and sync it up with dusk's IDDS.

I think it's kind of neat and fairly moddable. Anyways, If anyone can look at the code, I'll tell you right now it's hella messy and can use a lot of fixing up. I'm also pretty sure it leaks somewhere tho I've tried to patch it up as best as i could.

anyways, if ppl can test it out and browse the code I'd appreciate any feedback you can give.

I've tried to make sure it doesn't leak but there's a lot of stuff I've overlooked. If I'm doing something completely ass backwards, let me know.

Mercenary Clash_Beta_v0.1.rar
(72.63 KiB) Downloaded 258 times

To get an idea of how it works, try getting all the mortars to fire on 1 unit. You'll notice the damage display shows the total damage dealt within that short period of time. Spells that deal dps will stack or will not stack, depending on their damage interval.