• 🏆 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] can you arrange this?

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
JASS:
function Trig_Blink_Jass_Actions takes nothing returns nothing
    local integer Cn = GetPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
    local unit array C[Cn] = GetSpellAbilityUnit()
    local real x
    local real y
    local integer i = 0
    local location loc
    local effect sfx

    set sfx = AddSpecialEffectTarget( "Abilities\\Weapons\\SpiritOfVenganceMissile\\SpiritOfVenganceMissle.mdl", C[Cn], "weapon" )
    
    loop
        if i == 10
            set x = GetUnitX(C[Cn])
            set y = GetUnitY(C[Cn])
            set loc = (x, y)
            set i = i + 0.1
            call TriggerSleepAction( 0.1 )
            call DestroyEffect(
            call SetUnitPositionLoc( C[Cn], PolarProjectionBJ, loc, 300 + (GetUnitAbilityLevel( C[Cn], 'Cbk0' ) * 200  ), GetUnitFacing(C[Cn]))
        endif
        exitwhen i == 10
    endloop
    
endfunction

function Trig_Blink_Jass_Conditions takes nothing returns boolean
    if ( GetUnitTypeId(GetSpellAbilityUnit() == 'H007' ) then
        return false
    endif
    return true
    if ( GetSpellAbilityId() == 'Cbk0' ) then
        return false
    endif
    return true
endfunction

//===========================================================================
function InitTrig_Blink_Jass takes nothing returns nothing
    set gg_trg_Blink_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blink_Jass, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Blink_Jass, Condition(function Trig_Blink_Jass_Conditions) )
    call TriggerAddAction( gg_trg_Blink_Jass, function Trig_Blink_Jass_Actions )
endfunction


//wonder why i put wait action for 0.1? 
//its because the type of spell is instant and 
//you cant choose your target location where 
//you can blink so if i remove the wait action and when 
//the unit uses the ability it will move the unit 
//instantly and will not be able to USE THE ABILITY literally.

i need suggestions on how i arrange that thingy

actually i havnt tried the trigger my self yet
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,208
You have not made it clear what you are after doing.

Anyway you need to learn the basics of JASS. Your code largly did not even make sense.
JASS:
function Trig_Blink_Jass_Actions takes nothing returns nothing
    local unit C = GetSpellAbilityUnit() // cache casting unit, faster than multiple BJ calls
    local real facing = GetUnitFacing(C)*bj_DEGTORAD // cache angle to offset unit (radians), saves recomputing
    local real offset = 300 + (GetUnitAbilityLevel(C,'Cbk0') * 200 // cache offset distance, saves recomputing
    call DestroyEffect(AddSpecialEffectTarget( "Abilities\\Weapons\\SpiritOfVenganceMissile\\SpiritOfVenganceMissle.mdl", C, "weapon" ))
    // SetUnitX/Y does not interrupt units current order so it should finish casting spell
    // offsets are calculated unit trig (pay attention to highschool matemenatics)
    call SetUnitX(C,GetWidgetX(C)+offset*Cos(facing))
    call SetUnitY(C,GetWidgetY(C)+offset*Sin(facing))
    set C = null // this is to cover a WC3 engine bug where local handles do not automatically decriment the garbage collector counter when function ends
endfunction

function Trig_Blink_Jass_Conditions takes nothing returns boolean
    // test if the correct ability is cast and the correct unit is casting it
    return GetSpellAbilityId() == 'Cbk0' and GetUnitTypeId(GetSpellAbilityUnit() == 'H007'
endfunction

function InitTrig_Blink_Jass takes nothing returns nothing
    set gg_trg_Blink_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blink_Jass, EVENT_PLAYER_UNIT_SPELL_EFFECT ) // use effect rather than cast as cast runs too early for most uses
    call TriggerAddCondition( gg_trg_Blink_Jass, Condition(function Trig_Blink_Jass_Conditions) )
    call TriggerAddAction( gg_trg_Blink_Jass, function Trig_Blink_Jass_Actions )
endfunction

This code should work and has been extensivly optimized. Comments should explain why everything is done the way it is. It should also be fully MUI.

Locals are variables with a life expectancy of the function they are declared in and are unique to the running thread. The difference in reality is globals are stored in main memory where all threads can interact with them while locals are stored in the stack which means only the running thread can interact with a particular local instance. JASS does not support static locals (which act as a global with a scope of just that function) like you may be used to in C.
 
Status
Not open for further replies.
Top