Projectile Help

Rllulium

New Member
Reaction score
10
Hello Again.

I picked up JASS (very) recently, deciding that it wasn't nearly as complicated as I first had anticipated. While knowledge of GUI and some general programming gave me a head start, problems are gathering up as soon as I attempt anything more complicated. I'd appreciate it if someone could take a look at this projectile spell and tell me what is wrong:
JASS:
globals
trigger PjMoveTrigger
integer PjIndex = 0
integer PjUserData
integer array PjSpellLevel
real array PjRange
real array PjDistance
real array PjAngle
unit array PjCaster
location PjStart
location PjClick
location PjLocation
location PjMovement
group PjGroup = CreateGroup()
group PjTarget = CreateGroup()
group PjRandom = CreateGroup()
endglobals

function PjConditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function PjActions takes nothing returns nothing
    set PjIndex = (PjIndex + 1)
    set PjCaster[PjIndex] = GetSpellAbilityUnit()
    set PjSpellLevel[PjIndex] = GetUnitAbilityLevelSwapped('A004', PjCaster[PjIndex])
    set PjStart = GetUnitLoc(PjCaster[PjIndex])
    set PjClick = GetSpellTargetLoc()
    set PjAngle[PjIndex] = AngleBetweenPoints(PjStart, PjClick)
    call CreateUnitAtLocSaveLast(GetOwningPlayer(PjCaster[PjIndex]),'e000',PolarProjectionBJ(PjStart, 20., PjAngle[PjIndex]) , PjAngle[PjIndex])
    call SetUnitPathing( GetLastCreatedUnit(), false )
    call SetUnitUserData( GetLastCreatedUnit(), PjIndex)
    call GroupAddUnit(PjGroup, GetLastCreatedUnit())
    set PjRange[PjIndex] = 1000.
    set PjDistance[PjIndex] = 0.
    call RemoveLocation(PjStart)
    call RemoveLocation(PjClick)
    if(not( IsTriggerEnabled(PjMoveTrigger)))then
        call EnableTrigger(PjMoveTrigger)
    endif
endfunction

//===========================================================================
function InitTrig_Projectile_Setup takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( t, Condition( function PjConditions ) )
    call TriggerAddAction( t, function PjActions )
endfunction

JASS:
function PjTargetCheck takes nothing returns boolean
    local boolean b = false
    if (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetEnumUnit())) == true and IsUnitAliveBJ(GetFilterUnit()) == true) then
        set b = true
    endif
    return b
endfunction

function PjDamage takes nothing returns nothing
    call Damage_Spell(PjCaster[PjIndex],GetEnumUnit(),100)
endfunction

function PjMove takes nothing returns nothing
    set PjUserData = GetUnitUserData(GetEnumUnit())
    set PjLocation = GetUnitLoc(GetEnumUnit())
    set PjMovement = Location(GetLocationX(PjLocation) + Cos(PjAngle[PjUserData])*20, GetLocationY(PjLocation) + Sin(PjAngle[PjUserData])*20)
    call SetUnitPositionLoc( GetEnumUnit(), PjMovement )
    set PjDistance[PjUserData] = ( PjDistance[PjUserData] + 20.00 )
    set PjTarget = GetUnitsInRangeOfLocMatching(100.00, PjMovement, Condition(function PjTargetCheck))
    set PjRandom = GetRandomSubGroup(1, PjTarget)
    call ForGroup( PjRandom, function PjDamage )
    if ( CountUnitsInGroup(PjTarget) > 0 ) then
        call KillUnit( GetEnumUnit() )
        call GroupRemoveUnit(PjGroup, GetEnumUnit())
    endif
    if( PjDistance[PjUserData]>= PjRange[PjUserData])then
        call KillUnit( GetEnumUnit() )
        call GroupRemoveUnit(PjGroup, GetEnumUnit())
    endif
    call RemoveLocation(PjLocation)
    call RemoveLocation(PjMovement)
    call DestroyGroup(PjTarget)
    call DestroyGroup(PjRandom)
endfunction

function PjMoveActions takes nothing returns nothing
    call ForGroup(PjGroup, function PjMove)
    if ( CountUnitsInGroup(PjGroup) == 0 ) then
        call DisableTrigger( GetTriggeringTrigger() )
    endif
endfunction

//===========================================================================
function InitTrig_Projectile_Movement takes nothing returns nothing
    set PjMoveTrigger = CreateTrigger(  )
    call DisableTrigger( PjMoveTrigger )
    call TriggerRegisterTimerEventPeriodic( PjMoveTrigger, 0.02 )
    call TriggerAddAction( PjMoveTrigger, function PjMove )
endfunction


Thanks in advance!
 

PrisonLove

Hard Realist
Reaction score
78
I know this doesn't really help but you can do this as a bit of optimization. (Sorry I don't have time to help in depth, I have to go to work):

