Template [cJass] Chain Spell

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Or just make a [cJass] prefix.

I don't think that this will make everyone happy. Well maybe some cJass coder are forced to code in vJass if they want to submit sth., but imagine half of the "better" JASS coders start to code cJass and no vJass anymore. People using several systems will have to use cJass AND vJass in their maps which would just overcomplicate the whole thing particulary for the mapping beginners.

This cJass spell template uses a vJass system. cJass is easy to install and fully compatible. I don't see how it could overcomplicate anything. Beginners already have to install NewGen, this is just another click, it isn't a big deal. My spell even includes a link to the post containing the download, which would be a Good Idea™ to not overcomplicate things. When J4L sees this thread, he'll staple me to a train for sure...
 

Nestharus

o-o
Reaction score
84
This will hopefully start pointing you in the right direction.. I just put down the formatting, but I'm not going to recode the entire thing for you =P.

JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_types_priv.j"
include "cj_typesEx_priv.j"

library ChainSpell initializer init uses Recycle {
    public keyword Chain
    private player casterPlayer
    
    //distance formula variables
    private real distanceX1, distanceX2, distanceY1, distanceY2, distance
    
    private group array bouncedGroup; group bounceGroup = CreateGroup()
    private unit currentUnit, casterUnit
    private boolexpr bounceEnumeration
    private int bounceCount = 0
    private Chain array chainStack
    private int chainStackIndex = 0
    private int chainIndex = 0

    private bool Filt() {
        currentUnit = GetFilterUnit()

        if IsUnitEnemy(currentUnit, casterPlayer) && !IsUnitType(currentUnit,UNIT_TYPE_STRUCTURE) && !(IsUnitType(currentUnit, UNIT_TYPE_DEAD) || GetUnitTypeId(currentUnit) == 0) {
            /*if (!IsUnitInGroup(u,immune)) {
                //calculates distance between the picked unit and the last unit hit by the spell
                x2 = GetUnitX(u) - x1
                y2 = GetUnitY(u) - y1
                if (x2*x2 + y2*y2 < DISTANCE) { //is this unit the closest one in the group?
                    //sets DISTANCE to the distance to the closest unit
                    DISTANCE = x2*x2 + y2*y2
                    t = u
                }
            }*/
        }
        return false
    }
    
    public struct ChainProperties extends array {
        int numberOfBounces, spellId
        real bounceRange, bouncePeriod, damage
    }

    public struct Chain extends array {
        public delegate ChainProperties chainProperties
        
        void jumpTo(unit target) {
            /*UnitDamageTarget(this.caster,target,damage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_FIRE,null)
            bounceCount++ //jumping to a new unit, so add 1 to bounces.
            this.u = target //stores the target for the next bounce (comparing unit distances)
            GroupAddUnit(this.immune,target)*/
        }
        static thistype create(unit caster, unit target) {
            local thistype this
            if chainIndex != 0 { this = chainStack[--chainStackIndex] }
            else { this = ++chainIndex }
            .numberOfBounces = thistype(0).chainProperties.numberOfBounces
            /*D.caster = caster
            D.u = caster
            D.immune = Group.get()
            D.jumpTo(target)
            D.castingPlayer = GetOwningPlayer(caster)
            return D*/
            return this
        }

        /*private static thistype create(unit caster, unit target, int abilLevel){
            thistype D = thistype.allocate()
            D.bounces = 1
            D.maxBounces = abilLevel * 2//By default, bounces 2x the ability level
            D.caster = caster
            D.u = caster
            D.immune = Group.get()
            D.jumpTo(target)
            D.castingPlayer = GetOwningPlayer(caster)
            return D
        }*/

        /*void onDestroy(){
            Group.release(this.immune)
            this.immune = null
            this.caster = null
            this.u = null
        }*/
    }


    /*private bool Cond(){
        return GetSpellAbilityId() == SPELL_ID
    }

    private bool TimerCallback(){ //This function performs a bounce each PERIOD
    ChainTemplate D = KT_GetData()

        //Sets distance to square of bounce_range (efficiency)
        DISTANCE = BOUNCE_RANGE * BOUNCE_RANGE
        FILTER_PLAYER = D.castingPlayer
        x1 = GetUnitX(D.u)
        y1 = GetUnitY(D.u)
        immune = D.immune
        loop
            unit u; u = FirstOfGroup(immune)
            exitwhen u == null
            BJDebugMsg("|cffff0000" + GetUnitName(u) + "|r")
            GroupRemoveUnit(immune,u)
        endloop
        GroupEnumUnitsInRange(g,x1,y1,BOUNCE_RANGE,filterFunction)
        GroupClear(immune)
        g = null
        if (t == null) { //if there is no unit to jump to, end the spell
            t = null //just in case, heard that this was still needed anyway
            D.destroy()
            return true
        }
        D.jumpTo(t)
        if (D.bounces >= D.maxBounces) { //max bounces reached, end the spell.
            D.destroy()
            return true
        }
        return false
    }

    private void Act(){
        ChainTemplate D = ChainTemplate.create(GetTriggerUnit(),GetSpellTargetUnit())
        //ChainTemplate D = ChainTemplate.create(GetTriggerUnit(),GetSpellTargetUnit(), GetUnitAbilityLevel(GetTriggerUnit(),SPELL_ID))
        //uncomment the line above if using the ability level
        KT_Add(function TimerCallback,D, PERIOD)
    }*/

    private void init() {
        //printf(I2S(Test2.create(null, null).numberOfBounces))
    /*trigger t = CreateTrigger()
    int i = 0
    filterFunction = Condition(function Filt)

        loop {
            TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            exitwhen i >= 11
            i += 1
        }
        TriggerAddCondition(t,Condition(function Cond))
        TriggerAddAction(t,function Act)*/
    }
}
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I don't get what that formatting does. It seems a lot more complicated than what I want the spell to do. I just want people to slap it in, add whatever they want to the jumpTo method and the filter function, and be done with it.

