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

[vJASS] (Zinc) Struct Data Passing into Separate Timers

Status
Not open for further replies.
Level 4
Joined
Mar 20, 2014
Messages
67
Hi all again,

Trying to create a spell that last for 45 seconds, then is created into a unit that gives vision

For some reason when I cast it again while there is one channeling (being created with just a special effect) it changes the TargetX and TargetY to the new cast in the already existing ones. It creates all the structs separately, as well as the timers (I checked the ID's), but everything in between any of the structs created is shared between them

Any help would be appreciated

JASS:
//! zinc

library SpawnTrap requires GameTimer, GT, xebasic, xepreload {
    private struct SpawnTrap {
        private static real delayTime;
        //Keeps track of the current time
        private static real currentTime;
        private static string spawningEffect;
        private static integer abilityId = 'A094';
        private static integer dummyId = 'o02F';
        private static real targetX;
        private static real targetY;
        private static real timerSpeed;
        private effect spawnEffect;
        private boolean dummyCreated = false;
        private unit dummyUnit;
        private GameTimer periodicTimer;
        private unit caster;
     
        private method setup() {
            //What's the delay before it actually starts working?
            this.delayTime = 45.0;
            //What effect to play while spawning the trap/mirror
            this.spawningEffect = "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl";
            //How fast we want to check
            this.timerSpeed = 1.00;
            //Set the currentTime to 0
            this.currentTime = 0;
        }
     
        //This function only exists to create the special effect every second
        //Once it's activated we just check to see if the unit is still alive
        private method tick() {
        BJDebugMsg(R2S(this.targetX) + " , " + R2S(this.targetY));
            if(this.currentTime >= this.delayTime && this.dummyCreated == false) {
                this.dummyUnit = CreateUnit(GetOwningPlayer(this.caster), this.dummyId, this.targetX, this.targetY, bj_UNIT_FACING);
                this.dummyCreated = true;
            } else if(this.dummyCreated) {
                if(!UnitAlive(this.dummyUnit)) {
                    KillUnit(this.dummyUnit);
                    UnitApplyTimedLife(this.dummyUnit, 'BTLF', 2);
                    this.destroy();
                }
            } else if(this.currentTime <= this.delayTime) {
                this.spawnEffect = AddSpecialEffect(this.spawningEffect, this.targetX, this.targetY);
                DestroyEffect(this.spawnEffect);
                this.currentTime += this.timerSpeed;
            }
        }
     
     
        private static method begin(unit u) -> thistype {
            thistype this = thistype.allocate();
            this.caster = u;
            this.setup();
            this.targetX = GetSpellTargetX();
            this.targetY = GetSpellTargetY();
            this.periodicTimer = GameTimer.newPeriodic(function(GameTimer t){
                thistype this = t.data();
                this.tick();
            }).start(this.timerSpeed);
            this.periodicTimer.setData(this);
            return this;
        }
     
        private static method onCast() {
            unit caster = GetSpellAbilityUnit();
            thistype.begin(caster);
        }
     
        public static method onSetup() {
            trigger t = CreateTrigger();
            thistype this = thistype.allocate();
            integer id = this.abilityId;
            this.destroy();
            GT_RegisterStartsEffectEvent(t, id);
            TriggerAddCondition(t, Condition(function() -> boolean {
                thistype.onCast();
                return false;
            }));
            XE_PreloadAbility(id);
        }
     
        private static method onInit() {
                thistype.onSetup();
        }
    }
}

//! endzinc
 
Last edited by a moderator:
Status
Not open for further replies.
Top