Name | Type | is_array | initial_value |
caster | unit | No | |
i | integer | No | |
i1 | integer | No | |
i2 | integer | No | |
items | itemcode | Yes | |
myHero | unit | No | |
point1 | location | No | |
target | unit | No | |
unitG | group | No | |
urDialog | dialog | No | |
urItemType | itemcode | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_item_recipe_list_Actions takes nothing returns nothing
local Recipe data = Recipe.create( 'ratc', 'rat9', 'rat9', 0, 0, 0, 'I000', true)
local Recipe dat = Recipe.create( 'ratc', 'rat6', 0, 0, 0, 0, 'I000', false)
endfunction
//===========================================================================
function InitTrig_item_recipe_list takes nothing returns nothing
set gg_trg_item_recipe_list = CreateTrigger()
call TriggerRegisterTimerEvent( gg_trg_item_recipe_list, 0.00, false)
call TriggerAddAction( gg_trg_item_recipe_list, function Trig_item_recipe_list_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_disAssemble_item_Actions takes nothing returns nothing
call Recipe.disAssemble( UnitItemInSlot( gg_unit_Hamg_0003, 0), gg_unit_Hamg_0003)
endfunction
//===========================================================================
function InitTrig_disAssemble_item takes nothing returns nothing
set gg_trg_disAssemble_item = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_disAssemble_item, Player(0), "disAssemble", false)
call TriggerAddAction( gg_trg_disAssemble_item, function Trig_disAssemble_item_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
/* [Snippet] Alloc Alternative */
/* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-alloc-alternative-221493/ */
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=40
//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=0
//TESH.alwaysfold=0
library ItemRecipeSystem /* by deathismyfriend version 1.1.1.0
================================ 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 create item recipes.
*
************************************************************************************
*
* 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 recipe system it only requires you to make recipes by using the create function.
* After that it checks for a recipe everytime an item is picked up or bought or when u enter a rect decided by the user.
* Allows you to set a rect if u want to use the enter rect / region event.
* Note: removes the items and adds the new item to the unit when the last item needed for the recipe is picked up by the unit.
*
* Capabilities
* -----------------------
*
* Allows the user to easily create an item recipe.
* - example as done in map - local RecipeList data = RecipeList.create( 'ratc', 'rat6', 'rat9', 0, 0, 0, 'I000', true)
* - this recipe only uses 3 items.
*
******************************************************************************************************************************************************************************************************
/ ******************************************************************************************************************************************************************************************************
/ *
/ * CREATORS / DESTRUCTORS
/ * -----------------------
/ *
/ ******************************************************************************************************************************************************************************************************
/ *
/ * struct Recipe extends array
/ *
/ * static method create takes integer i1, integer i2, integer i3, integer i4, integer i5, integer i6, integer itmToBeMade, boolean createOnPickup returns thistype
/ * - this is all you need to create an itemRecipe. If you do not want a 6 item recipe just put in a 0 for the integers.
/ * - If you want to make a recipe that you need to go in a region to make then set pickupRecipe to false.
/ *
/ * method destroy takes nothing returns nothing
/ * - to destroy an item recipe if wanted. just store the struct into an integer variable to destroy the item Recipe
/ *
/ * static method disAssemble takes item itm, unit u returns nothing
/ * - u can use this to disAssemble an item made through a recipe
/ *
/ *
/ * METHODS
/ * -------
/ *
/ * method RequireCharges takes integer itemId, integer charges returns nothing
/ * - This allows u to make item recipes require charges.
/ * - It takes the item id and the number of charges you want it to have.
/ *
/ * static method forceRecipe takes unit u returns nothing
/ * - allows u to force a recipe for when a unit enters region or some other event of ur choice
/ *
/ * static method forceRecipeByItem takes unit u, integer itemTypeId returns nothing
/ * - this allows for specific recipes to be made in specific rects.
/ * - note: use a special item for the itemTypeId
/ *
/ * static method disable takes nothing returns nothing
/ * - pauses the recipe system
/ *
/ * static method enable takes nothing returns nothing
/ * - resumes the recipe system
/ *
/ *
/ * private static method turnOffOtherSystems takes nothing returns nothing
/ * - add systems to turn off when the recipe system is running
/ *
/ * private static method turnOnOtherSystems takes nothing returns nothing
/ * - the systems u turned off in the above method turn them on here
/ *
/ ********************************************************************************************************************************/
globals
private Table disAssembleTable
private integer array structArray
private integer array regId
endglobals
struct Recipe extends array
implement Alloc
private static rect recipeRect
private static integer tempR
private static method turnOffOtherSystems takes nothing returns nothing
endmethod
private static method turnOnOtherSystems takes nothing returns nothing
endmethod
private static integer index = 0
private static boolean combineItems = true
private integer i1
private integer i2
private integer i3
private integer i4
private integer i5
private integer i6
private integer charges1
private integer charges2
private integer charges3
private integer charges4
private integer charges5
private integer charges6
private integer itmToBeMade
private integer ttlItemsForRecipe
private boolean pickup
private boolean charges
private static method checkingRecipes takes integer id, unit u, boolean pick returns nothing
local thistype this
local region reg
local integer array i
local integer array charges
local integer ttlItemsUnitHas = 0
local boolean b
local item array itm
local boolean array isItm
local integer L = 1
local integer L1 = 1 // used to check through the recipes tht go w that specific item
local integer L2 = 1
local integer r = 1 // used for removing items from the slots
if combineItems then
call thistype.turnOffOtherSystems()
loop
exitwhen L1 > index
set this = structArray[L1]
if this.pickup == pick then
set i[1] = this.i1
set i[2] = this.i2
set i[3] = this.i3
set i[4] = this.i4
set i[5] = this.i5
set i[6] = this.i6
set charges[1] = this.charges1
set charges[2] = this.charges2
set charges[3] = this.charges3
set charges[4] = this.charges4
set charges[5] = this.charges5
set charges[6] = this.charges6
set isItm[1] = false
set isItm[2] = false
set isItm[3] = false
set isItm[4] = false
set isItm[5] = false
set isItm[6] = false
set ttlItemsUnitHas = 0
loop
exitwhen L > 6
set itm[L] = UnitItemInSlot( u, (L - 1))
loop
exitwhen L2 > 6
if isItm[L2] == false then
if itm[L] != null and GetItemTypeId( itm[L]) == i[L2] then
if this.charges then
if GetItemCharges( itm[L]) >= charges[L] then
set isItm[L2] = true
set ttlItemsUnitHas = ttlItemsUnitHas + 1
endif
else
set isItm[L2] = true
set ttlItemsUnitHas = ttlItemsUnitHas + 1
endif
exitwhen isItm[L2]
endif
endif
set L2 = L2 + 1
endloop
set L2 = 1
set L = L + 1
endloop
if ttlItemsUnitHas == this.ttlItemsForRecipe then
loop
exitwhen r > 6
if isItm[r] then
call RemoveItem( itm[r])
endif
set itm[r] = null
set r = r + 1
endloop
call UnitAddItemById( u, this.itmToBeMade)
endif
endif
set L1 = L1 + 1
endloop
call thistype.turnOnOtherSystems()
endif
endmethod
static method forceRecipe takes unit u returns nothing
local integer L = 0
loop
exitwhen L > 5
call thistype.checkingRecipes( GetItemTypeId( UnitItemInSlot( u, L)), u, false)
set L = L + 1
endloop
set u = null
endmethod
static method forceRecipeByItem takes unit u, integer itemTypeId returns nothing
local integer L = 0
loop
exitwhen L > 5
if GetItemTypeId( UnitItemInSlot( u, L)) == itemTypeId then
call thistype.checkingRecipes( itemTypeId, u, false)
endif
set L = L + 1
endloop
set u = null
endmethod
method RequireCharges takes integer itemId, integer charges returns nothing
if this.i1 != 0 and this.i1 == itemId then
set this.charges1 = charges
elseif this.i2 != 0 and this.i2 == itemId then
set this.charges2 = charges
elseif this.i3 != 0 and this.i3 == itemId then
set this.charges3 = charges
elseif this.i4 != 0 and this.i4 == itemId then
set this.charges4 = charges
elseif this.i5 != 0 and this.i5 == itemId then
set this.charges5 = charges
elseif this.i6 != 0 and this.i6 == itemId then
set this.charges6 = charges
endif
set this.charges = true
endmethod
static method disAssemble takes item itm, unit u returns nothing
local thistype this = disAssembleTable[ GetItemTypeId( itm)]
set combineItems = false
call thistype.turnOffOtherSystems()
call RemoveItem( itm)
call UnitAddItemById( u, this.i1)
call UnitAddItemById( u, this.i2)
call UnitAddItemById( u, this.i3)
call UnitAddItemById( u, this.i4)
call UnitAddItemById( u, this.i5)
call UnitAddItemById( u, this.i6)
call thistype.turnOnOtherSystems()
set combineItems = true
endmethod
static method disable takes nothing returns nothing
set combineItems = false
endmethod
static method enable takes nothing returns nothing
set combineItems = true
endmethod
static method create takes integer id1, integer id2, integer id3, integer id4, integer id5, integer id6, integer itmToBeMade, boolean createOnPickup returns thistype
local thistype this = thistype.allocate()
local integer array i
local integer L = 0
set this.i1 = id1
set this.i2 = id2
set this.i3 = id3
set this.i4 = id4
set this.i5 = id5
set this.i6 = id6
set this.itmToBeMade = itmToBeMade
set this.pickup = createOnPickup
set this.charges = false
set i[0] = id1
set i[1] = id2
set i[2] = id3
set i[3] = id4
set i[4] = id5
set i[5] = id6
set this.ttlItemsForRecipe = 0
set disAssembleTable[itmToBeMade] = this
set index = index + 1
set structArray[index] = this
set this.ttlItemsForRecipe = 0
loop
exitwhen L > 5
if i[L] != 0 then
set this.ttlItemsForRecipe = this.ttlItemsForRecipe + 1
endif
set L = L + 1
endloop
return this
endmethod
method destroy takes nothing returns nothing
local integer L = 1
loop
exitwhen L > index
if structArray[ L] == this then
set structArray[ L] = structArray[index]
set index = index - 1
endif
set L = L + 1
endloop
call this.deallocate()
endmethod
private static method recipeCheck takes nothing returns boolean
call thistype.checkingRecipes(GetItemTypeId(GetManipulatedItem()), GetTriggerUnit(), true)
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set disAssembleTable = Table.create()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition( t, function thistype.recipeCheck)
set t = null
endmethod
endstruct
endlibrary
/*
[HIDDEN="Changelog"]
version 1.1.1.0
[INDENT]mad changes purge suggested.[/INDENT]
version 1.1.0.0
[INDENT]Added the ability to make items require charges
Updated API[/INDENT]
version 1.0.9.1
[INDENT]added ability to make specific items in specific rects
note: u will need a condtion in the trigger u make and also a special item( an item not used in other recipes) for this to work[/INDENT]
version 1.0.9.0
[INDENT]got rid of rects and added a method to call for when a player wants to force a recipe to be created[/INDENT]
version 1.0.5.0
[INDENT]fixed a bug w owned rects[/INDENT]
version 1.0.4.5
[INDENT]you can now have regions w different owners[/INDENT]
version 1.0.4.2
[INDENT]fixed a bug w unit enters region event[/INDENT]
version 1.0.4.1
[INDENT]added ability for multiple regions[/INDENT]
version 1.0.4.0
[INDENT]got rid of unused Tables
now works completely although i will hopefully be changing it back to tables if i could find a viable way of storing itemTypeIds into tables[/INDENT]
version 1.0.3.0
[INDENT]works with unit enters region event.
Only downside is that to create a recipe it needs one more arguement[/INDENT]
version 1.0.2.0
[INDENT]fixed the bug with not working when 2 items of same type r being added in a recipe[/INDENT]
version 1.0.1.0
[INDENT]added a method to turn other systems on or off when needed
this is to be used when u have a system that fires w the event EVENT_PLAYER_UNIT_DROP_ITEM[/INDENT]
version 1.0.0.7
[INDENT]added a pause and resume for the system[/INDENT]
version 1.0.0.5
[INDENT]now can disAssemble items made through recipes[/INDENT]
version 1.0.0.1
[INDENT]corrected indentation again lol[/INDENT]
version 1.0.0.0
[INDENT]first version released[/INDENT]
[/HIDDEN]
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ItemRecipeSystem /* version 1.0.9.1
================================ 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 create item recipes.
*
************************************************************************************
*
* 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 recipe system it only requires you to make recipes by using the create function.
* After that it checks for a recipe everytime an item is picked up or bought or when u enter a rect decided by the user.
* Allows you to set a rect if u want to use the enter rect / region event.
* Note: removes the items and adds the new item to the unit when the last item needed for the recipe is picked up by the unit.
*
* Capabilities
* -----------------------
*
* Allows the user to easily create an item recipe.
* - example as done in map - local RecipeList data = RecipeList.create( 'ratc', 'rat6', 'rat9', 0, 0, 0, 'I000', true)
* - this recipe only uses 3 items.
*
******************************************************************************************************************************************************************************************************
/ ******************************************************************************************************************************************************************************************************
/ *
/ * CREATORS / DESTRUCTORS
/ * -----------------------
/ *
/ ******************************************************************************************************************************************************************************************************
/ *
/ * struct Recipe extends array
/ *
/ * static method create takes integer i1, integer i2, integer i3, integer i4, integer i5, integer i6, integer itmToBeMade, boolean createOnPickup returns thistype
/ * - this is all you need to create an itemRecipe. If you do not want a 6 item recipe just put in a 0 for the integers.
/ * - If you want to make a recipe that you need to go in a region to make then set pickupRecipe to false.
/ *
/ * method destroy takes nothing returns nothing
/ * - to destroy an item recipe if wanted. just store the struct into an integer variable to destroy the item Recipe
/ *
/ * static method disAssemble takes item itm, unit u returns nothing
/ * - u can use this to disAssemble an item made through a recipe
/ *
/ *
/ * FIELDS
/ * ------
/ *
/ * static method forceRecipe takes unit u returns nothing
/ * - allows u to force a recipe for when a unit enters region or some other event of ur choice
/ *
/ * static method forceRecipeByItem takes unit u, integer itemTypeId returns nothing
/ * - this allows for specific recipes to be made in specific rects.
/ * - note: use a special item for the itemTypeId
/ *
/ * static method pause takes nothing returns nothing
/ * - pauses the recipe system
/ *
/ * static method resume takes nothing returns nothing
/ * - resumes the recipe system
/ *
/ *
/ * private static method turnOffOtherSystems takes nothing returns nothing
/ * - add systems to turn off when the recipe system is running
/ *
/ * private static method turnOnOtherSystems takes nothing returns nothing
/ * - the systems u turned off in the above method turn them on here
/ *
/ ********************************************************************************************************************************/
globals
private Table disAssembleTable
private integer array structArray
private integer array regId
endglobals
struct Recipe extends array
implement Alloc
private static rect recipeRect
private static integer tempR
private static method turnOffOtherSystems takes nothing returns nothing
endmethod
private static method turnOnOtherSystems takes nothing returns nothing
endmethod
private static integer index = 0
private static boolean combineItems = true
private integer i1
private integer i2
private integer i3
private integer i4
private integer i5
private integer i6
private integer itmToBeMade
private integer ttlItemsForRecipe
private boolean pickup
static method forceRecipe takes unit u returns nothing
local integer L = 0
loop
exitwhen L > 5
call thistype.checkingRecipes( GetItemTypeId( UnitItemInSlot( u, L)), u, false)
set L = L + 1
endloop
set u = null
endmethod
static method forceRecipeByItem takes unit u, integer itemTypeId returns nothing
local integer L = 0
loop
exitwhen L > 5
if GetItemTypeId( UnitItemInSlot( u, L)) == itemTypeId then
call thistype.checkingRecipes( itemTypeId, u, false)
endif
set L = L + 1
endloop
set u = null
endmethod
static method disAssemble takes item itm, unit u returns nothing
local integer id = GetItemTypeId( itm)
local thistype this = disAssembleTable[id]
set combineItems = false
call thistype.turnOffOtherSystems()
call RemoveItem( itm)
call UnitAddItemById( u, this.i1)
call UnitAddItemById( u, this.i2)
call UnitAddItemById( u, this.i3)
call UnitAddItemById( u, this.i4)
call UnitAddItemById( u, this.i5)
call UnitAddItemById( u, this.i6)
set itm = null
call thistype.turnOnOtherSystems()
set combineItems = true
endmethod
static method pause takes nothing returns nothing
set combineItems = false
endmethod
static method resume takes nothing returns nothing
set combineItems = true
endmethod
static method create takes integer id1, integer id2, integer id3, integer id4, integer id5, integer id6, integer itmToBeMade, boolean createOnPickup returns thistype
local thistype this = thistype.allocate()
local integer array i
local integer L = 0
set this.i1 = id1
set this.i2 = id2
set this.i3 = id3
set this.i4 = id4
set this.i5 = id5
set this.i6 = id6
set this.itmToBeMade = itmToBeMade
set this.pickup = createOnPickup
set i[0] = id1
set i[1] = id2
set i[2] = id3
set i[3] = id4
set i[4] = id5
set i[5] = id6
set this.ttlItemsForRecipe = 0
set disAssembleTable[itmToBeMade] = this
set index = index + 1
set structArray[index] = this
set this.ttlItemsForRecipe = 0
loop
exitwhen L > 5
if i[L] != 0 then
set this.ttlItemsForRecipe = this.ttlItemsForRecipe + 1
endif
set L = L + 1
endloop
return this
endmethod
method destroy takes nothing returns nothing
call this.deallocate()
endmethod
private static method checkingRecipes takes integer id, unit u, boolean pick returns nothing
local thistype this
local region reg
local integer array i
local integer ttlItemsUnitHas = 0
local boolean b
local item array itm
local boolean array isItm
local integer L = 1
local integer L1 = 1 // used to check through the recipes tht go w that specific item
local integer L2 = 1
local integer r = 1 // used for removing items from the slots
if combineItems then
call thistype.turnOffOtherSystems()
loop
exitwhen L1 > index
set this = structArray[L1]
if this.pickup == pick then
set i[1] = this.i1
set i[2] = this.i2
set i[3] = this.i3
set i[4] = this.i4
set i[5] = this.i5
set i[6] = this.i6
set isItm[1] = false
set isItm[2] = false
set isItm[3] = false
set isItm[4] = false
set isItm[5] = false
set isItm[6] = false
set ttlItemsUnitHas = 0
loop
exitwhen L > 6
set itm[L] = UnitItemInSlot( u, (L - 1))
loop
exitwhen L2 > 6
if isItm[L2] == false then
if itm[L] != null and GetItemTypeId( itm[L]) == i[L2] then
set isItm[L2] = true
set ttlItemsUnitHas = ttlItemsUnitHas + 1
exitwhen isItm[L2]
endif
endif
set L2 = L2 + 1
endloop
set L2 = 1
set L = L + 1
endloop
if ttlItemsUnitHas == this.ttlItemsForRecipe then
loop
exitwhen r > 6
if isItm[r] then
call RemoveItem( itm[r])
endif
set itm[r] = null
set r = r + 1
endloop
call UnitAddItemById( u, this.itmToBeMade)
endif
endif
set L1 = L1 + 1
endloop
call thistype.turnOnOtherSystems()
endif
endmethod
private static method recipeCheck takes nothing returns boolean
local integer id = GetItemTypeId( GetManipulatedItem())
local unit u = GetTriggerUnit()
call thistype.checkingRecipes( id, u, true)
set u = null
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set disAssembleTable = Table.create()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition( t, function thistype.recipeCheck)
set t = null
endmethod
endstruct
endlibrary
/*
[HIDDEN="Changelog"]
version 1.0.9.1
[INDENT]added ability to make specific items in specific rects
note: u will need a condtion in the trigger u make and also a special item( an item not used in other recipes) for this to work[/INDENT]
version 1.0.9.0
[INDENT]got rid of rects and added a method to call for when a player wants to force a recipe to be created[/INDENT]
version 1.0.5.0
[INDENT]fixed a bug w owned rects[/INDENT]
version 1.0.4.5
[INDENT]you can now have regions w different owners[/INDENT]
version 1.0.4.2
[INDENT]fixed a bug w unit enters region event[/INDENT]
version 1.0.4.1
[INDENT]added ability for multiple regions[/INDENT]
version 1.0.4.0
[INDENT]got rid of unused Tables
now works completely although i will hopefully be changing it back to tables if i could find a viable way of storing itemTypeIds into tables[/INDENT]
version 1.0.3.0
[INDENT]works with unit enters region event.
Only downside is that to create a recipe it needs one more arguement[/INDENT]
version 1.0.2.0
[INDENT]fixed the bug with not working when 2 items of same type r being added in a recipe[/INDENT]
version 1.0.1.0
[INDENT]added a method to turn other systems on or off when needed
this is to be used when u have a system that fires w the event EVENT_PLAYER_UNIT_DROP_ITEM[/INDENT]
version 1.0.0.7
[INDENT]added a pause and resume for the system[/INDENT]
version 1.0.0.5
[INDENT]now can disAssemble items made through recipes[/INDENT]
version 1.0.0.1
[INDENT]corrected indentation again lol[/INDENT]
version 1.0.0.0
[INDENT]first version released[/INDENT]
[/HIDDEN]
*/