Name | Type | is_array | initial_value |
aoeIndex | integer | No | |
aoeTime | integer | Yes | |
aoeUnits | unit | Yes | |
ItemRemovalHashtable | hashtable | No | |
ItemRemovalItemRect | rect | No | |
ItemRemovalTime | real | No | |
lifeGroupCounter | integer | No | |
randomPoint | location | No | |
subStr | string | No | |
tempGroup | group | No | |
tempIncrease | integer | No | |
tempInt | integer | No | |
tempPoint | location | No | |
tempString | string | No | |
tempUnit | unit | No | |
unitLifeGroup | group | No | |
unitManaGroup | group | No | |
unitManaGroupBoolean | boolean | No | |
urAbility | abilcode | No | |
urReg | rect | No | |
urUnit | unit | No |
//TESH.scrollpos=139
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=13
//TESH.alwaysfold=0
library Alloc
module Alloc
private static integer array recycler
private static integer instanceCount = 0
debug private static boolean enabled = true
static method allocate takes nothing returns thistype
local thistype this = recycler[0]
debug if (not enabled) then
debug return 1/0
debug endif
if (this == 0) then
debug if (instanceCount == 8191) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"OVERFLOW")
debug set enabled = false
debug set this = 1/0
debug endif
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
debug set recycler[this] = -1
return this
endmethod
method deallocate takes nothing returns nothing
debug if (not enabled) then
debug set this = 1/0
debug endif
debug if (recycler[this] != -1) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"ATTEMPT TO DEALLOCATE NULL STRUCT INSTANCE")
debug set enabled = false
debug set this = 1/0
debug endif
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library UnitItemDrops /* by Deathismyfriend version 1.0.6.5
================================ Requirements =================================
Requires JNGP
*/uses Table, /* [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url] by bribe
* Alloc * [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-alloc-alternative-221493/[/url] by nestharus
*************************************************************************************
*
* Used to easily make drop tables for item drops when unit dies.
*
************************************************************************************
*
* Installing
* STEP 1: Install JNGP first if you dont have JNGP.
* STEP 2: Install Table by bribe the link is above.
* STEP 3: Install Alloc by nestharus the link is above. You may be able to use some other alloc systems.
* STEP 4: Copy and paste this library to your map.
*
************************************************************************************
*
* Description
* -----------------------
* This is a very easy item drop system.
* Allows for multi-Chance dropping of items w a simple method call after u call the create method.
*
* Capabilities
* -----------------------
* Allows the user to easily create an item recipe.
* - Easily create item tables for units that drop on percent chance.
* - You can add as many items as wanted for each table for the corresponding unit type id.
*
******************************************************************************************************************************************************************************************************
/ ******************************************************************************************************************************************************************************************************
/ *
/ * CREATORS / DESTRUCTORS
/ * ----------------------
/ * struct itemDropSystem extends array
/ *
/ * static method createForType takes integer unitTypeId returns thistype
/ * - this is what you need to start an item drop table.
/ * - Below is how u add the items to the table
/ *
/ * static method createForUnit takes unit u returns thistype
/ * - this is used for creating item tables for specific units do not call the create function for these units.
/ *
/ * static method destroy takes nothing returns nothing
/ * - to destroy an item drop table for the unit type id
/ *
/ *
/ * FIELDS
/ * ------
/ * method addItem takes integer itemId, integer percent returns nothing
/ * - this is how u add items to the unit drop table.
/ * - You add up to 5 items at a time
/ *
/ * method addZeroDropWeight takes integer weight returns nothing
/ * - this is how u add a weight for no item drops.
/ *
/ * method setDropCount takes integer multi returns nothing
/ * - allows you to change the multi drop.
/ * - Set multidrop integer to 2 or higher for multidrop chance
/ *
/ * method getDropCount takes nothing returns integer
/ * - returns the multi drop integer that u have set.
/ *
/ * static method getDataTable takes integer id returns thistype
/ * - this returns the item Table so u can easily add items to the table or destroy it if u want
/ *
/ ********************************************************************************************************************************/
globals
private Table unitTypeTable
private Table unitIdTable
private Table itemDropTable
private Table itemIdTable
endglobals
struct ItemDropSystem extends array
implement Alloc
private integer index
private integer arrayI
private integer checkPercent
private integer weight
private integer ttlWeight
private integer unitTypeId
private integer multiDrop
private boolean specificUnit
private method setValues takes nothing returns nothing
set this.multiDrop = 1
set this.index = 0
set this.weight = 0
endmethod
static method createForType takes integer unitTypeId returns thistype
local thistype this = thistype.allocate()
set this.unitTypeId = unitTypeId
set unitTypeTable[ unitTypeId] = this
set this.specificUnit = false
call this.setValues()
return this
endmethod
static method createForUnit takes unit u returns thistype
local thistype this = thistype.allocate()
local integer id = GetHandleId( u)
set this.unitTypeId = id
set unitIdTable[ this.unitTypeId] = this
set this.specificUnit = true
call this.setValues()
return this
endmethod
method setDropCount takes integer multi returns nothing
set this.multiDrop = multi
endmethod
method getDropCount takes nothing returns integer
return this.multiDrop
endmethod
static method getDataTable takes integer id returns thistype
if unitTypeTable.has( id) then
return unitTypeTable[ id]
endif
return unitIdTable[ id]
endmethod
method addZeroDropWeight takes integer weight returns nothing
set this.index = this.index + 1
set this.ttlWeight = this.ttlWeight + weight
set itemIdTable[this][index] = 100000
set itemDropTable[this][100000] = this.ttlWeight
endmethod
method addItem takes integer itemId, integer weight returns nothing
set this.index = this.index + 1
set this.ttlWeight = this.ttlWeight + weight
set itemIdTable[this][index] = itemId
set itemDropTable[this][itemId] = this.ttlWeight
endmethod
private static method deathEvent takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( GetTriggerUnit())
local thistype this
local integer r
local real x = GetUnitX( u)
local real y = GetUnitY( u)
local integer array weights
local integer L = 1
local integer L1 = 1
local integer end = 0
if unitTypeTable.has( id) then
set this = unitTypeTable[ id]
elseif unitIdTable.has( GetHandleId( u)) then
set this = unitIdTable[ GetHandleId( u)]
endif
if this != 0 then
loop
exitwhen L > this.index
set weights[L] = itemDropTable[this][itemIdTable[this][L]]
set end = end + 1
set L = L + 1
endloop
set L = 1
loop
exitwhen L > this.multiDrop
set r = GetRandomInt( 1, this.ttlWeight)
loop
exitwhen L1 > end
if r < weights[L1] then
call CreateItem( itemIdTable[this][L1], x, y)
set u = null
return false
endif
set L1 = L1 + 1
endloop
set L = L + 1
endloop
endif
set u = null
return false
endmethod
method destroy takes nothing returns nothing
if specificUnit then
call unitIdTable.remove( this.unitTypeId)
else
call unitTypeTable.remove( this.unitTypeId)
endif
call this.deallocate()
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set unitTypeTable = Table.create()
set unitIdTable = Table.create()
set itemIdTable = TableArray[0x2000]
set itemDropTable = TableArray[0x2000]
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition( t, function thistype.deathEvent)
set t = null
endmethod
endstruct
endlibrary
/*
[HIDDEN="Changelog"]
version 1.0.6.5
[INDENT]*changed the API
*changed the addItem function to only take one item and the weight of that item
*added a getDropCount which returns the multidrop integer
*changed the create method names to make it easier to understand
*changed it over to a weight taking system instead of percents
*added a method for no item drop w weights[/INDENT]
version 1.0.6.0
[INDENT]*got rid of tsa
*Changed the system to increase speed[/INDENT]
version 1.0.5.3
[INDENT]*Added protection from op limit w TSA. ( opend to better options ?)
*Can now change or add items to an old item Table that was previously made
just call the create function u used for that unit also allows you to change the multichance w same time
*Be careful when using this as the item Table keeps the old items percent that were already stored
if percent of drops added to 100 b4 you will have to destroy then recreate the item Table[/INDENT]
version 1.0.5.2
[INDENT]*fixed a mistype which caused unwanted results[/INDENT]
version 1.0.5.1
[INDENT]*allows for up to 400 item Tables now [/INDENT]
version 1.0.5.0
[INDENT]*allows you to create item drops based on preplaced / specific units[/INDENT]
version 1.0.0.0
[INDENT]*first version released[/INDENT]
[/HIDDEN]
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope ItemTables initializer init
globals
private integer L = 0
endglobals
function addToTable takes nothing returns nothing
local ItemDropSystem data = ItemDropSystem.createForType( 'hpea')
call data.addItem( 'afac', 20)
call data.addItem( 'ratc', 20)
call data.addItem( 'rat6', 20)
call data.addItem( 'rat9', 20)
call data.addItem( 'rst1', 100)
endfunction
//===========================================================================
function init takes nothing returns nothing
local trigger t = CreateTrigger()
local timer t1 = CreateTimer()
call TriggerRegisterTimerEvent( t, 0.00, false)
call TriggerAddAction( t, function addToTable)
set t = null
endfunction
endscope
//TESH.scrollpos=70
//TESH.alwaysfold=0
library ItemRemoval /* version 3.0.0.2
================================ Requirements =================================
Requires JNGP
*/uses Table, /* [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url] by bribe
================================ Installing =================================
STEP 1: Install JNGP first if you dont have JNGP.
STEP 2: Install Table by bribe the link is above.
STEP 3: Install Alloc by nestharus the link is above. You may be able to use some other alloc systems.
STEP 4: Create a rect and save it in the method below.
STEP 5: Copy and paste this library to your map.
================================== How to use ===================================================
Items that are created right after a unit dies whether its
through triggers( only works if item is placed at the position of the unit that died)
or the item table are automatically stored.
Items that are created through triggers that you want protected need to be added immediately using the protectItem method.
Alternately u can add items to be removed manually but it is not needed unless u create an item through triggers and
do not place that item near a dead unit. These types of items should be added using the additem method.
================================== API ===================================================
struct MapItemCleanup
static method addItemToRemove takes item itm, real time returns nothing
This function allows the user to add an item that they made using triggers or an item that was protected previously.
static method protectItem takes item itm returns nothing
This function allows the user to protect a specific item from being removed by this system.
static method deProtectItem takes item itm returns nothing
This function allows the user to stop protecting a previoulsy protected item from being removed by this system.
static method isItemProtected takes item itm returns boolean
This function allows the user to check if a specific item is protected from being removed by this system.
static method protectItemType takes integer itemTypeId returns nothing
This function allows the user to protect an item type from being removed by this system.
static method deProtectItemType takes integer itemTypeId returns nothing
This function allows the user to stop protecting a previoulsy protected item type from being removed by this system.
static method isItemTypeProtected takes integer itemTypeId returns boolean
This function allows the user to check if an item type is protected from being removed by this system.
static method setItemExpiration takes item itm, real seconds returns nothing
This function allows you to set an items expiration time.
static method getItemExpiration takes item itm returns real
This function allows you to get the time left till the item will get removed.
static method changeItemExpiration takes item itm, integer timeToIncreaseBy returns nothing
This function allows you to increase and decrease the timeout of a specific item.
To increase by 5 seconds pass a 5. To decrease by 5 seconds pass a -5.
static method forceItemExpiration takes item itm, real seconds returns nothing
This function allows the user to force remove an item. This item will be removed from anwhere in the map when the timer runs out.
================================ Explanation =================================
This system allows you to remove all items tht r on the ground for a certain amount of time.
If you pick an item up it will restart the timer.
You should know that any preplaced items will not be removed by this system. They are all set to keep the items on the map.
Once they are picked up and dropped. Then they will be removed when timer expires.
================================ Things You can change =================================
You can change the TIME variable. It determines the time in which an item is removed
If u use an inventory system you may need to change this value INVENTORY_CHECKER.
It checks if the item is in the inventory of the unit so u dont have people
pick up the item just to reset the items counter.
Should only have to be changed if u use an inventory system with a delay.
================================ Thanks to ppl tht helped =================================
Magtheridon96
Almia
Maker
Zwiebelchen
*/
globals
private constant real TIME = 5 // how long the item will last after being dropped
private constant real INVENTORY_CHECKER = 0.01 //how long an item has to be picked up b4 removed from the list
private TableArray ItemTable
private Table ProtectedItems // This keeps track of all the item types that should never be removed from the game by this system.
private rect ItemRect
endglobals
struct MapItemCleanup extends array
private static Table unitDataX
private static Table unitDataY
private static Table unitItemCheck
private static Table unitHasItem
private static method cleanItemTable takes item itm returns nothing
local integer id = GetHandleId(itm)
call ItemTable[id].remove(0)
call ItemTable[id].remove(1)
call DestroyTimer(ItemTable[id].timer[2])
call ItemTable[id].remove(2)
call ItemTable[id].remove(3)
call unitHasItem.remove(id)
endmethod
private static method removeItem takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = ItemTable[GetHandleId(t)][0]
if ItemTable[id].boolean[0] or ItemTable[id].boolean[3] then
call RemoveItem(ItemTable[id].item[1])
call cleanItemTable(ItemTable[id].item[1])
endif
set t = null
endmethod
static method addItemToRemove takes item itm, real time returns nothing
local integer id = GetHandleId(itm)
local timer t = CreateTimer()
set ItemTable[GetHandleId(t)][0] = id
set ItemTable[id].boolean[0] = true
set ItemTable[id].item[1] = itm
set ItemTable[id].timer[2] = t
set ItemTable[id].boolean[3] = false
call TimerStart(t, time, false, function thistype.removeItem)
set t = null
endmethod
static method protectItem takes item itm returns nothing
local integer id = GetHandleId(itm)
set ProtectedItems[id] = id
endmethod
static method deProtectItem takes item itm returns nothing
call ProtectedItems.remove( GetHandleId(itm))
endmethod
static method isItemProtected takes item itm returns boolean
return ProtectedItems.has(GetHandleId(itm))
endmethod
static method protectItemType takes integer itemTypeId returns nothing
set ProtectedItems[itemTypeId] = itemTypeId
endmethod
static method deProtectItemType takes integer itemTypeId returns nothing
call ProtectedItems.remove(itemTypeId)
endmethod
static method isItemTypeProtected takes integer itemTypeId returns boolean
return ProtectedItems.has(itemTypeId)
endmethod
static method setItemExpiration takes item itm, real seconds returns nothing
// * this function allows you to add items when created by a trigger and adds a specific time to the item * /
local integer id = GetHandleId( itm)
if ProtectedItems.has(id) then
call ProtectedItems.remove( id)
endif
if not unitHasItem.boolean[GetHandleId(itm)] then
call addItemToRemove(itm, seconds)
endif
endmethod
static method getItemExpiration takes item itm returns real
// * this function allows you to add items when created by a trigger and adds a specific time to the item * /
return TimerGetRemaining(ItemTable[GetHandleId( itm)].timer[2])
endmethod
static method changeItemExpiration takes item itm, real timeToIncreaseBy returns nothing
// * this function allows you to increase and decrease the timeout of a specific item. * /
// * to increase by 5 seconds pass a 5. To decrease by 5 seconds pass a -5. * /
local integer id = GetHandleId( itm)
call TimerStart(ItemTable[id].timer[2], TimerGetRemaining(ItemTable[id].timer[2]) + timeToIncreaseBy, false, function thistype.removeItem)
endmethod
static method forceItemExpiration takes item itm, real seconds returns nothing
set ItemTable[GetHandleId(itm)].boolean[3] = true
call addItemToRemove(itm, seconds)
endmethod
private static method inventoryCheck takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = unitItemCheck.unit[id]
local item itm = unitItemCheck.item[-1 * id]
set unitHasItem.boolean[GetHandleId(itm)] = true
if UnitHasItem( u, itm) then
set ItemTable[GetHandleId(itm)].boolean[0] = false
endif
call unitItemCheck.remove(id)
call unitItemCheck.remove(-1 * id)
call DestroyTimer(t)
set t = null
endmethod
private static method removePickedUpItem takes nothing returns boolean
local item itm = GetManipulatedItem()
local integer id = GetHandleId( itm)
local timer t
local integer id2
if ItemTable[id].boolean[0] and not ItemTable[id].boolean[3] then
set t = CreateTimer()
set id2 = GetHandleId(t)
set ItemTable[id2][0] = id
set unitItemCheck.unit[id2] = GetTriggerUnit()
set unitItemCheck.item[-1 * id2] = itm
call TimerStart( t, INVENTORY_CHECKER, false, function thistype.inventoryCheck)
set t = null
endif
set itm = null
return false
endmethod
private static method isNotInTable takes integer itemTypeId, integer handleId returns boolean
// * checks if enumerated item is not in ItemTable to be removed and is not in the protected items table * /
return not ItemTable[handleId].boolean[0] and not ItemTable[itemTypeId].boolean[0] /*
*/ and not ProtectedItems.has(handleId) and not ProtectedItems.has(itemTypeId)
endmethod
private static method mapInitItems takes nothing returns nothing
//* gets items that are preplaced on the map * /
local item itm = GetEnumItem()
local integer id = GetHandleId( itm)
if not isNotInTable(GetItemTypeId(itm), id) then
set ProtectedItems[id] = id
endif
set itm = null
endmethod
private static method getMapInitItems takes nothing returns nothing
//* stores items that are preplaced on the map * /
call EnumItemsInRect( bj_mapInitialPlayableArea, null, function thistype.mapInitItems)
endmethod
private static method addManipItem takes nothing returns boolean
// * passes manipulated items to AddItem method and checks if timer is running * /
local item itm = GetManipulatedItem()
local integer id = GetHandleId( itm)
if not isNotInTable(GetItemTypeId(itm), id) then
call addItemToRemove( itm, TIME) // This adds the Manipulated item with a standard time.
endif
set unitHasItem.boolean[id] = false
set itm = null
return false
endmethod
private static method addEnumItems takes nothing returns nothing
// * passes enumerated items to AddItem method and checks if timer is running * /
local item itm = GetEnumItem()
if isNotInTable(GetItemTypeId(itm), GetHandleId(itm)) then
call addItemToRemove( itm, TIME) // This adds the Enumerated item with a standard time.
endif
set itm = null
endmethod
private static method getNewItems takes nothing returns nothing
// * gets new items tht were dropped by killed units or tht were created in a trigger and placed in map * /
local timer t = GetExpiredTimer()
local integer id = GetHandleId( t)
local real X = unitDataX.real[ id]
local real Y = unitDataY.real[ id]
call MoveRectTo( ItemRect, X, Y)
call unitDataX.remove( id)
call unitDataY.remove( id)
call DestroyTimer( t)
set t = null
call EnumItemsInRect( ItemRect, null, function thistype.addEnumItems)
endmethod
private static method getNewItemDelay takes nothing returns boolean
// * creates a delay after unit dies so tht the item has time to be created * /
local timer t = CreateTimer()
local integer id = GetHandleId( t)
local unit u = GetTriggerUnit()
set unitDataX.real[id] = GetUnitX( u)
set unitDataY.real[id] = GetUnitY( u)
call TimerStart( t, 0.00, false, function thistype.getNewItems)
set t = null
set u = null
return false
endmethod
private static method itemSold takes nothing returns boolean
// * removes sold items from Table * /
local integer id = GetHandleId( GetSoldItem())
if not ItemTable[id].boolean[0] then
call ItemTable[id].remove(0)
endif
if ProtectedItems.has( id) then
call ProtectedItems.remove( id)
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
set ItemTable = TableArray[0x2000]
set ProtectedItems = Table.create()
set unitDataX = Table.create()
set unitDataY = Table.create()
set unitItemCheck = Table.create()
set unitHasItem = Table.create()
call thistype.getMapInitItems()
set ItemRect = Rect( 0, 0, 64, 64)
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent( t, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
call TriggerRegisterPlayerUnitEvent( t1, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
call TriggerRegisterPlayerUnitEvent( t2, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerRegisterPlayerUnitEvent( t3, Player(i), EVENT_PLAYER_UNIT_SELL_ITEM, null)
set i = i + 1
endloop
call TriggerAddCondition( t, function thistype.addManipItem)
call TriggerAddCondition( t1, function thistype.removePickedUpItem)
call TriggerAddCondition( t3, function thistype.itemSold)
call TriggerAddCondition( t2, function thistype.getNewItemDelay)
set t = null
set t1 = null
set t2 = null
set t3 = null
endmethod
endstruct
endlibrary
/*
[HIDDEN="Changelog"]
version 3.0.0.2
[INDENT]Fixed small mistakes.[/INDENT]
version 3.0.0.1
[INDENT]Fixed a few bugs.
Removed Alloc as it was not necessary.[/INDENT]
version 3.0.0.0
[INDENT]Reworked system to be more compact and a lot more efficient.[/INDENT]
version 2.7.0.6
[INDENT]changed a mistake w call create() that i made[/INDENT]
version 2.7.0.5
[INDENT]changed the method addItem
changed the GetPlayableMapRect() to bj_mapInitialPlayableArea[/INDENT]
version 2.7.0.0
[INDENT]changed the API a little
removed the createitem method
you now do not need a preplaced rect
added double free protection in case an item was removed by another trigger
added protection from ppl abusing the system when picking up item when they dont have a free inventory space available[/INDENT]
version 2.6.0.0
[INDENT]redid system a bit now removes items when there time expires.
does not loop through all the items anymore
this is a lot more efficient than it was b4[/INDENT]
version 2.5.1.0
[INDENT]added an alternate method to adding items to system[/INDENT]
version 2.5.0.1
[INDENT]forgot to remove saved values from Table[/INDENT]
version 2.5.0.0
[INDENT]system now uses only a struct
API is now updated and improved
trigger add actions have been changed to conditions
a rect has been added to speed up the checking for items when unit dies[/INDENT]
version 2.1.0.0
[INDENT]changed the system to use structs
changed the special timer function. now easier to use just enter your time in seconds and your done[/INDENT]
version 2.0.5.0
[INDENT]fixed small bug with pausing item timer[/INDENT]
version 2.0.0.0
[INDENT]made changes to functionality
removes dead or removed items every second
adds all items that are preplaced into the table tht doesnt allow removal of those items
fixed a small bug with unpausing timer[/INDENT]
version 1.9.0.0
[INDENT]added description of what every function does[/INDENT]
version 1.8.5.0
[INDENT]made changes to functionality
added ability to put custom timer on different items
now removes sold items[/INDENT]
version 1.7.5.0
[INDENT]made changes to functionality
added a table for items u dont want to be removed
fixed some bugs[/INDENT]
version 1.6.0.0
[INDENT]made changes to functionality
added ability to pause item removal[/INDENT]
version 1.5.0.0
[INDENT]uses table by bribe[/INDENT]
[/HIDDEN]
*/