1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  4. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[System] Item Removal System

Discussion in 'Graveyard' started by deathismyfriend, Mar 19, 2013.

  1. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    Updated and moved to spell section.
     
    Last edited: Sep 3, 2014
  2. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Your function names are too vauge.

    Your coding is JASS-bourne,meaning you code like in JASS. We are in vJASS now bro.

    It would be better if you use structs and this:http://www.hiveworkshop.com/forums/jass-resources-412/repo-comment-headers-192184/

    I suggest you using Table,so that it would not waste hash tables.

    Also,we don't use any TriggerAddAction,it always creates new thread,so we only use TriggerAddCondition because its much faster and doesn't create new thread.
     
  3. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    I didn't know tht about triggeraddaction ill have to change them over to triggeraddcondition. And what do u mean by my function names r 2 vague ? I don't like big function names. As for using table I haven't used anything anyone else created so I'm not sure about using table. I may change it so it can use it but 255 has tables is a lot to go through lol.

    I didn't think structs would matter to use them here. Not: I have not used structs much at all so I do not know a lot of stuff about there efficiency in coding and everything like tht. I hope to be able to sit down and learn them soon.

    I like the commenting thing I have up top short and to the point. Easy to find how to install use and so on. I will take a look at the comment link tht u gave me and I'll see if I like it better I will change it.
     
    Last edited: Apr 7, 2013
  4. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    They are too simple(e.g. Actions)

    I suggested you to use Table because there are so many resources that uses hashtables
     
  5. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    It would be nice to be able to pause the timer, for example during cinematics.
     
  6. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    ^ Its pauses timer in the code right?
     
  7. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    There could be pauseItemDecay and resumeItemDecay functions that can be accessed from outside the library.
     
  8. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Oh now i get it
     
  9. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    Being able to pause the timer makes sense tht should be easy enough to do. What do u mean by pauseItemDecay and resumeItemDecay ? We're u just suggesting names to use for pausing the timer ?

    On the function names im not sure ill ever change them I like them short it's easy to understand.

    And since This is a public resource I think I will switch if over so it uses table.

    Edit: I hope to be able to add the pause timer option and to make it useable with table when I get out of work. Thx for your suggestions plz keep them coming lol
     
    Last edited: Mar 19, 2013
  10. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    added the pause item timer function. lets u pause and unpause timer when u want.

    also trying to get it to work w Table by bribe. i have to learn structs tho. if anyone could tell me how to assign items like i did above and how to use the condition like i did above to see if it is in Table ? ik how to create a Table array ( i think thts the one i need ) thx in advance
     
  11. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    if b then

    and don't destroy the timer.
     
  12. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ive been told do not pause repeating timers. if u pause them destroy them and remake them. what should i do then ?

    edit: i think i got the table working right

    edit2: i have noticed a problem tho. a pre created unit tht drops item on death does not trigger the player unit drops item event. gonna have to fix this b4 it becomes a viable system. any ideas ? i was think of every 1 second i can enumerate all items in map but id rather not do tht since u would have to set a boolean if u dont want tht item to be removed ( quest item ). all items tht were created in the editor would be removed also if i do it this way

    i think i found a solution when a unit dies i can enumerate items in area around were the unit died. mybe this will work?
     
    Last edited: Mar 19, 2013
  13. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    If you pause a periodic timer and then resume it, it won't be periodic anymore. I think if you restart it again as a periodic, it will work ok.
     
  14. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ooo ok i thought tht would cause a leak thx
     
  15. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,905
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Seriously, this system is far too inefficient for a public resource, for several reasons:

    1) Enuming all items in map area each timer interval AND looping through an array of all stored items at the same time just to decrease the item counter?
    Use an item indexing system instead and use the event fired on registering the item instead. Most item indexers have all possible ways to create items on ground covered so you can avoid that enum.

    2) You do not need to loop through the arrays of items every time. Instead, sort the items in your array depending on the time remaining with a linked list (that way you only need to loop through the items that decayed). When an item timer is paused, remove that item from the linked list and add it back in as soon as the timer is resumed. That way you only need to loop through all the items when an item is created or removed.

    3) Your system does not have any protection against killing or removing items. Killed or removed items should be cleared from the system automaticly

    4) You can avoid the search loop in your pickup trigger by having an array storing the current position in the item table (well, in this case, speed doesn't matter that much, I think, so it should be okay to loop here).

    5) Improve the structure of your code to improve readability, especially the conditions.
     
  16. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    Well tht should help w a couple of things only problem I have is when u kill a unit and the unit drops an item the event unit drops item doesn't fire for them. I meant to have another event tht fires when a unit does then it will enum items. I forgot to out tht in and remove the one tht enum items every second.

    When an item gets killed sold or removed by some other means definitely has to be covered in this system. To be honest I just forgot about tht lol thx

    I only have one item timer. When the timer goes off it just adds a +1 to each item in the array. Tht way when the item array hits ur specific time u want the items to remove at then the item is removed.

    Also can u check and see I'm not sure I'm using table the right way. When I enum items its supposed to check the isnotintable condition the one w enum items. It does work when first adding the item to table but when enumerating through items it still enumerates the items tht r in table. Ill have to check all of these suggestions after work. Thx for the good suggestions. I'm not sure if I will use indexer or anything like tht but I will check what's the best way to do it and go from there.

    also next time u comment on something plz say the function name w the comment.
     
    Last edited: Mar 20, 2013
  17. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    added some new stuff and i plane on making this use structs but i have to learn how to use structs first. hopefully ill have enough time to learn them soon and then implement it into this. if anyone wants to show me how i should do the structs feel free. all the help and criticism is appreciated.
     
  18. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    redid the code to use structs may have some bugs. i did not have time to test this so if anyone sees any screw ups plz tell me
     
  19. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,003
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Jesus, will someone ever make an Item Indexer and post it in the JASS section? :(

    edit

    Code (vJASS):
    struct Items extends array
    function PauseItemTimer takes boolean b returns nothing
    function DoNotRemoveItem takes item itm, boolean b returns nothing
    function RemoveItemWithDiffTime takes item i, integer T returns nothing


    Honestly, the API isn't very good :/

    DoNotRemoveItem
    isn't a proper function name in any programming/scripting language.

    struct Items
    is too vague. The name should be referring to some sort of recycler or recycling unit.
    Something like
    ItemSweeper
    or
    MapItemCleaner
    or whatever. Anything specific to this library would be good.

    PauseItemTimer
    is also a pretty bad name as it can be referring to any timer that deals with items.

    You have 2 options here:
    • Move the functions to the body of the struct so you can shorten the names after beefing up the struct name.
    • Beef up the function names so that they fit into the library. Also, follow everyone's naming conventions here :v.

    Personally, I would just put them in the struct because coming up for a good name for the second function is really difficult.

    Code (vJASS):
    struct ItemSweeper extends array
        static method start takes nothing returns nothing
        static method pause takes nothing returns nothing
        static method resume takes nothing returns nothing

        static method isPaused takes nothing returns boolean
        static method isRunning takes nothing returns boolean

        static method protectItem takes item it returns nothing
        static method unprotectItem takes item it returns nothing
        static method isItemProtected takes item it returns boolean

        static method setItemExpiration takes item it, real time returns nothing
        static method getItemExpiration takes item it returns real
    endstruct
     
    Last edited: Mar 26, 2013
  20. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ok tht makes sense. hopefully i can change them like tht soon. i just started learning structs so i think i need to learn a little more about them. hopefully trying to make this a good system will do tht for me. it may take a while since i dont have much time to work on this stuff atm but hopefully soon i can do it. thx for ur suggestions
     
    Last edited: Mar 25, 2013