This:
JASS:
function PjConditions takes nothing returns boolean
    local boolean b = false
    if (GetSpellAbilityId() == 'A004' ) then
        set b = true
    endif
    return b
endfunction


Can be turned into:
JASS:
function PjConditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction



I know that doesn't solve your problem, but just something I noticed.
 

Trollvottel

never aging title
Reaction score
262
JASS:
set PjIndex = GetUnitId(GetEnumUnit())


KK, quite high index for an array variable. the size of an array variable is 8190(+2).
Better use some hashing or GetUnitUserData or some Attachment system.
 

Rllulium

New Member
Reaction score
10
I appriciate the advice, thanks for that.

But... the trigger is still not doing anything beyond spawning the dummy at my feet.

EDIT: Updated the code in the original post to its current state.
 

saw792

Is known to say things. That is all.
Reaction score
280
Regardless of whether the spell works correctly or not, this is still coded exactly like a GUI spell. Basically what you're doing here is using a GUI MUI method in JASS, which is quite silly as we have much better ways of doing things in JASS.

Seeing as you are using a globals block I must assume you can use vJASS, so the first thing you should do is take a look at a basic vJASS tutorial, a timer and attachment tutorial and Jesus4Lyf's leakless groups tutorial. Then you can work on running the spell off a single trigger and a timer with a struct and global group, limiting the BJs you use and using x and y coordinates instead of locations.

Unfortunately not many people will be able to/bother to help you with the code in its current state as it is far too messy/overcomplicated/incorrectly implemented, which is why I made the suggestions above. Good luck :)
 

Rllulium

New Member
Reaction score
10
Regardless of whether the spell works correctly or not, this is still coded exactly like a GUI spell. Basically what you're doing here is using a GUI MUI method in JASS, which is quite silly as we have much better ways of doing things in JASS.

Seeing as you are using a globals block I must assume you can use vJASS, so the first thing you should do is take a look at a basic vJASS tutorial, a timer and attachment tutorial and Jesus4Lyf's leakless groups tutorial. Then you can work on running the spell off a single trigger and a timer with a struct and global group, limiting the BJs you use and using x and y coordinates instead of locations.

Unfortunately not many people will be able to/bother to help you with the code in its current state as it is far too messy/overcomplicated/incorrectly implemented, which is why I made the suggestions above. Good luck :)

Thanks. This is exactly the kind of criticism I was looking for. :D

So I remade the whole thing (heavily inspired by tutorials though :p), here it is; now working flawlessly according to 2 minutes of testing. Do please point at places where I might improve it.
JASS:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//      Projectile_Create(unit caster, real damage, real speed, real range, real angle)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
library Projectile requires Damage

private struct Input
    unit Caster
    unit Proj
    real Damage
    real Speed
    real Range
    real Dist
    real Angle
    method Move takes nothing returns nothing
        call SetUnitX(.Proj,GetUnitX(.Proj)+20*Sin(.Angle))
        call SetUnitY(.Proj,GetUnitY(.Proj)+20*Cos(.Angle))
        set .Dist = .Dist + .Speed
    endmethod
endstruct

globals
    private integer Count = 0
    private integer Index
    private group target = CreateGroup()
    private Input array Pj
    private timer Timer = CreateTimer()
endglobals

private function Impact takes nothing returns boolean
if IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(Pj[Index].Caster)) then
    call Damage_Spell(Pj[Index].Caster,GetFilterUnit(),Pj[Index].Damage)
    set Pj[Index].Dist = Pj[Index].Range + 20
endif
return false
endfunction

private function Action takes nothing returns nothing
    set Index = 0
    loop
        exitwhen Index >= Count
        call GroupEnumUnitsInRange(target, GetUnitX(Pj[Index].Proj),GetUnitY(Pj[Index].Proj),100,Filter(function Impact))
        if Pj[Index].Dist > Pj[Index].Range then
            call KillUnit(Pj[Index].Proj)
            call Pj[Index].destroy()
            set Count = Count-1
            if Count > 0 then
                set Pj[Index] = Pj[Count]
                set Index = Index-1
            else
                call PauseTimer(Timer)
            endif
        else
            call Pj[Index].Move()
        endif
        set Index = Index + 1
    endloop
endfunction

public function Create takes unit c, real d, real s, real r, real a returns nothing
    local Input Temp = Input.create()
    set Temp.Caster = c
    set Temp.Damage = d
    set Temp.Speed = s
    set Temp.Range = r
    set Temp.Angle = a
    set Temp.Dist = 0
    call CreateUnitAtLocSaveLast(GetOwningPlayer(Temp.Caster),'e000',Location(GetUnitX(Temp.Caster),GetUnitY(Temp.Caster)),Temp.Angle)
    set Temp.Proj = GetLastCreatedUnit()
    if Count == 0 then
        call TimerStart(Timer,0.02,true,function Action)
    endif
    set Pj[Count] = Temp
    set Count = Count + 1
endfunction

endlibrary
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top