wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 10-30-2009, 01:01 PM   #1
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default 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
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 10-30-2009, 01:27 PM   #2
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,075

Submissions (19)

Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

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.
__________________

Last edited by Anitarf : 10-30-2009 at 01:29 PM.
Anitarf is offline   Reply With Quote
Old 10-30-2009, 01:33 PM   #3
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

bleh seems I fixed the wrong line. Changes done.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-30-2009, 01:49 PM   #4
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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)
__________________
Rising_Dusk is offline   Reply With Quote
Old 10-30-2009, 01:51 PM   #5
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

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.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-30-2009, 01:54 PM   #6
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 10-30-2009, 02:04 PM   #7
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

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.
grim001 is offline   Reply With Quote
Old 10-30-2009, 02:25 PM   #8
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

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.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-30-2009, 02:36 PM   #9
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

That'll do. I guess this can be approved right away, then.
__________________
Rising_Dusk is offline   Reply With Quote
Old 10-30-2009, 03:06 PM   #10
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

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
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-30-2009, 03:25 PM   #11
D3zmodos
User
 
Join Date: Feb 2009
Posts: 13

D3zmodos has little to show at this moment (8)

Default

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
D3zmodos is offline   Reply With Quote
Old 10-30-2009, 03:27 PM   #12
Deaod
User
 
Join Date: Jan 2007
Posts: 541

Submissions (11)

Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)

Send a message via ICQ to Deaod Send a message via MSN to Deaod
Default

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.
__________________
Deaod is offline   Reply With Quote
Old 10-30-2009, 03:45 PM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

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.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 11-01-2009, 02:07 PM   #14
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

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.

Last edited by Troll-Brain : 11-01-2009 at 02:12 PM.
Troll-Brain is offline   Reply With Quote
Old 11-01-2009, 02:17 PM   #15
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

I do not support TriggerSleepAction, even if it is 'fine.'
__________________
Rising_Dusk is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 01:50 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

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