• 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] What is wrong with this code?

Status
Not open for further replies.
Level 3
Joined
Aug 15, 2007
Messages
37
I am creating a TD in which a player gathers magic (gold), and uses mana wells to refine the magic into a desired type. There are six different types the wells can be, one being a Generic type which is what I am using in this example.

The effect I am going for is this:
The well regenerates mana by subtracting magic from the Magic Pool, with a cooldown time of 20 secs.
The wells spell can be autocast, or done manually
The ability is deactivated when magic reaches 0 or the wells mana is full
The wells max mana is increased by 1 every round

As of now, I am using invisibility as the base of the spell (I've tried others as well). And calling the trigger when a players gold is > 0. I have also just started using the CasterSystem.

The problem I am having is that the well won't cast the spell automatically when the trigger is called. If I manually cast the spell, it will though.
JASS:
function RegenMana_Actions takes nothing returns nothing
    local group manaWellsG = CreateGroup()
    local unit tempWell
    local player p = GetTriggerPlayer()

    call SetPlayerTechResearched(p,'R002',1)
    set manaWellsG = GetUnitsOfPlayerAndTypeId(p,'e002')
    
    loop
        set tempWell = FirstOfGroup(manaWellsG)
        exitwhen tempWell == null
        if ((GetUnitState(tempWell,UNIT_STATE_MAX_MANA) != GetUnitState(tempWell,UNIT_STATE_MANA)) and (GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD) > 0)) then
            call CasterCastAbility(GetOwningPlayer(tempWell),'Aivs',"invisibility",tempWell,true)
            call GroupRemoveUnit(manaWellsG,tempWell)
            //
            //set players gold - 1
            //set units mana + 1
            //wait length of spell cooldown and call trigger again
        endif 
    endloop
    // cleanup
endfunction

function InitTrig_RegenMana takes nothing returns nothing
  set gg_trg_RegenMana = CreateTrigger() 
    call TriggerRegisterPlayerStateEvent(gg_trg_RegenMana,Player(0),PLAYER_STATE_RESOURCE_GOLD,GREATER_THAN,0.)
    call TriggerAddAction(gg_trg_RegenMana,function RegenMana_Actions) 
endfunction
Some other things I've tried:
I have created a check var (using a leaderboard) that was incremented for every well that was selected in the group. This was inside the if statement, and it showed that the conditions were true and it was selecting the right units.
Any advice would be appreciated, thanks.
 
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
I edited your [code] tags into [code=jass] tags.

The code;

-You don't need to CreateGroup() if you use GetUnits..., only if you use GroupEnumUnits. However, you should use the latter because the former is a BJ.

-you forgot to destroy the group and all (or is that what you put cleanup there for?)

-Move GroupRemoveUnit out of the loop, otherwise you'll get thread crash funness. (or a chance to, anyways)

Also, why don't you just order the well to cast the spell? In the current case, you're making a dummy be created to cast it for you.

I'm guessing what you want is to target the well with invisibility. If so,

call IssueTargetOrder(tempWell,"invisibility",tempWell)
 
Status
Not open for further replies.
Top