• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Random Units in an area

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I was wondering, is there a way to make a dummy unit spawn in an random area within 800 of a target unit. And ( I know how to add an ability) is it more efficient to have the created unit cast an ability (fearie fire) and then have that same unit attack the target (with 100% bash) or create a second dummy and have it attack the same unit?

All I am really worried about is creating the dummy in a random spot basically this is what I got (I dont know how to make it a periodic event, nor how to make it a random spot):
JASS:
function Trig_Stunner_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'
endfunction

function Trig_Stunner_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local location t = GetSpellTargetLoc()
    local group g = CreateGroup()
    local unit u = FirstOfGroup(g)
    local unit dumb
    call GroupEnumUnitsInRangeOfLoc(g, t, 800, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        if IsUnitEnemy(u, GetOwningPlayer(cast)) then
        set dumb = CreateUnit(GetOwningPlayer(cast), 'h008', GetUnitX(cast), GetUnitY(cast), 0.00)
        call UnitAddAbility(dumb, 'A00F')
        call IssueTargetOrder(dumb, "faeriefire", u)        
        call UnitApplyTimedLife(dumb, 'BTLF', 3)
        // I don't know whether to order the dummy to attack, or create another one.
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call RemoveLocation(t)
    call DestroyGroup(g)
    set g = null
    set dumb = null
    set cast = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stunner takes nothing returns nothing
    set gg_trg_Stunner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stunner, EVENT_PLAYER_UNIT_SPELL_EFFECT )// I want to make this a repeating event, but Im not sure how to make it every half second.
    call TriggerAddCondition( gg_trg_Stunner, Condition( function Trig_Stunner_Conditions ) )
    call TriggerAddAction( gg_trg_Stunner, function Trig_Stunner_Actions )
endfunction

Thanks in advance (once again)
 
Something like this should work:
JASS:
function CreateDummyRandomArea takes integer dummyId, real x, real y, real range returns unit
    return CreateUnit(Player(15),dummyId,x+GetRandomReal(x,range)*Cos(GetRandomReal(bj_PI,2*bj_PI)),y+GetRandomReal(y,range)*Sin(GetRandomReal(bj_PI,2*bj_PI)),0)
endfunction

Or this for organization:
JASS:
function CreateDummyRandomArea takes integer dummyId, real x, real y, real range returns unit
    local real randx = x+GetRandomReal(x,range)*Cos(GetRandomReal(bj_PI,2*bj_PI)) 
    local real randy = y+GetRandomReal(y,range)*Sin(GetRandomReal(bj_PI,2*bj_PI))
    return CreateUnit(Player(15),dummyId,randx,randy,0)
endfunction

Basically randomizes the x/y offset and the angle of the offset.
 
So is this correct then?? I added the timer as i needed to, and also added the random unit event.
JASS:
function Trig_Stunner_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'
endfunction

function CreateDummyRandomArea takes integer dummyId, real x, real y, real range returns unit
    local unit cast = GetTriggerUnit()
    local real randx = x+GetRandomReal(x,range)*Cos(GetRandomReal(bj_PI,2*bj_PI)) 
    local real randy = y+GetRandomReal(y,range)*Sin(GetRandomReal(bj_PI,2*bj_PI))
    return CreateUnit(GetOwningPlayer(cast), 'hoo8', randx, randy, 0.)
endfunction

function Pacifier_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    // Naw, Im lost. If I put in "call CreateDummyRandomArea()",
    // How do i call the unit that was created? I think it would be 
    //pretty simple with the rest of it. I might be wrong. :( Just an 
    //experiment, Please tell me what i did wrong thus far. 

function Trig_Stunner_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local location t = GetSpellTargetLoc()
    local group g = CreateGroup()
    local unit u = FirstOfGroup(g)
    local unit dumb
    local timer t = CreateTimer()
    call GroupEnumUnitsInRangeOfLoc(g, t, 800, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        if IsUnitEnemy(u, GetOwningPlayer(cast)) then
        set dumb = CreateUnit(GetOwningPlayer(cast), 'h008', GetUnitX(cast), GetUnitY(cast), 0.00)
        call UnitAddAbility(dumb, 'A00F')
        call IssueTargetOrder(dumb, "faeriefire", u)        
        call UnitApplyTimedLife(dumb, 'BTLF', 3)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call TimerStart(t, .50, true, function Stunner_Repeater)
    call RemoveLocation(t)
    call DestroyGroup(g)
    set g = null
    set dumb = null
    set cast = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stunner takes nothing returns nothing
    set gg_trg_Stunner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stunner, EVENT_PLAYER_UNIT_SPELL_EFFECT )// I want to make this a repeating event, but Im not sure how to make it every half second.
    call TriggerAddCondition( gg_trg_Stunner, Condition( function Trig_Stunner_Conditions ) )
    call TriggerAddAction( gg_trg_Stunner, function Trig_Stunner_Actions )
endfunction
 
I added some comments to the code, fixed some things, but for the most part it is just questions:
JASS:
function Trig_Stunner_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'
endfunction

