Itemcrafting Skill

Heavy-Gear

New Member
Reaction score
7
For my game Island of Souls I've been working on the itemcrafting trigger. There are no syntax errors etc. but at the moment, regardless of whether you have the correct components, "ERROR: Missing Requirements!" Is displayed whenever you try to make something.

JASS:
scope CraftTrigger
//==========================================================================
globals
    
    // Toolcraft Abilities
    private constant integer SID_BUILDARROW = 'A00E'
    private constant integer SID_BUILDAWARD = 'A00J'
    private constant integer SID_BUILDFIREKIT = 'A005'
    private constant integer SID_BUILDFBLADE = 'A00F'
    private constant integer SID_BUILDHSTONE = 'A00K'
    private constant integer SID_BUILDKNIFE = 'A00G'
    private constant integer SID_BUILDSWARD = 'A00H'
    private constant integer SID_BUILDSHARPSTONE = 'A007'
    private constant integer SID_BUILDSFBLADE = 'A00I'   
    // Toolcraft Items
    private constant integer IID_ARROW = 'I00D'
    private constant integer IID_AWARD = 'I00E'
    private constant integer IID_FIREKIT = 'I00A'
    private constant integer IID_FBLADE = 'I007'
    private constant integer IID_HSTONE = 'I005'
    private constant integer IID_KNIFE = 'I006'
    private constant integer IID_SWARD = 'I00C'
    private constant integer IID_SHARPSTONE = 'I009'
    private constant integer IID_SFBLADE = 'I008'
    
    
    
endglobals
//==========================================================================
private function Actions takes nothing returns nothing

local integer array RawItem
local integer array RawItemIID
local integer array RawItemNeeded
                       
local unit C = GetSpellAbilityUnit()
local integer I
local integer c = 0                
local integer t = 0
local integer i = 0
local integer j = 0
      
local integer stones = 0                  
local integer vines = 0                   
local integer flint = 0                   
local integer largebones = 0              
local integer shells = 0                  
local integer smallbones = 0              
local integer soulstones = 0              
local integer sticks = 0                  
local integer flintblades = 0             
local integer strongflintblades = 0       
local integer merrentill = 0              
local integer sungrass = 0                
local integer gnollsleaf = 0              
local integer avantoe = 0                 
local integer gnomeswood = 0
local integer knifereq = 0                 
local integer hammerreq = 0

if GetSpellAbilityId() == SID_BUILDARROW then
    set sticks = 1
    set shells = 1
    set knifereq = 1
    set I = IID_ARROW
    set t = 3
endif 
if GetSpellAbilityId() == SID_BUILDAWARD then 
    set sticks = 1
    set stones = 1
    set vines = 1
    set flint = 1
    set soulstones = 1
    set knifereq = 1
    set I = IID_AWARD
    set t = 6
endif 
if GetSpellAbilityId() == SID_BUILDFIREKIT then 
    set sticks = 1
    set stones = 2
    set knifereq = 1
    set I = IID_FIREKIT
    set t = 4
endif 
if GetSpellAbilityId() == SID_BUILDFBLADE then 
    set flint = 1
    set hammerreq = 1
    set I = IID_FBLADE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDHSTONE then 
    set stones = 2
    set I = IID_HSTONE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDKNIFE then 
    set flintblades = 1
    set vines = 1
    set I = IID_KNIFE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDSWARD then 
    set sticks = 1
    set stones = 1
    set vines = 1
    set flint = 1
    set soulstones = 1
    set knifereq = 1
    set I = IID_SWARD
    set t = 6
endif 
if GetSpellAbilityId() == SID_BUILDSHARPSTONE then 
    set stones = 1
    set knifereq = 1
    set I = IID_SHARPSTONE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDSFBLADE then 
    set flint = 1
    set hammerreq = 1
    set I = IID_SFBLADE
    set t = 2    
endif

set RawItemIID[0]  = 'I002' //Stone                   
set RawItemIID[1]  = 'I000' //Vine                    
set RawItemIID[2]  = 'I00B' //Flint                    
set RawItemIID[3]  = 'I00G' //LargeBone               
set RawItemIID[4]  = 'I003' //Shell                   
set RawItemIID[5]  = 'I00F' //SmallBone               
set RawItemIID[6]  = 'I004' //SoulStone               
set RawItemIID[7]  = 'I001' //Stick                   
set RawItemIID[8]  = 'I007' //FlintBlade              
set RawItemIID[9]  = 'I008' //StrongFlintBlade        
set RawItemIID[10] = 'I00J' //Merrentill     
set RawItemIID[11] = 'I00K' //Sungrass       
set RawItemIID[12] = 'I00L' //Gnollsleaf     
set RawItemIID[13] = 'I00M' //Avantoe        
set RawItemIID[14] = 'I00N' //Gnomeswood
set RawItemIID[15] = 'I006' //Knife        
set RawItemIID[16] = 'I005' //Hammerstone      
                           