Did some code updates and added a test map. It's staying in this form until I can get that pesky filter function to work.
 

Viikuna

No Marlo no game.
Reaction score
265
That cJass indeed looks quite strange.

I didnt really read the code too much, but at least your group usage sucks terribly.

( I really feel again like I should write a tutorial about group usage. I just hate writing tutorials,
cant you do it, Jesus4Lyf, or someone? )

Anyways, go to wc3c.net and get GroupUtils and learn how to use it.

Also you should use TriggerRegisterAnyUnitEventBJ, it does all that looping for you, so you dont have to type it yourself.

edit. Oh yea, read those other posts. You are using that Recycle thingy, and you just havent updated the first post. All right then. So immune group gets recycled, thats good, but you still should use somekind of ENUM_GROUP for GroupEnums.
 

Nestharus

o-o
Reaction score
84
Viikuna, actually looping through all players when they may not all be in the map is a bad practice =).
 

Viikuna

No Marlo no game.
Reaction score
265
Well, no one really cares about that, since it has no significant negative effects at all.


What matters is that one liner BJ looks better here than some loop thingy, that does exactly the same, but takes many lines.

Then again, you also probably need some system like SpellEvent, because Blizzards event responses that dont always work when you need them, so using system for event stuff is ultimately the best way to do it since it also looks pretty nice. ( You dont even have to use triggers directly, because function interfaces do that stuff for you )
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Have you seen this?

Just curious.

Nope.

Viikuna, I'll look into GroupUtils. I know the group usage isn't the best. I first tried to move the whole [ljass]FirstOfGroup[/ljass] into the filter, by using a global group and a global unit to transfer the data back to the main function:

[ljass]group immune = CreateGroup()[/ljass]
[ljass]unit closestUnit[/ljass]

JASS:
immune = D.immune
GroupEnumUnitsInRange(g,....)

//filter function
IsUnitInGroup(GetFilterUnit(),immune) == false //this ran into problems, would just keep bouncing to same unit.
closestUnit = GetFilterUnit() 

//back inside the main function

D.jumpTo(closestUnit)

//inside jumpTo

void jumpTo(unit u){
GroupAddUnit(this.immune,u)


It would work on the first jump, but never on the second jump. I'm assuming it was something with the global unit variable, but after a few hours of trying other things, I reverted back to the [ljass]FirstOfGroup[/ljass] loop. If you do make that group tutorial, please tell me about it. Otherwise any help will be accepted. The above is conceptual freehand.
 

Nestharus

o-o
Reaction score
84
And we really need some sort of cJASS vs vJASS/Zinc thread where this can properly be duked out. I'm seeing these disputes all over the place where they don't belong =).

Maybe I shall start one up : o.
 

Romek

Super Moderator
Reaction score
964
> Maybe I shall start one up : o.
No.

The staff is currently discussing what to do with all these new languages in the staff forum. We've somewhat come to a verdict. I'll place a sticky soon.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Could someone go through and delete all the "debate" posts? I haven't been able to solve the problem because my thread has been hijacked :( I've been trying to solve it a lot on my own, but to no avail.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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