HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple JASS Question

08-01-2007, 10:19 PM#1
botanic
I am trying to set range and damage based on the hero's strength and know nearly nothing about JASS (kill me know i know) and was wondering why this didnt work
The first box is what i modified


Collapse JASS:
function SetStr takes nothing returns nothing
    set udg_tempintiger = GetHeroStatBJ(bj_HEROSTAT_STR, gg_unit_Nbst_0060, true)
    set udg_tempreal = I2R(udg_TempInteger)
endfunction

constant function StompDamage takes real level returns real
    return udg_tempreal*level // The damage dealt when the units hits the ground.
endfunction

constant function StompArea takes real level returns real
    return udg_tempreal+level+150 // The spells area of effect.
endfunction

Collapse JASS:
function SetStr takes nothing returns nothing
    set udg_tempintiger = GetHeroStatBJ(bj_HEROSTAT_STR, gg_unit_Nbst_0060, true)
    set udg_tempreal = I2R(udg_TempInteger)
endfunction

constant function StompSpellId takes nothing returns integer
    return 'A01G' // The rawcode of the Stomp spell.
endfunction

constant function StompDamage takes real level returns real
    return udg_tempreal*level // The damage dealt when the units hits the ground.
endfunction

constant function StompArea takes real level returns real
    return udg_tempreal+level+150 // The spells area of effect.
endfunction

constant function StompHitAllies takes nothing returns boolean
    return false // If this is true the spell will affect both allied and enemy units. Otherwise it will affect only enemies.
endfunction

constant function StompDisablePathing takes nothing returns boolean
    return false // If this is true the units will be able to pass through units in their way, while being in the air. That looks best, but can cause problems because the units can land at very strange places, even outside the playable map area.
endfunction

constant function StompFlyHeightChangeAllowerId takes nothing returns integer
    return 'Amrf' // The rawcode of any "Fly Height Trick". If you haven't changed Medivh's Crow Form spell, just leave this as it is now, and it shouldn't cause problems. However if you've changed that spell, copy/paste it, reset the new one, and put its rawcode here.
endfunction

//===========================================================================
//The spell itself. Don't touch it unless you know exactly what you're doing.
function Trig_Stomp_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == StompSpellId()
endfunction

function StompConditions takes nothing returns boolean
    if (StompHitAllies()) then
        return (not(IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL))) and (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0) and (GetFilterUnit() != GetTriggerUnit()) and (not(GetHandleBoolean(GetFilterUnit(), "Stomp"))) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)
    endif
    return (not(IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL))) and (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0) and (IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit()))) and (not(GetHandleBoolean(GetFilterUnit(), "Stomp"))) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)
endfunction

function StompMove takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit e = GetEnumUnit()
    local unit c = GetHandleUnit(t, "caster")
    local group g = GetHandleGroup(t, "group")
    local location l = Location(GetHandleReal(t, "X"), GetHandleReal(t, "Y"))
    local location current = GetUnitLoc(e)
    local location new = PolarProjectionBJ(l, DistanceBetweenPoints(l, current)+18, AngleBetweenPoints(l, current))
    call SetUnitPositionLoc(e, new)
    if (GetHandleBoolean(t, "half")) then
        call SetUnitFlyHeight(e, 0, 1800)
    endif
    if (GetHandleBoolean(t, "end")) then
        call SetUnitInvulnerable(e, false)
        call UnitDamageTarget(c, e, StompDamage(GetHandleInt(t, "level")), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS) // Just if someone should doubt, ATTACK_TYPE_NORMAL is attack type spells in GUI.
        call SetHandleBoolean(e, "Stomp", false)
        call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", new))
        if (StompDisablePathing()) then
            call SetUnitPathing(e, true)
        endif
    endif
    set t = null
    set e = null
    set c = null
    set g = null
    call RemoveLocation(l)
    set l = null
    call RemoveLocation(new)
    set new = null
    call RemoveLocation(current)
    set current = null
endfunction