set RawItemNeeded[0]  = stones
set RawItemNeeded[1]  = vines
set RawItemNeeded[2]  = flint
set RawItemNeeded[3]  = largebones
set RawItemNeeded[4]  = shells
set RawItemNeeded[5]  = smallbones
set RawItemNeeded[6]  = soulstones
set RawItemNeeded[7]  = sticks
set RawItemNeeded[8]  = flintblades
set RawItemNeeded[9]  = strongflintblades
set RawItemNeeded[10] = merrentill
set RawItemNeeded[11] = sungrass
set RawItemNeeded[12] = gnollsleaf
set RawItemNeeded[13] = avantoe
set RawItemNeeded[14] = gnomeswood
set RawItemNeeded[15] = knifereq
set RawItemNeeded[16] = hammerreq

loop
exitwhen i >= 5   //loops inventory slots     
    loop
        exitwhen j >= 16  //loops all raw item types  
        if GetItemTypeId(UnitItemInSlot(C, i)) == RawItemIID[j] then  
            set RawItem[j] = RawItem[j] + 1 
        endif  
        if RawItem[j] == RawItemNeeded[j] and RawItemNeeded[j] != 0 then  //checks if there is enough of that item
            set c = c + 1 
        endif
        set j = j + 1     
    endloop        
set i = i + 1
endloop

set i = 0
set j = 0

if c == t then    
    loop
    exitwhen i >= 14 //note: this loop only removes up to knife/hammerstone and not including
        loop
            exitwhen j &gt;= RawItemNeeded<i>
            call UnitRemoveItem(C, GetItemOfTypeFromUnitBJ(C, RawItem<i>))
            set j = j + 1
        endloop
    set i = i + 1
    endloop
    
    call UnitAddItem(C, CreateItem(I, GetUnitX(C), GetUnitY(C)))
else
    call DisplayTimedTextToPlayer(GetOwningPlayer(C), 0, 0, 10, &quot;ERROR: Missing requirements!&quot;)
endif

endfunction

//==========================================================================
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SID_BUILDARROW or GetSpellAbilityId() ==  SID_BUILDAWARD or GetSpellAbilityId() ==  SID_BUILDFIREKIT or GetSpellAbilityId() ==  SID_BUILDFBLADE or GetSpellAbilityId() ==  SID_BUILDHSTONE or GetSpellAbilityId() == SID_BUILDKNIFE or GetSpellAbilityId() == SID_BUILDSWARD or GetSpellAbilityId() == SID_BUILDSHARPSTONE or GetSpellAbilityId() == SID_BUILDSFBLADE
endfunction

public function InitTrig takes nothing returns nothing
local trigger trigg = CreateTrigger()
local integer i = 0
loop
    exitwhen i &gt;= 11
        call TriggerRegisterPlayerUnitEvent(trigg, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    endloop
    call TriggerAddCondition(trigg, Condition(function Conditions ) )
    call TriggerAddAction(trigg, function Actions )
endfunction
//==========================================================================
endscope</i></i>


Any help appreciated :)
 

Viikuna

No Marlo no game.
Reaction score
265
If you get that 'false components' -message every time, then
JASS:
if c == t then
this returns false. Use
JASS:
and check those variables. Allways use BJDebugMsg its really usefull and one of those BJ -functions you should not try to avoid.

I hope you can fix it.
 

Heavy-Gear

New Member
Reaction score
7
Hmm.. for the life of me, I can't see what's wrong with it. The total number of components seems to be working fine but the nested loops are going haywire :p

Has anyone had a chance to have a look at it?
 

Tukki

is Skeleton Pirate.
Reaction score
29
Okey, so I took a look at the code and most of it was correct - but the things that were wrong screwed the whole code.
Some notes;

1: The variable "j" is used by the loop which is looped 6 times - but it was not reset - therefor only 1 item was checked.
JASS:
loop
exitwhen i &gt;= 5   //loops inventory slots
    loop
        exitwhen j &gt;= 16  //loops all raw item types
        if GetItemTypeId(UnitItemInSlot(C, i)) == RawItemIID[j] then  
            set RawItem[j] = RawItem[j] + 1 
        endif  
        if RawItem[j] == RawItemNeeded[j] and RawItemNeeded[j] != 0 then  //checks if there is enough of that item
            set c = c + 1 
        endif
        set j = j + 1     
    endloop   
set j = 0 // this was forgotten
set i = i + 1
endloop

2: And some of your "if/then/else" conditions were scary..
JASS:
        if GetItemTypeId(UnitItemInSlot(C, i)) == RawItemIID[j] then  
            set RawItem[j] = RawItem[j] + 1 
        endif  
        if RawItem[j] == RawItemNeeded[j] and RawItemNeeded[j] != 0 then  //checks if there is enough of that item
            set c = c + 1 
        endif
