• 🏆 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!

[JASS] 180 % help.

Status
Not open for further replies.
Level 8
Joined
Jun 18, 2007
Messages
214
Hello, there. I'm trying to make a spell that summons novas starting from caster's east all the way to his west side. Now I managed to calculate 180 % degrees divided by the number of novas. It's working except it always summons novas north-west all to way to north-east side.

I'm trying to find out how to make does novas summon in front of the caster like I said from his east to west side, or west to east. I failed 100 times with GetUnitFacing, and math is not really my strongest side :p. So, if anyone can help I would be most grateful.

Here's the code.

JASS:
constant function Swing_Slash_Rawcode takes nothing returns integer
    return 'A000'
endfunction

constant function Nova_SFX takes nothing returns string
    return "Objects\\Spawnmodels\\Undead\\UndeadLargeDeathExplode\\UndeadLargeDeathExplode.mdl"
endfunction

constant function Hit_SFX takes nothing returns string
    return "Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl"
endfunction

constant function Slash_Distance takes nothing returns real
    return 200.0
endfunction

constant function Damage_Radius takes nothing returns real
    return 125.0
endfunction

constant function Slash_Damage takes integer i returns real
    return 100.0*i
endfunction    

constant function Slash_Number takes nothing returns integer
    return 20
endfunction

constant function Nova_Spawn_Speed takes nothing returns real
    return 0.1
endfunction
//==========================================================================================================================================================================================================
//Condition trigger.
function Trig_Swing_Slash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Swing_Slash_Rawcode()
endfunction

//Filter for picking enemies in group.
function Swing_Slash_Filter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), bj_groupEnumOwningPlayer) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and (GetWidgetLife(GetFilterUnit())>0.405)
endfunction
//==========================================================================================================================================================================================================


