• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Help! New to JASS...

Status
Not open for further replies.
Level 2
Joined
May 31, 2007
Messages
7
JASS:
function Trig_Ranged_Attack_Filter takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction

function Trig_Ranged_Attack_Condition2 takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

function Trig_Ranged_Attack_Loop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = GetHandleInt(t, "i")
    local unit a = GetHandleUnit(t, "a")
    local unit r = GetHandleUnit(t, "r")
    local boolexpr d = Condition(function Trig_Ranged_Attack_Filter)
    local unit f
    local group g = CreateGroup()
    call GetUnitsInRangeOfLocMatching(100, GetUnitLoc(r), d)
    set g = GetLastCreatedGroup()
        if CountUnitsInGroup(g) >= 1 then
            loop
                set f = FirstOfGroup(g)
                exitwhen f == null
                call UnitDamageTargetBJ(a, f, (100+(I2R(GetHeroStatBJ(bj_HEROSTAT_STR, a, true)))*2.50), ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL)
                call AddSpecialEffectTargetUnitBJ("head", GetEnumUnit(), "Objects\\Spawnmodels\\Critters\\Albatrosse\\CritterBloodAlbatross.mdl")
                call GroupRemoveUnit(g, f)
            endloop
                set f = null
                set g = null
                set d = null
            else
                call SetUnitPositionLoc(r, PolarProjectionBJ(GetUnitLoc(r), 15.00, GetUnitFacing(r)))
        endif
    call SetHandleInt(t, "i", i+1)
    if i >= 40 then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        set t = null
    endif
endfunction

function Trig_Ranged_Attack_Actions takes nothing returns nothing
    local timer t
    local location p = PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), 600.00, GetUnitFacing(GetSpellAbilityUnit()))
    local real i = 1.00
    if GetSpellAbilityId() == 'A002' then
        set t = CreateTimer()
        call CreateNUnitsAtLocFacingLocBJ( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), GetUnitLoc(GetSpellAbilityUnit()), p )
        call SetHandleHandle(t, "r", GetLastCreatedUnit())
        call SetHandleHandle(t, "a", GetSpellAbilityUnit())
        call SetHandleInt(t, "i", R2I(i))
        call TimerStart(t, i, true, function Trig_Ranged_Attack_Loop)
    endif
endfunction


//===========================================================================
function InitTrig_Ranged_Attack takes nothing returns nothing
    set gg_trg_Ranged_Attack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ranged_Attack, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Ranged_Attack, Condition(function Trig_Ranged_Attack_Condition2))
    call TriggerAddAction( gg_trg_Ranged_Attack, function Trig_Ranged_Attack_Actions )
endfunction

So what it should do is create a projectile and then send it off to 600 in front of a unit. It worked a while ago, but I tried to make it multiinstanceable, and now it works not so well. I removed the parts of the trigger that remove the projectile, and now it just makes an arrow above the shooters head for maybe 1 second...

Erm... help? Where do I place the dummy unit (projectile) removal, why isn't it working, will this actually do damage?

EDIT: Made a few minor edits, now when a unit uses the ability, the projectile dummy appears over the targets head... so... thats not much of an improvement. And it still doesnt do damage. And I still don't know when to remove it...

EDIT2: Actually it is just putting the arrows 600 infront of whatever is getting shot...

EDIT3: Oh, I'm fairly certain that the problem is that I don't want a loop so much as I want to use timers, so I need to recode a lot of this...

And now I don't know what I'm going to do. I need to make the loop stuff happen every 0.05 seconds... but I don't really know how to do that. Time for more research...

EDIT4: Ok... updated what I have now... the old code isnt here anymore, I still have it if you want to look at it, but it doesn't make sense. I would like to test it but it crashes my editor... so I don't really know what to do...

EDIT5: Updated to latest version of code.

EDIT6: After a lot of help, another updated version of the code. Still need a lot more help. Still doesn't work. Its back to making the arrow dummy at the caster...

EDIT7: Okay big changes, I was way off. I think its closer to making sense, but still doesn't work...

EDIT8: Most recent version, I recoded it from mostly scratch. Still doesn't work :p
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
JASS:
function Trig_Attack_Base_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A002' ) ) then
        return false
    endif
    return true
endfunction

Is equal to:

JASS:
function Trig_Attack_Base_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

And its more efficient.

GetSpellAbilityUnit() = GetTriggerUnit()

JASS:
function Trig_Attack_Base_Conditions2 takes nothing returns boolean
    local unit a = GetTriggerUnit()
    if ( not ( GetOwningPlayer(GetEnumUnit()) != GetOwningPlayer(a) ) ) then
        return false
    endif
    return true
endfunction

Is equal to:

JASS:
function Trig_Attack_Base_Conditions2 takes nothing returns boolean
    local unit a = GetTriggerUnit()
    return GetOwningPlayer(GetEnumUnit()) != GetOwningPlayer(a)
endfunction

Lots of OMG leaks, BJs, and I don't feel like correcting them to a stranger. Also, use the goddamn coordinates, and CreateNUnitsAtLoc.......I'm allergic to that :). Maybe later I will find the actual problem. Don't start with something you cannot handle
 
Last edited:
Level 2
Joined
May 31, 2007
Messages
7
I know, I'll clear leaks once I get it working, but so far that has been somewhat of a challenge...

EDIT: and right now I'm recoding it to... hopefully be more efficient/work...

EDIT2: And... first post is updated with the recode. Still doesn't work however... So I guess my general idea is flawed, but I don't know how...
 
Last edited:
Status
Not open for further replies.
Top