so I replaced them with another one (2)
JASS:
        if GetItemTypeId(UnitItemInSlot(C, i)) == RawItemIID[j] then  
            set Item =  UnitItemInSlot(C, i)
            if RawItemNeeded[j] &gt; 0 and GetItemTypeId(Item) == RawItemIID[j] then
                set DestroyItems<i> = Item
                set RawItemNeeded[j] = RawItemNeeded[j] - 1
                set c = c + 1
            endif
        endif</i>


3 and 4: Your "Remove Item" loop didn't work correctly - so it has also been fixed. And there are actually 6 item slots not 5.
But everything else was okey - only a small effiency (I hope) improvement by using textmacros to set your variables so you don't do it every time to run the trigger.

Here's the trigger script if you would like to have it.

JASS:
//! textmacro SetCraftTriggerData

set RawItemIID[0]  = &#039;I002&#039; //Stone                   
set RawItemIID[1]  = &#039;I000&#039; //Vine                    
set RawItemIID[2]  = &#039;I00B&#039; //Flint                    
set RawItemIID[3]  = &#039;I00G&#039; //LargeBone               
set RawItemIID[4]  = &#039;I003&#039; //Shell                   
set RawItemIID[5]  = &#039;I00F&#039; //SmallBone               
set RawItemIID[6]  = &#039;I004&#039; //SoulStone               
set RawItemIID[7]  = &#039;I001&#039; //Stick                   
set RawItemIID[8]  = &#039;I007&#039; //FlintBlade              
set RawItemIID[9]  = &#039;I008&#039; //StrongFlintBlade        
set RawItemIID[10] = &#039;I00J&#039; //Merrentill     
set RawItemIID[11] = &#039;I00K&#039; //Sungrass       
set RawItemIID[12] = &#039;I00L&#039; //Gnollsleaf     
set RawItemIID[13] = &#039;I00M&#039; //Avantoe        
set RawItemIID[14] = &#039;I00N&#039; //Gnomeswood
set RawItemIID[15] = &#039;I006&#039; //Knife        
set RawItemIID[16] = &#039;I005&#039; //Hammerstone   

//! endtextmacro

scope CraftTrigger
//==========================================================================
globals
    
    // Toolcraft Abilities
    private constant integer SID_BUILDARROW = &#039;A00E&#039;
    private constant integer SID_BUILDAWARD = &#039;A00J&#039;
    private constant integer SID_BUILDFIREKIT = &#039;A005&#039;
    private constant integer SID_BUILDFBLADE = &#039;A00F&#039;
    private constant integer SID_BUILDHSTONE = &#039;A00K&#039;
    private constant integer SID_BUILDKNIFE = &#039;A00G&#039;
    private constant integer SID_BUILDSWARD = &#039;A00H&#039;
    private constant integer SID_BUILDSHARPSTONE = &#039;A007&#039;
    private constant integer SID_BUILDSFBLADE = &#039;A00I&#039;   
    // Toolcraft Items
    private constant integer IID_ARROW = &#039;I00D&#039;
    private constant integer IID_AWARD = &#039;I00E&#039;
    private constant integer IID_FIREKIT = &#039;I00A&#039;
    private constant integer IID_FBLADE = &#039;I007&#039;
    private constant integer IID_HSTONE = &#039;I005&#039;
    private constant integer IID_KNIFE = &#039;I006&#039;
    private constant integer IID_SWARD = &#039;I00C&#039;
    private constant integer IID_SHARPSTONE = &#039;I009&#039;
    private constant integer IID_SFBLADE = &#039;I008&#039;
    
    private integer array RawItemIID
    
endglobals
//==========================================================================
private function Actions takes nothing returns nothing
local item Item 
local item    array DestroyItems

local integer array RawItem
local integer array RawItemNeeded
                       
local unit C = GetSpellAbilityUnit()

local integer I
local integer c = 0             
local integer t = 0    
local integer i = 0   
local integer j = 0    
      
local integer stones = 0                    
local integer vines = 0                     
local integer flint = 0                      
local integer largebones = 0              
local integer shells = 0                    
local integer smallbones = 0                
local integer soulstones = 0                
local integer sticks = 0                     
local integer flintblades = 0              
local integer strongflintblades = 0          
local integer merrentill = 0                 
local integer sungrass = 0                
local integer gnollsleaf = 0                 
local integer avantoe = 0                   
local integer gnomeswood = 0    
local integer knifereq = 0                     
local integer hammerreq = 0    

if GetSpellAbilityId() == SID_BUILDARROW then
    set sticks = 1
    set shells = 1
    set knifereq = 1
    set I = IID_ARROW
    set t = 3
