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

[General] [JASS] Refresh, doesn't work

Status
Not open for further replies.
Level 13
Joined
Aug 4, 2012
Messages
1,022
FIXED!
Here's the code, thanks to TriggerHappy & Bribe!

JASS:
scope refresh initializer chat
    globals
        private constant string string = "-refresh"
    endglobals
    private function pick takes nothing returns nothing
        local unit u
        call groupenumunitsofplayer(bj_lastcreatedgroup, gettriggerplayer(), null)
        loop
            set u = firstofgroup(bj_lastcreatedgroup)
            exitwhen u == null
            call groupremoveunit(bj_lastcreatedgroup, u)
            call setwidgetlife(u, 999999)
            call setunitstate(u, unit_state_mana, 999999)
            call unitresetcooldown(u)
        endloop
    endfunction
    private function chat takes nothing returns nothing
        local trigger t = createtrigger()
        local integer i = 12
        loop
            set i = i - 1
            call triggerregisterplayerchatevent(t, player(i), string, true)
            exitwhen i == 0
        endloop
        call triggeraddaction(t, function pick)
        set t = null
    endfunction
endscope


QUESTION:

JASS:
scope Refresh initializer Chat
    globals
        private constant string STRING = "-refresh"
        private constant player PLAYER = Player(0)
    endglobals
    private function Fresh takes nothing returns nothing
        call SetUnitLifePercentBJ(GetTriggerUnit(), 100)
        call SetUnitManaPercentBJ(GetTriggerUnit(), 100)
        call UnitResetCooldown(GetTriggerUnit())
    endfunction
    private function Pick takes nothing returns nothing
        call ForGroupBJ(GetUnitsOfPlayerAll(PLAYER), function Fresh)
    endfunction
    private function Chat takes nothing returns nothing
        call TriggerRegisterPlayerChatEvent(gg_trg_Refresh, PLAYER, STRING, true)
        call TriggerAddAction(gg_trg_Refresh, function Pick)
    endfunction
endscope
Those code was made by ME :D :D
It's got no syntax error!!

but it doesn't work
Here's what I want with that code:
1. Player enters chat "-refresh"
2. All unit owned by chatting player will be reseted it cooldowns, hp & mana
 
Last edited:
gg_trg_Refresh is a generated variable, are you sure it's created/initialized?

Using a local trigger would probably be best anyway, so this would work:

JASS:
scope Refresh initializer Chat

    globals
        private constant string STRING = "-refresh"
        private constant player PLAYER = Player(0)
    endglobals
    
    private function Pick takes nothing returns boolean
        local group g = CreateGroup()
        local unit u
        
        call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
        
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            
            call SetWidgetLife(u, 999999)
            call SetUnitState(u, UNIT_STATE_MANA, 999999)
            call UnitResetCooldown(u)

            call GroupRemoveUnit(g, u)
        endloop
        
        call DestroyGroup(g)
        set g = null
        
        return false
    endfunction
    
    private function Chat takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, PLAYER, STRING, true)
        call TriggerAddCondition(t, function Pick)
    endfunction
endscope
 
Last edited:
Level 13
Joined
Aug 4, 2012
Messages
1,022
gg_trg_Refresh is a generated variable, are you sure it's created/initialized?

Using a local trigger would probably be best anyway, so this would work:

JASS:
scope Refresh initializer Chat

    globals
        private constant string STRING = "-refresh"
        private constant player PLAYER = Player(0)
    endglobals
    
    private function Pick takes nothing returns boolean
        local group g = CreateGroup()
        local unit u
        
        call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
        
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            
            call SetWidgetLife(u, 999999)
            call SetUnitState(u, UNIT_STATE_MANA, 999999)
            call UnitResetCooldown(u)
        endloop
        
        call DestroyGroup(g)
        set g = null
        
        return false
    endfunction
    
    private function Chat takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, PLAYER, STRING, true)
        call TriggerAddCondition(t, function Pick)
    endfunction
endscope

wow thanks, so gg_trg is just the variable, I didn't know it until now hehe thanks :D :D
well, gg_trg is my Trigger name :D :D

Change GetTriggerUnit to GetEnumUnit. You also need to create the trigger before it can have any events. Also, this only works for Player 0 as it doesn't have any events for the other players.

How to make it Chatting player??

EDIT:


Umm, TriggerHappy
It didn't work :/ :/
JASS:
scope Refresh initializer Chat
    globals
        private constant string STRING = "-refresh"
        private constant player PLAYER = Player(0)
    endglobals
    private function Fresh takes nothing returns boolean
        local group GROUP = CreateGroup()
        local unit UNITS
        call GroupEnumUnitsOfPlayer(GROUP, PLAYER, null)
        loop
            set UNITS = FirstOfGroup(GROUP)
            exitwhen UNITS == null
            call SetWidgetLife(UNITS, 9999999)
            call SetUnitState(UNITS, UNIT_STATE_MANA, 9999999)
            call UnitResetCooldown(UNITS)
        endloop
        call DestroyGroup(GROUP)
        set GROUP = null
        return false
    endfunction
    private function Chat takes nothing returns nothing
        local trigger THIS = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(THIS, PLAYER, STRING, true)
        call TriggerAddCondition(THIS, function Fresh)
    endfunction
endscope
 
wow thanks, so gg_trg is just the variable, I didn't know it until now hehe thanks :D :D
well, gg_trg is my Trigger name :D :D

