• 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] Help Edit Jass Code

Status
Not open for further replies.
Level 13
Joined
Jun 10, 2007
Messages
780
Hey, I'm in need of a fixing for this jass code. What it does currently is it makes a random unit near you get selected and moved to the targeted unit. I want the spell to, however be able to select a point so that the unit will move to the point. When I edited it and tried to make it toss to a point, it would toss it into the middle of the map. My question is, can someone edit this script so that when I select an area (not a unit!!), it will make the unit move there and not to the center of the map area. And also, can someone use a variable to track the unit moved?
Variable: R = Real number (non array)
Variable: CsCache = A game catche (base value 0)

JASS:
function Trig_Toss_Current_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A007'
endfunction

function TossCheck2 takes nothing returns boolean
    return not IsUnitType(GetFilterUnit(),UNIT_TYPE_FLYING) and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and not (GetUnitTypeId(GetFilterUnit()) == 'E000') and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction

function TossCurrentAction takes nothing returns nothing
    local string s = I2S(H2I(GetExpiredTimer()))
    local gamecache gc = udg_CSCache
    local unit targ = I2U(GetStoredInteger(gc,s,"targ"))
    local unit Tiny = I2U(GetStoredInteger(gc,s,"Tiny"))
    local real angle = GetStoredReal(gc,s,"angle")
    local unit hitD
    local real x = GetUnitX(targ)
    local real y = GetUnitY(targ)
    local location qw = Location(x,y)
    local real px = GetStoredReal(gc,s,"px")
    local real py = GetStoredReal(gc,s,"py")
    local real moved = GetStoredReal(gc,s,"moved")
    local real range = GetStoredReal(gc,s,"range")
    local real spd
    local real dist = SquareRoot((px - x)*(px - x) + (py - y)*(py - y)) 
    local integer lvl = GetStoredInteger(gc,s,"lvl")
    local real det = moved/range
    local real face = GetStoredReal(gc,s,"face") + 4
    local real z
    local real fxl = 0
    local group dmgD
    local boolexpr chk = Condition(function TossCheck2)
        
    if det < 0.2 or det > 0.8 then
        set spd = (range/1100)*40
      elseif (det >= 0.2 and det < 0.35) or (det <= 0.8 and det > 0.65) then
          set spd = (range/1100)*34
        elseif (det > 0.35 and det <= 0.5) or (det <= 0.65 and det > 0.5) then
           set spd = (range/1100)*20
    endif
    
    if moved < range then
        set moved = moved + spd
        set det = moved/range
        set z = 750 * Sin(det * bj_PI)
        call SetUnitPosition(targ,x + spd*Cos(angle),y+spd*Sin(angle))
        call SetUnitFlyHeight(targ,z,0)
        call StoreReal(gc,s,"moved",moved)
        call SetUnitFacing(targ,face)
        call StoreReal(gc,s,"face",face)
        call StoreReal(gc,s,"spd",spd)
      else
          call DestroyTimer(GetExpiredTimer())
          call PauseUnit(targ,false)
          call SetUnitPathing(targ,true)
          call SetUnitFlyHeight(targ,0,0)
          call FlushStoredMission(gc,s)
          if targ != null then
              set dmgD = CreateGroup()
              call GroupEnumUnitsInRange(dmgD,x+spd*Cos(angle),y+spd*Sin(angle),275,chk)
              call TerrainDeformationRippleBJ( 0.49, false, qw, 275.00, 275.00, 25.00, 0.25, 275 )
              call UnitDamageTarget(Tiny,targ,150,false,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_DEMOLITION,WEAPON_TYPE_WHOKNOWS)
              call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\FlakCannons\\FlakTarget.mdl",targ,"origin"))
              loop
                  exitwhen dmgD == null
                  set hitD = FirstOfGroup(dmgD)
                  if IsUnitEnemy(hitD,GetOwningPlayer(Tiny)) then
                      call UnitDamageTarget(Tiny,hitD,75*lvl,false,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_DEMOLITION,WEAPON_TYPE_WHOKNOWS)
                      call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\FlakCannons\\FlakTarget.mdl",hitD,"origin"))
                  endif
                  call GroupRemoveUnit(dmgD,hitD)
              endloop
              call DestroyGroup(dmgD)
          endif
          
    endif
    call DestroyBoolExpr(chk)
    call RemoveLocation(qw)
    set dmgD = null
    set gc = null
    set dmgD = null
    set targ = null
    set Tiny = null
endfunction
     
function TossMainActions takes nothing returns nothing
    local unit Tiny = GetTriggerUnit()
    local unit pt = GetSpellTargetUnit()
    local real x = GetUnitX(Tiny)
    local real y = GetUnitY(Tiny)
    local real tx
    local real ty
    local real px = GetUnitX(pt) + 10
    local real py = GetUnitY(pt) + 10
    local real range
    local gamecache gc = udg_CSCache
    local unit targ
    local real angle
    local timer t = CreateTimer()
    local string s = I2S(H2I(t))
    local integer lvl = GetUnitAbilityLevel(Tiny,'A007')
    local group g = CreateGroup()
    local boolexpr chk = Condition(function TossCheck2)

    call SetUnitAnimation(Tiny,"stand")    
    call GroupEnumUnitsInRange(g,GetUnitX(Tiny),GetUnitY(Tiny),200,chk)
    set targ = GroupPickRandomUnit(g)
    set tx = GetUnitX(targ)
    set ty = GetUnitY(targ)
    set range = SquareRoot((tx - px)*(tx - px) + (ty - py)*(ty - py))
    set angle = Atan2((py - ty),(px - tx))
    
    call UnitAddAbility(targ,'Arav')
    call UnitRemoveAbility(targ,'Arav')
    call SetUnitPathing(targ,false)
    
    call StoreReal(gc,s,"angle",angle)
    call StoreReal(gc,s,"py",py)
    call StoreReal(gc,s,"px",px)
    call StoreReal(gc,s,"angle",angle)
    call StoreReal(gc,s,"range",range)
    call StoreReal(gc,s,"face",GetUnitFacing(targ))
    call StoreInteger(gc,s,"targ",H2I(targ))
    call StoreInteger(gc,s,"lvl",lvl)
    call StoreInteger(gc,s,"Tiny",H2I(Tiny))
    
    call PauseUnit(targ,true)
    call TimerStart(t,0.03,true,function TossCurrentAction)
    call DestroyBoolExpr(chk)

    set chk = null
    set t = null
    set gc = null
    set Tiny = null
    set targ = null
endfunction

function InitTrig_Toss_Current_Copy takes nothing returns nothing
    set gg_trg_Toss_Current_Copy = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Toss_Current_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Toss_Current_Copy, Condition( function Trig_Toss_Current_Conditions ) )
    call TriggerAddAction( gg_trg_Toss_Current_Copy, function TossMainActions )
endfunction
 
Last edited:
Status
Not open for further replies.
Top