• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] How can i make this work??

Status
Not open for further replies.
Level 18
Joined
Oct 18, 2007
Messages
930
Ok im VERRY new to jass and im trying something but it dosent seem to work :(

So how can i make this work??

I did:
  • Kaboom
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Suicide Bomb
    • Actions
      • Custom script: local unit u = GetTriggerUnit()
      • Custom script: local location Kaboom
      • Wait 2.00 seconds
      • Custom script: set Kaboom = GetUnitLoc( u )
      • Custom script: set udg_Group = GetUnitsInRangeOfLocMatching(500.00, Kaboom, Condition(function Trig_Kaboom_Func011002003))
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
      • Custom script: set u = null
Hows how it looks in Converted Text
JASS:
function Trig_Kaboom_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Kaboom_Func012002003 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function Trig_Kaboom_Func013A takes nothing returns nothing
endfunction

function Trig_Kaboom_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location Kaboom
    call PlaySoundBJ( udg_Lalalalalala[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] )
    call TriggerSleepAction( 2.00 )
    call CameraSetEQNoiseForPlayer( GetOwningPlayer(GetTriggerUnit()), 8.00 )
    call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(GetTriggerUnit()), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
    call UnitApplyTimedLifeBJ( 4.00, 'BTLF', GetLastCreatedUnit() )
    call AddSpecialEffectLocBJ( GetRectCenter(GetPlayableMapRect()), "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl" )
    call DestroyEffectBJ( GetLastCreatedEffectBJ() )
    set Kaboom = GetUnitLoc( u )
    set udg_Group = GetUnitsInRangeOfLocMatching(500.00, Kaboom, Condition(function Trig_Kaboom_Func011002003))
    set udg_Group = GetUnitsInRangeOfLocMatching(500.00, GetRectCenter(GetPlayableMapRect()), Condition(function Trig_Kaboom_Func012002003))
    call ForGroupBJ( udg_Group, function Trig_Kaboom_Func013A )
    call TriggerSleepAction( 1.50 )
    call CameraClearNoiseForPlayer( GetOwningPlayer(GetTriggerUnit()) )
    set u = null
endfunction

//===========================================================================
function InitTrig_Kaboom takes nothing returns nothing
    set gg_trg_Kaboom = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Kaboom, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Kaboom, Condition( function Trig_Kaboom_Conditions ) )
    call TriggerAddAction( gg_trg_Kaboom, function Trig_Kaboom_Actions )
endfunction

Would be nice if someone told me why
JASS:
set udg_Group = GetUnitsInRangeOfLocMatching(500.00, Kaboom, Condition(function Trig_Kaboom_Func011002003))
Does not work.

[+] if someone knew how to make a local group and do the things that i wanted to do, plz post it :).

Thx
 
Level 5
Joined
Dec 18, 2007
Messages
205
I think the problem is that Trig_Kaboom_Func012002003 does not detect 'GetTriggerUnit()' anymore.
Instead of using 'ForGroupBJ' and 'GetUnitsInRangeOfLocMatching' you should make loops for both events. this way you avoid that 'GetTriggerUnit' bug like this:

JASS:
function mytrigger takes nothing returns nothing
local unit u=GetTriggerUnit()
local unit x
local group g=CreateGroup()
local group h=CreateGroup()
local location kaboom

//some code
call TriggerSleepAction(2.) // The wait function that causes the GetTriggerUnit()-error

set kaboom=GetUnitLoc(u)
set g=GetUnitsInRangeOfLocAll(500.,kaboom)
loop
    set x=FirstOfGroup(g)
    exitwhen x==null
    if IsUnitEnemy(x,GetOwningPlayer(u)) and GetUnitState(x,UNIT_STATE_LIFE)>0 then
        call GroupAddUnit(h,x)
    endif
    call GroupRemoveUnit(g,x)    
endloop
call DestroyGroup(g)
// now all units that are in group h are living enemys in 500 range of your unit, now do with them what you want
loop
    set x=FirstOfGroup(h)
    exitwhen x==null
    //actions with each unit
    call GroupRemoveUnit(h,x)
endloop
call DestroyGroup(h)
call RemoveLocation(kaboom)
set h=null
set g=null
set u=null
set kaboom=null
endfunction

And here some tips to improve your code:

JASS:
//locations leak, because of that use
call RemoveLoaction(kaboom) // and
set kaboom=null // so it doesnt leak anymore
in my script you see other things that leak, e.g. a group. next thing is this trigger

JASS:
function Trig_Kaboom_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

if you look closely you recognize that you can rewrite it to a faster way:
JASS:
function Trig_Kaboom_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

another hint are nearly all BJ-functions WE uses when you convert things. for example
JASS:
call UnitApplyTimedLifeBJ( 4.00, 'BTLF', GetLastCreatedUnit() )
just makes this
JASS:
function UnitApplyTimedLifeBJ takes real duration, integer buffId, unit whichUnit returns nothing
    call UnitApplyTimedLife(whichUnit, buffId, duration)
endfunction
so you could write
JASS:
call UnitApplyTimedLife(GetLastCreatedUnit(),'BTLF',4.)
This is a faster way.

That's all i can tell you for now. I don't have more time.

greetz
 
Status
Not open for further replies.
Top