function StompLoop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local group g = GetHandleGroup(t, "group")
    call SetHandleReal(t, "timeelapsed", GetHandleReal(t, "timeelapsed")+0.05)
    if (GetHandleReal(t, "timeelapsed") > 0.6) then
        call SetHandleBoolean(t, "half", true)
    endif
    if (GetHandleReal(t, "timeelapsed") > 0.9) then
        call SetHandleBoolean(t, "end", true)
    endif
    call ForGroup(g, function StompMove)
    if (GetHandleBoolean(t, "end")) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        call DestroyGroup(g)
    endif
    set t = null
    set g = null
endfunction

function StompStart takes nothing returns nothing
    local unit e = GetEnumUnit()
    local unit c = GetTriggerUnit()
    call UnitAddAbility(e, StompFlyHeightChangeAllowerId())
    call UnitRemoveAbility(e, StompFlyHeightChangeAllowerId())
    call SetUnitFlyHeight(e, 99999999, 1000)
    if (StompDisablePathing()) then
        call SetUnitPathing(e, false)
    endif
    call SetUnitInvulnerable(e, true) // Makes the units invulnerable while they're in the air. If they were vulnerabe, they could get attacked, and if they died their corpse would stay in the air, which looks very ugly.
    call SetHandleBoolean(e, "Stomp", true) // A boolean used so units won't be affected by multiple stomps, that would drew them in different directions which would suck.
    set e = null
    set c = null
endfunction

function Trig_Stomp_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local location l = GetUnitLoc(c)
    local boolexpr be = Condition(function StompConditions)
    local integer level = GetUnitAbilityLevel(c, GetSpellAbilityId())
    local group g = CreateGroup()
    local timer t = CreateTimer()
    call GroupEnumUnitsInRangeOfLoc(g, l, StompArea(level), be)
    call SetHandleReal(t, "X", GetLocationX(l))
    call SetHandleReal(t, "Y", GetLocationY(l))
    call SetHandleInt(t, "level", level)
    call SetHandleHandle(t, "caster", c)
    call SetHandleHandle(t, "group", g)
    call ForGroup(g, function StompStart)
    call TimerStart(t, 0.05, true, function StompLoop) // Some might call it dumb using 0.05, but it ain't. If you used 0.01 the chance for lag would be 5 times greater, and the difference can't be seen with the human eye.
    set c = null // (continued comment) And as there can be many units caught in the AoE it could be really laggy, especially on Battle.net.
    call RemoveLocation(l)
    set l = null
    call DestroyBoolExpr(be)
    set be = null
    set g = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stomp takes nothing returns nothing
    set gg_trg_Stomp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stomp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stomp, Condition( function Trig_Stomp_Conditions ) )
    call TriggerAddAction( gg_trg_Stomp, function Trig_Stomp_Actions )
endfunction

08-01-2007, 11:37 PM#2
Pyrogasm
Change the SetStr function to this:
Collapse JASS:
function SetStr takes nothing returns nothing
    set udg_tempreal = I2R(GetHeroStat(gg_unit_Nbst_0060, true, bj_HEROSTAT_STR))
endfunction
And add this line into your code:
Collapse JASS:
    if (GetHandleBoolean(t, "end")) then
        call SetUnitInvulnerable(e, false)
        call SetStr()
         call UnitDamageTarget(c, e, StompDamage(GetHandleInt(t, "level")), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS) // Just if someone should doubt, ATTACK_TYPE_NORMAL is attack type spells in GUI.
        call SetHandleBoolean(e, "Stomp", false)
        call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", new))
        if (StompDisablePathing()) then
            call SetUnitPathing(e, true)
        endif
    endif

Oh, and this too:
Collapse JASS:
    local timer t = CreateTimer()
    call SetStr()
    call GroupEnumUnitsInRangeOfLoc(g, l, StompArea(level), be)
    call SetHandleReal(t, "X", GetLocationX(l))
    call SetHandleReal(t, "Y", GetLocationY(l))
    call SetHandleInt(t, "level", level)
    call SetHandleHandle(t, "caster", c)
    call SetHandleHandle(t, "group", g)
    call ForGroup(g, function StompStart)
That's the easiest solution without modifying the spell too much.