//===========EXECUTE NOVA===============================================================================
function Slash_Nova takes nothing returns nothing
 local timer novatimer = GetExpiredTimer()
 local unit damager    = LoadUnitHandle(udg_Hash, GetHandleId(novatimer), 1)
 local unit ug         =  null
 local integer angle   = 180/Slash_Number()
 local integer count   = LoadInteger(udg_Hash, GetHandleId(novatimer), 2)
 local real x          = LoadReal(udg_Hash, GetHandleId(novatimer), 3)
 local real y          = LoadReal(udg_Hash, GetHandleId(novatimer), 4)
 local group g         =  null
 local boolexpr b      =  null
 local real newX
 local real newY 
 
 if count != Slash_Number() then
 
  set newX = x + Slash_Distance() * Cos(I2R(angle*count) * bj_DEGTORAD)
  set newY = y + Slash_Distance() * Sin(I2R(angle*count) * bj_DEGTORAD)
  call DestroyEffect(AddSpecialEffect(Nova_SFX(), newX, newY)) 
  call SaveInteger  (udg_Hash, GetHandleId(novatimer), 2, count + 1)
  
  set g                        = CreateGroup()
  set b                        = Condition(function Swing_Slash_Filter)
  set bj_groupEnumOwningPlayer = GetOwningPlayer(damager)
  call GroupEnumUnitsInRange(g, newX, newY, Damage_Radius(), b)
  call DestroyBoolExpr(b)
        
        loop   
            set ug = FirstOfGroup(g)
            exitwhen ug == null
            call GroupRemoveUnit(g, ug)
            call DestroyEffect(AddSpecialEffect(Hit_SFX(), GetUnitX(ug), GetUnitY(ug)))
            call UnitDamageTarget(damager, ug, Slash_Damage(GetUnitAbilityLevel(damager, Swing_Slash_Rawcode())), true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
        endloop
   call DestroyGroup(g)
   set g = null
   set b = null
   set novatimer = null
   set damager = null
   set ug = null
   
 else
    
    call FlushChildHashtable(udg_Hash, GetHandleId(novatimer))
    call PauseTimer(novatimer)
    call DestroyTimer(novatimer)
    set novatimer = null
    set b = null
    set g = null
    set damager = null
    set ug = null
  endif
endfunction       


//===============SETTINGS FOR 180 % NOVA==============================================================================
function Trig_Swing_Slash_Actions takes nothing returns nothing
 local timer novatimer = CreateTimer()
 local unit cast       = GetTriggerUnit()
 local integer count   = 1
 local real cX         = GetUnitX(cast)
 local real cY         = GetUnitY(cast)

        call BJDebugMsg(R2S(GetUnitFacing(cast)))
        call SaveUnitHandle  (udg_Hash, GetHandleId(novatimer), 1, cast)
        call SaveInteger     (udg_Hash, GetHandleId(novatimer), 2, count)
        call SaveReal        (udg_Hash, GetHandleId(novatimer), 3, cX)
        call SaveReal        (udg_Hash, GetHandleId(novatimer), 4, cY)
        call TimerStart(novatimer, Nova_Spawn_Speed(), true, function Slash_Nova)
    set novatimer = null
    set cast      = null
endfunction
     


//=============INIT TRIGG===================================================================
function InitTrig_Swing_Slash takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer guza

    set guza = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(guza), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set guza = guza + 1
        exitwhen guza == 16
    endloop

    call TriggerAddCondition(trig, Condition(function Trig_Swing_Slash_Conditions))
    call TriggerAddAction(trig, function Trig_Swing_Slash_Actions)
    
    call Preload(Nova_SFX())
    call Preload(Hit_SFX())
    call PreloadStart()
    
    
    set udg_Hash = InitHashtable()
    set trig = null
endfunction

Thank you!
 
Level 6
Joined
Oct 31, 2008
Messages
229
It's simple. You get the facing of the unit right?
Then. try with For loop integer (whatever variable) starting value (convert real to integer the facing angle of your unit - something) ending value ( the integerified real of your units angle + something)
 
Level 8
Joined
Jun 18, 2007
Messages
214
It's simple. You get the facing of the unit right?
Then. try with For loop integer (whatever variable) starting value (convert real to integer the facing angle of your unit - something) ending value ( the integerified real of your units angle + something)

Before I understood something. Now I don't understand a thing. For loop integer, that's a GUI action. Ok, I convert facing to integer, I get that. Ending value? What ending value?

If I understood you right (which I highly doubt) this will create first nova directly in front of caster, while adding some number to move right or left. I need something that will create first nova on his right or left side while moving to his opposite side(right or left) side, while moving in front of him. Like an arc.
 
Level 6
Joined
Oct 31, 2008
Messages
229
Ok lets say jass

The use of For loop integer is this:
For Integer <variable> from <starting value> to <ending value>
this will set the variable to starting value, perform the actions you want it to perform, and then increase the value by 1. Until it takes the ending value.
Now, for starting value, put the (Facing of the unit - 30) and for ending the (facing of unit +30) and inside the loop do whatever you want.

Inside the value, put an If statement so every time it has the facing you want, do the action you want. Or try to make it with a loop in jass.
 
Level 8
Joined
Jun 18, 2007
Messages
214
Set angle to:
JASS:
local integer angle = GetUnitFacing(damager) + (180/Slash_Number())

Told you before tried this 100 times. It's not working. GetUnitFacing gives you degrees, which means you need to convert it to radians (because Cos and Sin take radians not degrees. I convert it with GetUnitFacing(damager) * (bj_PI/180.0) same as * bj_DEGTORAD. Now adding this still does the same thing it always starts on his north-east side and goes to his north-west.

EDIT: It seems we didn't quite understand each other. I need a mathematical formula that will calculate his angle from his right (or left side) to his left (or right side), while being dived by the number of total novas. While movement is in front of him.
 
Level 4
Joined
Apr 16, 2009
Messages
85
try:

JASS:
local integer angle   = 180/Slash_Number()
local real start = GetUnitFacing(damager) - 90.0
  set newX = x + Slash_Distance() * Cos((start + angle * count) * bj_DEGTORAD)
  set newY = y + Slash_Distance() * Sin((start + angle * count) * bj_DEGTORAD)
 
Last edited:
Status
Not open for further replies.
Top