endif 
if GetSpellAbilityId() == SID_BUILDAWARD then 
    set sticks = 1
    set stones = 1
    set vines = 1
    set flint = 1
    set soulstones = 1
    set knifereq = 1
    set I = IID_AWARD
    set t = 6
endif 
if GetSpellAbilityId() == SID_BUILDFIREKIT then 
    set sticks = 1
    set stones = 2
    set knifereq = 1
    set I = IID_FIREKIT
    set t = 4
endif 
if GetSpellAbilityId() == SID_BUILDFBLADE then 
    set flint = 1
    set hammerreq = 1
    set I = IID_FBLADE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDHSTONE then 
    set stones = 2
    set I = IID_HSTONE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDKNIFE then 
    set flintblades = 1
    set vines = 1
    set I = IID_KNIFE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDSWARD then 
    set sticks = 1
    set stones = 1
    set vines = 1
    set flint = 1
    set soulstones = 1
    set knifereq = 1
    set I = IID_SWARD
    set t = 6
endif 
if GetSpellAbilityId() == SID_BUILDSHARPSTONE then 
    set stones = 1
    set knifereq = 1
    set I = IID_SHARPSTONE
    set t = 2
endif 
if GetSpellAbilityId() == SID_BUILDSFBLADE then 
    set flint = 1
    set hammerreq = 1
    set I = IID_SFBLADE
    set t = 2    
endif   
                           
set RawItemNeeded[0]  = stones
set RawItemNeeded[1]  = vines
set RawItemNeeded[2]  = flint
set RawItemNeeded[3]  = largebones
set RawItemNeeded[4]  = shells
set RawItemNeeded[5]  = smallbones
set RawItemNeeded[6]  = soulstones
set RawItemNeeded[7]  = sticks
set RawItemNeeded[8]  = flintblades
set RawItemNeeded[9]  = strongflintblades
set RawItemNeeded[10] = merrentill
set RawItemNeeded[11] = sungrass
set RawItemNeeded[12] = gnollsleaf
set RawItemNeeded[13] = avantoe
set RawItemNeeded[14] = gnomeswood
set RawItemNeeded[15] = knifereq
set RawItemNeeded[16] = hammerreq

loop
exitwhen i &gt; 5   //loops inventory slots (there are actually 6 of them <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)   
  
    loop
        exitwhen j &gt;= 16  //loops all raw item types (with the correct conditions)
        if GetItemTypeId(UnitItemInSlot(C, i)) == RawItemIID[j] then  
            set Item =  UnitItemInSlot(C, i)
            if RawItemNeeded[j] &gt; 0 and GetItemTypeId(Item) == RawItemIID[j] then
                set DestroyItems<i> = Item
                set RawItemNeeded[j] = RawItemNeeded[j] - 1
                set c = c + 1
            endif
        endif
        set j = j + 1     
    endloop
set j = 0
set i = i + 1
endloop

set i = 0
set j = 0

if c == t then    
    loop
    exitwhen i &gt; 5 // destroys all items in the DestroyItems array
        call RemoveItem(DestroyItems<i>)
    set i = i + 1
    endloop
    
    call UnitAddItem(C, CreateItem(I, GetUnitX(C), GetUnitY(C)))
else
    call DisplayTimedTextToPlayer(GetOwningPlayer(C), 0.52, -1, 10, &quot;|CFFFF0000ERROR: Missing requirements!|r&quot;) // replaced X/Y values and added |CFFFF0000 &lt;- red to the string
endif

endfunction

//==========================================================================
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SID_BUILDARROW or GetSpellAbilityId() ==  SID_BUILDAWARD or GetSpellAbilityId() ==  SID_BUILDFIREKIT or GetSpellAbilityId() ==  SID_BUILDFBLADE or GetSpellAbilityId() ==  SID_BUILDHSTONE or GetSpellAbilityId() == SID_BUILDKNIFE or GetSpellAbilityId() == SID_BUILDSWARD or GetSpellAbilityId() == SID_BUILDSHARPSTONE or GetSpellAbilityId() == SID_BUILDSFBLADE
endfunction

public function InitTrig takes nothing returns nothing
local trigger trigg = CreateTrigger()
local integer i = 0
loop
    exitwhen i &gt;= 11
        call TriggerRegisterPlayerUnitEvent(trigg, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    endloop
    call TriggerAddCondition(trigg, Condition(function Conditions ) )
    call TriggerAddAction(trigg, function Actions )
    //! runtextmacro SetCraftTriggerData()
endfunction
//==========================================================================
endscope</i></i>


Hope it helped :)
 

Heavy-Gear

New Member
Reaction score
7
Yay!

Not reseting the 'j' looked like the major error. Thanks for all your help, it works great! The only thing I had to change was that it shouldn't remove knives/hammerstones but other than that it's perfect.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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