Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Scripts (http://www.wc3c.net/forumdisplay.php?f=737)
-   -   PowerupSentinel (http://www.wc3c.net/showthread.php?t=108065)

Vexorian 10-30-2009 01:01 PM

PowerupSentinel
 
Err, ok, read the description comment.
Requires jasshelper 0.A.2.ish, better just get 0.A.2.6 or later.

If you paste it on newgen pack, use the //! zinc...endzinc stuff, when you paste it on a .zn file, remove the //! zinc and //! endzinc lines.

Err, ok, read the description comment.
Requires jasshelper 0.A.2.ish, better just get 0.A.2.6 or later.

If you paste it on newgen pack, use the //! zinc...endzinc stuff, when you paste it on a .zn file, remove the //! zinc and //! endzinc lines.

Updated to use some suggestions by Troll Brain.
Collapse Zinc:
//! zinc
/*
*  PowerupSentinel
*  ------------
*    Placing this library in your map will automatically fix all rune/tome
* memory leaks in your map.
*
*    Powerup items don't get removed automatically by the game, they instead
* just leave a small item in the map, this caused memory leaks but - worse -
* it also makes areas of your map where a lot of tomes have been used lag a lot.
*
*/
library PowerupSentinel
{
    function onInit(){
        trigger t = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DROP_ITEM);
        TriggerAddCondition(t, function()->boolean {
            if (GetWidgetLife(GetManipulatedItem())==0) {
                RemoveItem(GetManipulatedItem());
            }
            return false;
        });
    }
    
}
//! endzinc

Anitarf 10-30-2009 01:27 PM

You should probably remove that debug message and actually remove the item instead.
Also, since this is a new thing (zinc, I presume) you should probably mention the version of JassHelper that it requires in the documentation.

Vexorian 10-30-2009 01:33 PM

bleh seems I fixed the wrong line. Changes done.

Rising_Dusk 10-30-2009 01:49 PM

Well, this is cool, but I am a purist and don't want any C syntax in my map, so I guess I won't use it. I do so hate how unreadable that stuff is. Anyways, it looks fine, I guess, but I think it should be named TomeSentinel. The name ItemSentinel makes it sound like it does stuff to more types of items than just powerups. (Could also call it PowerupSentinel, but that doesn't sound as cool)

Vexorian 10-30-2009 01:51 PM

It is not like you'll have to use the syntax at all. But you can make jasshelper convert this into a vJass library if you want.

Except PowerupSentinel does not sound cool.

Rising_Dusk 10-30-2009 01:54 PM

That is why I suggested TomeSentinel, 'cuz it does sound cool.
Quote:

Originally Posted by Vexorian
It is not like you'll have to use the syntax at all. But you can make jasshelper convert this into a vJass library if you want.

I suppose I could do that.

grim001 10-30-2009 02:04 PM

I think TomeSentinel sounds cooler and communicates what it does more aptly.

I see you are really abusing anonymous functions. I think the code looks pretty neat.

Vexorian 10-30-2009 02:25 PM

I think someone needs to draw a line as to when to use anonymous functions, they are getting out of control.

Hmnn, in my case I use more runes than tomes. How about BlizzItemLeakMessupSentinel?

Ok, I'll call it PowerupSentinel, correctness over coolness. The name of the library does not matter much since no code needs to actually call it anyway.

I should probably make a GUI thing to make that zinc2vJass conversion easy to use for nutjobspurists.

Rising_Dusk 10-30-2009 02:36 PM

That'll do. I guess this can be approved right away, then.

Vexorian 10-30-2009 03:06 PM

hmnn this is what jasshelper generates, not sure which one is the least readable...

Collapse JASS:
/*
*  PowerupSentinel
*  ------------
*    Placing this library in your map will automatically fix all rune/tome
* memory leaks in your map.
*
*    Powerup items don't get removed automatically by the game, they instead
* just leave a small item in the map, this caused memory leaks but - worse -
* it also makes areas of your map where a lot of tomes have been used lag a lot.
*
*/

library PowerupSentinel initializer onInit 
    private keyword tic
    private keyword queue
    private keyword qn
    private keyword onInit
    globals
    private timer tic
    endglobals
    globals
    private item  array queue
    endglobals
    globals
    private integer qn=0
    endglobals
            private function anon__1 takes nothing returns nothing
                local integer i=0
                set i=0
                loop
                exitwhen (i>=qn)
                    if (GetWidgetLife(queue[i])<0.405)then
                        call RemoveItem(queue[i])
                    endif
                    set queue[i]=null
                set i = i+1
                endloop
                set qn=0
            endfunction
        private function anon__0 takes nothing returns boolean
            set queue[qn]=GetManipulatedItem()
            set qn=qn+1
            call TimerStart(tic,0.0,false,function anon__1)
            return false
        endfunction
    private function onInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        set tic=CreateTimer()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
        call TriggerAddCondition(t,function anon__0)
    endfunction
endlibrary

D3zmodos 10-30-2009 03:25 PM

I did a quick conversion, for those who dont want to do it themselves and dont like zinc:

Collapse JASS:
library PowerupSentinel initializer onInit
//* ============================================================================
//*  PowerupSentinel by Vexorian
//*  ------------
//*    Placing this library in your map will automatically fix all rune/tome
//* memory leaks in your map.
//*
//*    Powerup items don't get removed automatically by the game, they instead
//*    just leave a small item in the map, this causes memory leaks but - worse -
//*    it also makes areas of your map where a lot of tomes have been used lag.
//*
//* ===========================================================================

globals
    private timer tic
    private item  array queue
    private integer qn=0
endglobals
    
    private function Callback takes nothing returns nothing
        local integer i=0
        loop
            exitwhen ( i >= qn )
            if ( GetWidgetLife(queue[i]) < 0.405 ) then
                call RemoveItem(queue[i])
            endif
            set queue[i]=null
            set i=i + 1
        endloop
        set qn=0
    endfunction
            
    private function CleanCall takes nothing returns boolean
        set queue[qn]=GetManipulatedItem()
        set qn=qn + 1
        call TimerStart(tic, 0.0, false, function Callback)
        return false
    endfunction
        
    private function onInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer i = 0
        set tic=CreateTimer()
        loop
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function CleanCall))
    endfunction

    endlibrary

Deaod 10-30-2009 03:27 PM

Why do you set qn to 0 at the end?

Imagine a player buys a tome of levelup and is already on max level. The tome will stay on the ground and leak at a later point.

Id suggest you just recycle indices.

Vexorian 10-30-2009 03:45 PM

Quote:

Imagine a player buys a tome of levelup and is already on max level. The tome will stay on the ground and leak at a later point.
So the tome is in the ground, next time a unit picks up this item it will trigger PICKUP_ITEM again.

Troll-Brain 11-01-2009 02:07 PM

Completely untested but instead of add all acquired items you could simply detect when an item is used, and use the native IsItemPowerup.

If the player want to deal with the item on his use, you would need to use a short wait (TriggerSleepAction(0) seems fine here).
In order to remove the item after a short time, or the user could have a removed item, when the use item event fire on one of his trigger.

Rising_Dusk 11-01-2009 02:17 PM

I do not support TriggerSleepAction, even if it is 'fine.'


All times are GMT. The time now is 10:42 PM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services