Yeah when you create a new trigger in the editor it will generate a global variable for you.

This is normally initialized inside the generated InitTrig function and it would look like set gg_trg_Refresh = CreateTrigger( )
 
Here is what TriggerHappy made, but fixed several issues with it and added support for all human players.

JASS:
scope Refresh initializer Chat

    globals
        private constant string STRING = "-refresh"
    endglobals
    
    private function Pick takes nothing returns nothing
        local unit u
        
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, GetTriggerPlayer(), null)
        
        loop
            set u = FirstOfGroup(bj_lastCreatedGroup)
            exitwhen u == null
            call GroupRemoveUnit(bj_lastCreatedGroup, u)
            
            call SetWidgetLife(u, 999999)
            call SetUnitState(u, UNIT_STATE_MANA, 999999)
            call UnitResetCooldown(u)
        endloop
    endfunction
    
    private function Chat takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 12
        loop
            set i = i - 1
            call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
            exitwhen i == 0
        endloop
        call TriggerAddAction(t, function Pick)
        set t = null
    endfunction
endscope
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
here is what triggerhappy made, but fixed several issues with it and added support for all human players.

JASS:
scope refresh initializer chat

    globals
        private constant string string = "-refresh"
    endglobals
    
    private function pick takes nothing returns nothing
        local unit u
        
        call groupenumunitsofplayer(bj_lastcreatedgroup, gettriggerplayer(), null)
        
        loop
            set u = firstofgroup(bj_lastcreatedgroup)
            exitwhen u == null
            call groupremoveunit(bj_lastcreatedgroup, u)
            
            call setwidgetlife(u, 999999)
            call setunitstate(u, unit_state_mana, 999999)
            call unitresetcooldown(u)
        endloop
    endfunction
    
    private function chat takes nothing returns nothing
        local trigger t = createtrigger()
        local integer i = 12
        loop
            set i = i - 1
            call triggerregisterplayerchatevent(t, player(i), string, true)
            exitwhen i == 0
        endloop
        call triggeraddaction(t, function pick)
        set t = null
    endfunction
endscope

THANKS!! Works perfectly :D :D
 
Level 19
Joined
Dec 12, 2010
Messages
2,069
JASS:
loop
            set u = firstofgroup(bj_lastcreatedgroup)
            exitwhen u == null
            call groupremoveunit(bj_lastcreatedgroup, u)
            if GetHandleId(u)>0 and GetWidgetLife(u)>0.5 and GetUnitAbilityLevel(u,'Aloc')==0 then
            call setwidgetlife(u, 999999)
            call setunitstate(u, unit_state_mana, 999999)
            call unitresetcooldown(u)
endif
        endloop
 
JASS:
scope Refresh initializer Chat

    globals
        private constant string STRING = "-refresh"
    endglobals
    
    private function Pick takes nothing returns nothing
        local unit u
        
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, GetTriggerPlayer(), null)
        
        loop
            set u = FirstOfGroup(bj_lastCreatedGroup)
            exitwhen u == null
            call GroupRemoveUnit(bj_lastCreatedGroup, u)
            
            if GetUnitAbilityLevel(u, 'Aloc') == 0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                call SetWidgetLife(u, 999999)
                call SetUnitState(u, UNIT_STATE_MANA, 999999)
                call UnitResetCooldown(u)
            endif
        endloop
    endfunction
    
    private function Chat takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 12
        loop
            set i = i - 1
            call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
            exitwhen i == 0
        endloop
        call TriggerAddAction(t, function Pick)
        set t = null
    endfunction
endscope
 
those flag isn't enough to say if the unit is dead for sure. it may be non-existant or reincarnating

It is impossible to enumerate a removed ir decayed unit in a group. You only need that check if the unit was removed from the game after it was removed from the group. Not only that, but removed units will result "null" when using FirstOfGroup in those cases, which is why Captain Griffon added GroupRefresh.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
those flag isn't enough to say if the unit is dead for sure. it may be non-existant or reincarnating

JASS:
loop
            set u = firstofgroup(bj_lastcreatedgroup)
            exitwhen u == null
            call groupremoveunit(bj_lastcreatedgroup, u)
            if GetHandleId(u)>0 and GetWidgetLife(u)>0.5 and GetUnitAbilityLevel(u,'Aloc')==0 then
            call setwidgetlife(u, 999999)
            call setunitstate(u, unit_state_mana, 999999)
            call unitresetcooldown(u)
endif
        endloop

JASS:
scope Refresh initializer Chat

    globals
        private constant string STRING = "-refresh"
    endglobals
    
    private function Pick takes nothing returns nothing
        local unit u
        
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, GetTriggerPlayer(), null)
        
        loop
            set u = FirstOfGroup(bj_lastCreatedGroup)
            exitwhen u == null
            call GroupRemoveUnit(bj_lastCreatedGroup, u)
            
            if GetUnitAbilityLevel(u, 'Aloc') == 0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                call SetWidgetLife(u, 999999)
                call SetUnitState(u, UNIT_STATE_MANA, 999999)
                call UnitResetCooldown(u)
            endif
        endloop
    endfunction
    
    private function Chat takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 12
        loop
            set i = i - 1
            call TriggerRegisterPlayerChatEvent(t, Player(i), STRING, true)
            exitwhen i == 0
        endloop
        call TriggerAddAction(t, function Pick)
        set t = null
    endfunction
endscope

Which one I should choose??
 
Status
Not open for further replies.
Top