• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Condition checking Dest/Unit Collision + JassCorrection

Status
Not open for further replies.
Level 3
Joined
May 3, 2004
Messages
46
Aloha, a bit stuck on Jass atm(maybe since I recently started ;P) and I am trying to make an ability that when you use it, it'll create a dummy-bullet and also start a timer that moves the bullet. The timer function also has "if then else" function, that should check wether or not there is a destructible or unit(except the casting) colliding with it/within radius, And this is what I kinda got to atm, please correct me and/or give me advices if I have misunderstood some Jass functions/things/whatever ^^

JASS:
//=======Condition = True?=======================
function Shoot_Cond takes nothing returns boolean 
return GetSpellAbilityId() == 'A000'              
endfunction

//=======Action - Timer===============================================================================================================
 function Shoot_TimerAction takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local unit caster = GetHandleUnit(t, "caster")
 local unit bullet = GetHandleUnit(t, "bullet")
 call EnumDestructablesInRectAll( GetPlayableMapRect(), //<------------ STUCK
 if Condition(---TheCondition---)==true                 //<------------ STUCK
    then
        call UnitDamagePointLoc(caster, 0.15, 80.00, GetUnitLoc(bullet), GetRandomReal(80.00, 120.00), ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)
        call KillUnit(bullet)
    else
        call SetUnitPositionLoc(bullet, PolarProjectionBJ(GetUnitLoc(bullet), +15.00, GetUnitFacing(bullet))
 endif
 endfunction
 
 //======Action - Start===============================================================================
 function Shoot_Action takes nothing returns nothing
 local timer t
 local unit caster
 local unit bullet
 set caster = GetTriggerUnit()
    call CreateNUnitsAtLoc(1, 'a001', GetOwningPlayer(caster), GetUnitLoc(caster), GetUnitFacing(caster))
 set bullet = GetLastCreatedUnit()
 set t = CreateTimer()
    call TimerStart(t, 0.04, true, function Shoot_TimerAction)
    call TriggerSleepAction(2.00)
    call DestroyTimer(t)
 set t = null
 set caster = null
 set bullet = null
 endfunction
 
 //======Trigger Events etc.======================================
 function InitTrig_ShootSpell takes nothing returns nothing
 local trigger t
 set t = CreateTrigger()
    call TriggerRegisterUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, Condition(function Shoot_Cond))
    call TriggerAddAction(t, Shoot_Action)
 endfunction

I hope the title of my threads aren't too confusing =P

edit: I forgot to mention also what I was trying to do with the two //<--- STUCK lines.
Well, the line with call EnumDestructables....etc. is that since I am used to GUI, I was trying to make some "pick all dest" and then "pick all units except casting unit & bullet" and check if there's any picked unit within radius of the 'bullet' - condition. Hope it made it clearer ^^
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Welcome the the pains of JASS, you got your self a SYNTAX error there, do not worry ill fix it for you.

JASS:
function Shoot_Cond takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Shoot_TimerAction takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit caster = GetHandleUnit(t, "caster")
    local unit bullet = GetHandleUnit(t, "bullet")
    if IsTerrainPathable(GetUnitX(bullet),GetUnitY(bullet),PATHING_TYPE_WALKABILITY)==true then
        call UnitDamagePoint(caster,0.15,80,GetUnitX(bullet),GetUnitY(bullet),GetRandomReal(80,120),FALSE,FALSE,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        call KillUnit(bullet)
    else
        //OPEN LEAK
        call SetUnitPositionLoc(bullet,PolarProjectionBJ(GetUnitLoc(bullet),15,GetUnitFacing(bullet)))
        //END  LEAK
    endif
    set t = null
    set caster = null
    set bullet = null
endfunction

function Shoot_Action takes nothing returns nothing
    local timer t = CreateTimer()
    local unit caster = GetTriggerUnit()
    local unit bullet = CreateUnit(GetOwningPlayer(caster),'a001',GetUnitX(caster),GetUnitY(caster),GetUnitFacing(caster))
    //YOU NEED TO ATTACH THE HANDLES TO THE TIMER HERE
    call TimerStart(t,0.04, true, function Shoot_TimerAction)
    call TriggerSleepAction(2.00)
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
    set caster = null
    set bullet = null
endfunction

function InitTrig_ShootSpell takes nothing returns nothing
    local trigger t
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Shoot_Cond))
    call TriggerAddAction(t,function Shoot_Action)
endfunction

Notice the changes and learn, also note that I left some stuff for you to do and also note that I implimented some collision detection (what your script was after) but not advanced. If you want better you will have to make it your self.
 
Level 3
Joined
May 3, 2004
Messages
46
Thanks alot, I think I understand it a bit better now, :D

But I still keep getting some error from WE whenever I try to save/run the map, it just wont run o.o

Here's a little screenie, since I don't really get what it wants. :s
WEgoesEvil.jpg

The funny thing is that the program I used for writing the Jass in before transferring it to WE, says there's no kinda error except the handlers, so it should work.

(and yeah, the //LEAK comments, were they just comments or "input something here-comments" ? :D
 
Status
Not open for further replies.
Top