SerraAvenger
Cuz I can
- Reaction score
- 234
Special Thanks:
Rheias, for his Idea with the one line Recipe! ( No I did not copy any code. I didn't even look at his code. I only saw his idea of NewRecipe( .... ) - which was a good idea !)
Works like the weapon doubling in Battleships crossfire: two weapons of the same type are merged into one item when acquired.
I.e. :
Hero Archmage get's an item of type Bioshpere.
Soon, he find's another item of type Bioshpere, and as soon he takes it, both B.s - vanish!
But at the position of the first item (in the inventory), suddenly Hero A. find's item Carbon Acid - and get's the message: "Two Biospheres merged to a Carboic acid" !
With this system, you only tell which items B combine to an item C ( up to 8191 possible recipes - and searching for the right item takes only little time! ) - and as soon any Hero get's two items B, he'll get that item C.
Easy to modify for your map, and contains two short manuals - one for JASSers and one for GUIlers : )
Perhaps I shall add a combining system ( which works with the same efficiency then).
Fyi: stands under the GNU license.
Code:
MAP HEADER
Trigger WeaponDoubler
Requirements:
In order to implement it in your map, you will need NewGen JassPack (c) Vexorian - or you'll have to delete that "constant" from the first line of code in your map header
Special Features:
- Create a new Recipe with a single line of code, nothing else has to be changed!
- You can easily create new recipes during a game, and system will still work perfectly!
- Runs With Very high efficiency!
- Introduction for GUI-users - you need no knowledge of JASS in order to make it work, everything you need is explained in a three steps guide
- Only short code that almost doesn't need any space
-have a lot of fun!
Changes since 1.0:
-Removed a Variable Leak (If existant) that ocurred when the doubler function is reaturning before the end
-Removed a Bug that let the ItemDoubler stop working with exactly 20 items
-Made It A LOT easier to create new recipes, you now need many lines less in order to make new recipes
Rheias, for his Idea with the one line Recipe! ( No I did not copy any code. I didn't even look at his code. I only saw his idea of NewRecipe( .... ) - which was a good idea !)
Works like the weapon doubling in Battleships crossfire: two weapons of the same type are merged into one item when acquired.
I.e. :
Hero Archmage get's an item of type Bioshpere.
Soon, he find's another item of type Bioshpere, and as soon he takes it, both B.s - vanish!
But at the position of the first item (in the inventory), suddenly Hero A. find's item Carbon Acid - and get's the message: "Two Biospheres merged to a Carboic acid" !
With this system, you only tell which items B combine to an item C ( up to 8191 possible recipes - and searching for the right item takes only little time! ) - and as soon any Hero get's two items B, he'll get that item C.
Easy to modify for your map, and contains two short manuals - one for JASSers and one for GUIlers : )
Perhaps I shall add a combining system ( which works with the same efficiency then).
Fyi: stands under the GNU license.
Code:
MAP HEADER
JASS:
constant function recipetype takes nothing returns itemtype
return ITEM_TYPE_ARTIFACT
endfunction
globals
integer numrecipes = 0
endglobals
function bsearch takes integer itemid returns integer
// All Indicators ( Indicate the current position in inventory, arrays, playergroups and anything similiar)
local integer fieldindicator = 0
local integer base = 1
local integer lim = numrecipes
loop
exitwhen lim == 0
set fieldindicator = base + (lim / 2)
if itemid > udg_CombineEducts[fieldindicator] then
set lim = lim - 1
set base = fieldindicator + 1
elseif itemid == udg_CombineEducts[fieldindicator] then
return fieldindicator
endif
set lim = lim / 2
endloop
return 0
endfunction
function SortNewRecipe takes nothing returns boolean
// All Indicators ( Indicate the current position in inventory, arrays, playergroups and anything similiar)
local integer loopa // loops back through the array in order to sort it
// Everything interesting with the array
local integer key // The integer that will be sorted now
local integer lock // integer corresponding to the key. Lock and key have to have the same position but in different arrays.
set key = udg_CombineEducts[numrecipes]
set lock = udg_CombineProducts[numrecipes]
set loopa = numrecipes - 1
loop
set udg_CombineEducts[loopa + 1] = udg_CombineEducts[loopa]
set udg_CombineProducts[loopa + 1] = udg_CombineProducts[loopa]
exitwhen not ( loopa > 0 and udg_CombineEducts[loopa] > key)
set loopa = loopa - 1
endloop
set udg_CombineEducts[loopa + 1] = key
set udg_CombineProducts[loopa + 1] = lock
return true
endfunction
function NewDoublingRecipe takes integer EductId, integer ProductId returns nothing
set numrecipes = numrecipes + 1
set udg_CombineEducts[ numrecipes ] = EductId
set udg_CombineProducts[ numrecipes ] = ProductId
call SortNewRecipe()
endfunction
Trigger WeaponDoubler
JASS:
function doubler takes nothing returns boolean
// All Indicators ( Indicate the current position in inventory, arrays, playergroups and anything similiar)
local integer fieldindicator = ( numrecipes + 1 ) /2
local integer slotindicator = 0
local integer lastfield = numrecipes
local integer nextstep = 0
local integer lim = numrecipes
// Anything Interesting about the Acquired Item
local item trigitem = GetManipulatedItem()
local integer itemid = GetItemTypeId( trigitem )
// This is reservated for another item of the same type like the Acquired item
local item slotitem = null
// The item name of the product&the product
local string productname
local item product
// Anything interesting about triggering unit
local unit trigunit = GetTriggerUnit()
local player trigplayer = GetOwningPlayer( trigunit )
if GetItemType( trigitem) != recipetype() then
set trigunit = null
set trigitem = null
set slotitem = null
set product = null
set productname = null
set fieldindicator = 0
set slotindicator = 0
set lastfield = 0
return false // the return statement skips the rest of this code.
endif
loop
// Now we loop through the inventory of the triggering unit checking if there is a second item of the same itemtype like trigitem but which is different than trigitem.
if slotindicator > 5 then
set trigunit = null
set trigitem = null
set slotitem = null
set product = null
set productname = null
set fieldindicator = 0
set slotindicator = 0
set lastfield = 0
return false
endif
set slotitem = UnitItemInSlot( trigunit , slotindicator )
exitwhen slotitem != trigitem and GetItemTypeId( slotitem ) == itemid
//now as soon as we found another item that is like our first item, we exit.
set slotindicator = slotindicator + 1
endloop
set fieldindicator = bsearch( itemid )
// Now the Two Items are exchanged with an upgraded item of the same type, and a message is displayed showing what was combined to what.
set product = CreateItem( udg_CombineProducts[fieldindicator] , GetUnitX( trigunit ), GetUnitY( trigunit ) )
set productname = GetItemName( product )
call RemoveItem( slotitem )
call DisplayTextToPlayer( trigplayer , 0 , 0 , "You combined two |cff5555ff" + GetItemName( trigitem ) + "s|r to a |cff55ff55" + productname + "|r. Gratulations!" )
call RemoveItem( trigitem )
call UnitAddItem( trigunit, product )
// Clean up
set trigunit = null
set trigitem = null
set slotitem = null
set product = null
set productname = null
set fieldindicator = 0
set slotindicator = 0
set lastfield = 0
return true
endfunction
//==== Init Trigger NewTrigger ====
function InitTrig_WeaponDoubler takes nothing returns nothing
local integer playerindicator = 0
local boolexpr dummyboolexpr = null
set gg_trg_WeaponDoubler = CreateTrigger()
loop
exitwhen playerindicator > 12
call TriggerRegisterPlayerUnitEvent(gg_trg_WeaponDoubler, Player( playerindicator ) , EVENT_PLAYER_UNIT_PICKUP_ITEM, dummyboolexpr )
// makes the "Unit owned by player X picks up an item" function for all players from 1 - 12
set playerindicator = playerindicator + 1
endloop
call NewDoublingRecipe( 039;afac039; , 039;spsh039; )
call NewDoublingRecipe( 039;spsh039; , 039;dsum039; )
call NewDoublingRecipe( 039;dsum039; , 039;penr039; )
call NewDoublingRecipe( 039;penr039; , 039;evtl039; )
call DestroyBoolExpr( dummyboolexpr )
call TriggerAddCondition(gg_trg_WeaponDoubler, Condition(function doubler))
set playerindicator = 0
endfunction
Requirements:
In order to implement it in your map, you will need NewGen JassPack (c) Vexorian - or you'll have to delete that "constant" from the first line of code in your map header
Special Features:
- Create a new Recipe with a single line of code, nothing else has to be changed!
- You can easily create new recipes during a game, and system will still work perfectly!
- Runs With Very high efficiency!
- Introduction for GUI-users - you need no knowledge of JASS in order to make it work, everything you need is explained in a three steps guide
- Only short code that almost doesn't need any space
-have a lot of fun!
Changes since 1.0:
-Removed a Variable Leak (If existant) that ocurred when the doubler function is reaturning before the end
-Removed a Bug that let the ItemDoubler stop working with exactly 20 items
-Made It A LOT easier to create new recipes, you now need many lines less in order to make new recipes