System ItemDoubler

Status
Not open for further replies.

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
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( 'afac' , 'spsh' )
    call NewDoublingRecipe( 'spsh' , 'dsum' )
    call NewDoublingRecipe( 'dsum' , 'penr' )
    call NewDoublingRecipe( 'penr' , 'evtl' )

    
    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
 

Attachments

  • ItemDoubler 1.7.w3x
    28 KB · Views: 231

Hero

─║╣ero─
Reaction score
250
hhmh..post the code here please...will be easier to comment without having to download
 

Sim

Forum Administrator
Staff member
Reaction score
534
> Works like the weapon doubling in Battleships crossfire: two weapons of the same type are merged into one item when acquired.

Further explanations wouldn't hurt :p

>You want any and every lagg in the loadingscreen

Huh? :confused: What does it mean?
 

Hero

─║╣ero─
Reaction score
250
>You want any and every lagg in the loadingscreen

Huh? What does it mean?

I think he means...the only time you want a map to lag is when it is at the loading screen.


And posting the code wouldn't hurt :p
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Introduce vJass functions into this system?
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top