function CreateDummyRandomArea takes player whichPlayer, integer dummyId, real x, real y, real range returns unit
    //local unit cast = GetTriggerUnit()
    //I've just added "takes player whichPlayer" =)
    local real randx = x+GetRandomReal(x,range)*Cos(GetRandomReal(bj_PI,2*bj_PI))
    local real randy = y+GetRandomReal(y,range)*Sin(GetRandomReal(bj_PI,2*bj_PI))
    return CreateUnit(GetOwningPlayer(whichPlayer), 'hoo8', randx, randy, 0.)
endfunction

function Pacifier_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    //It is actually a bit difficult. You'd probably end up using hashtables:
    //https://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/hashtables-mui-133407/
    //That is a link to the tutorial explaining them. Basically, you save the things you need to the id of the timer.
    //However, we need some more info:
    //   - First off, what are you planning to do in this timer function? =) It ticks every 0.5 seconds.
    //   - Second, what things do you think you'd need to save. (eg: unit, point, group, etc.)
    //   - Third, what is the spell supposed to do? (you can probably just post the tooltip) 
endfunction

function Trig_Stunner_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local location t = GetSpellTargetLoc()
    local group g = CreateGroup()
    local unit u = FirstOfGroup(g)
    local unit dumb
    local timer t = CreateTimer()
    call GroupEnumUnitsInRangeOfLoc(g, t, 800, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        if IsUnitEnemy(u, GetOwningPlayer(cast)) then
            set dumb = CreateUnit(GetOwningPlayer(cast), 'h008', GetUnitX(cast), GetUnitY(cast), 0.00)
            //Are you trying to create the dummy right here?
            //If so, use "set dumb = CreateDummyRandomArea(GetOwningPlayer(cast),'h008',GetUnitX(cast),GetUnitY(cast),800)"
            //If not, then just ignore these 3 comments.
            call UnitAddAbility(dumb, 'A00F')
            call IssueTargetOrder(dumb, "faeriefire", u)
            call UnitApplyTimedLife(dumb, 'BTLF', 3)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call TimerStart(t, .50, true, function Stunner_Repeater)
    //call RemoveLocation(t), the timer isn't a location. =D
    //Also, we will save destroying it until the timer is done.
    call DestroyGroup(g)
    set g = null
    set dumb = null
    set cast = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Stunner takes nothing returns nothing
    set gg_trg_Stunner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stunner, EVENT_PLAYER_UNIT_SPELL_EFFECT )// I want to make this a repeating event, but Im not sure how to make it every half second.
    call TriggerAddCondition( gg_trg_Stunner, Condition( function Trig_Stunner_Conditions ) )
    call TriggerAddAction( gg_trg_Stunner, function Trig_Stunner_Actions )
endfunction

Answer those and I'm sure we'll find an answer. =)
 
//It is actually a bit difficult. You'd probably end up using hashtables:
//https://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/hashtables-mui-133407/
//That is a link to the tutorial explaining them. Basically, you save the things you need to the id of the timer.
//However, we need some more info:
// - First off, what are you planning to do in this timer function? =) It ticks every 0.5 seconds.
// - Second, what things do you think you'd need to save. (eg: unit, point, group, etc.)
// - Third, what is the spell supposed to do? (you can probably just post the tooltip)

1) Thanks, I tried learning hashtables once, but Im afraid I was inept at making it work, so i gave up :sad:
1b)The timer itself is supposed to create a wave effect. The faeriefire is only a part of the spell, I really wanted the dummy model (yes its visible)
2)I really don't know, mostly just the dummy unit created at a random spot.
3)I creates a dummy for every enemy unit in the area, casts feariefire on them, then I was thinking of making them attack their same spell targeted unit. After the main effect, I wanted a timer that did the same thing, creating a unit in a random spot around the caster. The dummy units have two abilities in the end: faerie fire (Customed) and permabash (100% with an attack cd of .10) The spell itself runs for 15 seconds, or until cancelled (I'm still working on this part)


if IsUnitEnemy(u, GetOwningPlayer(cast)) then
set dumb = CreateUnit(GetOwningPlayer(cast), 'h008', GetUnitX(cast), GetUnitY(cast), 0.00)
//Are you trying to create the dummy right here?
//If so, use "set dumb = CreateDummyRandomArea(GetOwningPlayer(cast),'h008',GetUnitX(cast),GetUnitY(cast),800)"
//If not, then just ignore these 3 comments.

Ignored :thumbs_up:


call TimerStart(t, .50, true, function Stunner_Repeater)
//call RemoveLocation(t), the timer isn't a location. =D
//Also, we will save destroying it until the timer is done.
Okay, Thanks for that. I seen once that they nulled the timer, perhaps I am mistaken on the tut. I know you can destroy it, I really didnt think about it.

Basically its all about me learning hashtables, all the while me trying to learn JASS as well. This should be fun :thumbs_up:
 
Status
Not open for further replies.
Back
Top