• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] System Problem

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I was making a resource system. But it doesn't work. It should remove item charges when building a building( in other words, it makes building cost item charges). Can anyone help? Thanks!

JASS:
//Made by Destroyer95
//
//
//              
//               
//                
//               
//              


library Resource

globals

    integer array BUILDING
    integer array RESOURCE1_COST
    integer array RESOURCE2_COST
    integer array RESOURCE3_COST
    integer array RESOURCE_ITEMS
    
endglobals

function SetBuildingCost takes integer buildingNumber, integer buildingRawcode, integer res1Cost, integer res2Cost, integer res3Cost returns nothing
    set BUILDING[buildingNumber] = buildingRawcode
    set RESOURCE1_COST[buildingNumber] = res1Cost
    set RESOURCE2_COST[buildingNumber] = res2Cost
    set RESOURCE3_COST[buildingNumber] = res3Cost
endfunction

function SetupItemRawcodes takes integer item1Rawcode, integer item2Rawcode, integer item3Rawcode returns nothing
    set RESOURCE_ITEMS[1] = item1Rawcode
    set RESOURCE_ITEMS[2] = item2Rawcode
    set RESOURCE_ITEMS[3] = item3Rawcode
endfunction

function UnitStartsBuilding takes nothing returns nothing
    local unit structure = GetTriggerUnit()
    local unit builder = GetOrderedUnit() 
    local boolean array bo
    local integer id = UnitId( OrderId2StringBJ( GetIssuedOrderId() ) ) 
    local integer count = 0
    local integer index = 0
    local item array indexItem

    if id != null then
        loop 
            exitwhen id == BUILDING[count] or count == 8191
            if id != BUILDING[count] then
                set count = count + 1
            endif
        endloop
    endif
    if RESOURCE1_COST[count] != 0 then
        loop
            set indexItem[1] = UnitItemInSlot(builder, index)
            if (indexItem[1] != null) and (GetItemTypeId(indexItem[1]) == RESOURCE_ITEMS[1]) then
                if GetItemCharges(indexItem[1]) >= RESOURCE1_COST[count] then
                    set bo[1] = true
                endif
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[1] == true
        endloop
        else
            set bo[1] = true
    endif
        
        
    if RESOURCE2_COST[count] != 0 then
        loop
            set indexItem[2] = UnitItemInSlot(builder, index)
            if (indexItem[2] != null) and (GetItemTypeId(indexItem[2]) == RESOURCE_ITEMS[2]) then
                if GetItemCharges(indexItem[2]) >= RESOURCE2_COST[count] then
                    set bo[2] = true
                endif
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[2] == true
       endloop
       else
           set bo[2] = true
    endif
    
        
    if RESOURCE3_COST[count] != 0 then
        loop
            set indexItem[3] = UnitItemInSlot(builder, index)
            if (indexItem[3] != null) and (GetItemTypeId(indexItem[3]) == RESOURCE_ITEMS[3]) then
                if GetItemCharges(indexItem[3]) >= RESOURCE3_COST[count] then
                    set bo[3] = true
                endif
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[3] == true
        endloop
        else
            set bo[3] = true
    endif
        
    if bo[1] == true and bo[2] == true and bo[3] == true then
        call SetItemCharges(indexItem[1], GetItemCharges(indexItem[1]) - RESOURCE1_COST[count])
        call SetItemCharges(indexItem[2], GetItemCharges(indexItem[2]) - RESOURCE2_COST[count])
        call SetItemCharges(indexItem[3], GetItemCharges(indexItem[3]) - RESOURCE3_COST[count])
        else
            call KillUnit(structure)
    endif
        
    set structure = null
    set builder = null
    set indexItem[1] = null
    set indexItem[2] = null
    set indexItem[3] = null
    
endfunction
    
function Trig_ResourceSystem_Conditions takes nothing returns boolean
    return GetIssuedOrderId() == String2OrderIdBJ("build")
endfunction
    
function InitTrig_Resource_System takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, Condition( function Trig_ResourceSystem_Conditions ) )
    call TriggerAddAction(t, function UnitStartsBuilding)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
endfunction

endlibrary
 

Attachments

  • Resource System.w3x
    19.9 KB · Views: 83
Level 16
Joined
Mar 3, 2006
Messages
1,564
I have separated the triggers into two as this:

JASS:
library L initializer init
globals
    integer array BUILDING
    integer array RESOURCE1_COST
    integer array RESOURCE2_COST
    integer array RESOURCE3_COST
    integer array RESOURCE_ITEMS
 
endglobals
function SetBuildingCost takes integer buildingNumber, integer buildingRawcode, integer res1Cost, integer res2Cost, integer res3Cost returns nothing
     call BJDebugMsg("Building # = " + I2S(buildingNumber))
    set BUILDING[buildingNumber] = buildingRawcode
     call BJDebugMsg("Building: " + I2S(BUILDING[buildingNumber]))
    set RESOURCE1_COST[buildingNumber] = res1Cost
     call BJDebugMsg("Res1 cost = " + I2S(RESOURCE1_COST[buildingNumber]))
    set RESOURCE2_COST[buildingNumber] = res2Cost
     call BJDebugMsg("Res2 cost = " + I2S(RESOURCE2_COST[buildingNumber]))
    set RESOURCE3_COST[buildingNumber] = res3Cost
     call BJDebugMsg("Res3 cost = " + I2S(RESOURCE3_COST[buildingNumber]))
endfunction
function SetupItemRawcodes takes integer item1Rawcode, integer item2Rawcode, integer item3Rawcode returns nothing
    set RESOURCE_ITEMS[1] = item1Rawcode
    set RESOURCE_ITEMS[2] = item2Rawcode
    set RESOURCE_ITEMS[3] = item3Rawcode
endfunction
    function init takes nothing returns nothing
        call SetupItemRawcodes('I000', 'I001', 'I002')
        call SetBuildingCost(1, 'hhou', 2, 1, 0)
        call SetBuildingCost(2, 'hbar', 4, 0, 3)
    endfunction
endlibrary

This now works fine, the problem is in the Build trigger.

JASS:
//Made by Destroyer95
//
function UnitStartsBuilding takes nothing returns nothing
    local unit structure = GetTriggerUnit()
    local unit builder = GetOrderedUnit()
    local boolean array bo
    local integer id = UnitId( OrderId2StringBJ( GetIssuedOrderId() ) ) 
    local integer count = 0
    local integer index = 0
    local item array indexItem
    call BJDebugMsg("function UnitStartsBuilding() is running")
    if id != null then
        loop 
            exitwhen id == BUILDING[count] or count == 8191
            if id != BUILDING[count] then
                set count = count + 1
            endif
        endloop
    endif
    if RESOURCE1_COST[count] != 0 then
        loop
            set indexItem[1] = UnitItemInSlot(builder, index)
            if (indexItem[1] != null) and (GetItemTypeId(indexItem[1]) == RESOURCE_ITEMS[1]) then
                if GetItemCharges(indexItem[1]) >= RESOURCE1_COST[count] then
                    set bo[1] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[1] == true
        endloop
        else
            set bo[1] = true
    endif
 
 
    if RESOURCE2_COST[count] != 0 then
        loop
            set indexItem[2] = UnitItemInSlot(builder, index)
            if (indexItem[2] != null) and (GetItemTypeId(indexItem[2]) == RESOURCE_ITEMS[2]) then
                if GetItemCharges(indexItem[2]) >= RESOURCE2_COST[count] then
                    set bo[2] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[2] == true
       endloop
       else
           set bo[2] = true
    endif
 
 
    if RESOURCE3_COST[count] != 0 then
        loop
            set indexItem[3] = UnitItemInSlot(builder, index)
            if (indexItem[3] != null) and (GetItemTypeId(indexItem[3]) == RESOURCE_ITEMS[3]) then
                if GetItemCharges(indexItem[3]) >= RESOURCE3_COST[count] then
                    set bo[3] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[3] == true
        endloop
        else
            set bo[3] = true
    endif
 
    if bo[1] == true and bo[2] == true and bo[3] == true then
        call SetItemCharges(indexItem[1], GetItemCharges(indexItem[1]) - RESOURCE1_COST[count])
        call SetItemCharges(indexItem[2], GetItemCharges(indexItem[2]) - RESOURCE2_COST[count])
        call SetItemCharges(indexItem[3], GetItemCharges(indexItem[3]) - RESOURCE3_COST[count])
        else
            call KillUnit(structure)
    endif
 
    set structure = null
    set builder = null
    set indexItem[1] = null
    set indexItem[2] = null
    set indexItem[3] = null
 
endfunction
 
function Trig_ResourceSystem_Conditions takes nothing returns boolean
    return GetIssuedOrderId() == String2OrderIdBJ("build")
endfunction
 
function Build takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, Condition( function Trig_ResourceSystem_Conditions ) )
    call TriggerAddAction(t, function UnitStartsBuilding)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
endfunction

I have added a function which is call BJDebugMsg("function UnitStartsBuilding() is running") and no message displayed, there is something wrong and I am working on finding it.
 
Level 10
Joined
May 19, 2008
Messages
176
Dude it's the condition... When a unit start construction the condition is false. @Starquizer look at my upper post. You can't get the unit which builds. You need a work around, and I have an idea how I can do this. But I do it only when its really important...

cedi
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Dude it's the condition... When a unit start construction the condition is false. @Starquizer look at my upper post. You can't get the unit which builds. You need a work around, and I have an idea how I can do this. But I do it only when its really important...

cedi

I think not because I disabled the condition and still not working.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
I've changed a few things. The first trigger is the same but for the second condition is now working but still a problem with the actions.


JASS:
library K initializer Build  //Add initializer keyword
//Made by Destroyer95
//
function UnitStartsBuilding takes nothing returns nothing
    local unit structure = GetTriggerUnit()
    local unit builder = GetOrderedUnit()
    local boolean array bo
    local integer id = UnitId( OrderId2StringBJ( GetIssuedOrderId() ) ) 
    local integer count = 0
    local integer index = 0
    local item array indexItem
    call BJDebugMsg("function UnitStartsBuilding() is running")
    if id != null then
        loop 
            exitwhen id == BUILDING[count] or count == 8191
            if id != BUILDING[count] then
                set count = count + 1
            endif
        endloop
    endif
    if RESOURCE1_COST[count] != 0 then
        loop
            set indexItem[1] = UnitItemInSlot(builder, index)
            if (indexItem[1] != null) and (GetItemTypeId(indexItem[1]) == RESOURCE_ITEMS[1]) then
                if GetItemCharges(indexItem[1]) >= RESOURCE1_COST[count] then
                    set bo[1] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[1] == true
        endloop
        else
            set bo[1] = true
    endif
 
 
    if RESOURCE2_COST[count] != 0 then
        loop
            set indexItem[2] = UnitItemInSlot(builder, index)
            if (indexItem[2] != null) and (GetItemTypeId(indexItem[2]) == RESOURCE_ITEMS[2]) then
                if GetItemCharges(indexItem[2]) >= RESOURCE2_COST[count] then
                    set bo[2] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[2] == true
       endloop
       else
           set bo[2] = true
    endif
 
 
    if RESOURCE3_COST[count] != 0 then
        loop
            set indexItem[3] = UnitItemInSlot(builder, index)
            if (indexItem[3] != null) and (GetItemTypeId(indexItem[3]) == RESOURCE_ITEMS[3]) then
                if GetItemCharges(indexItem[3]) >= RESOURCE3_COST[count] then
                    set bo[3] = true
                endif
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY or bo[3] == true
        endloop
        else
            set bo[3] = true
    endif
 
    if bo[1] == true and bo[2] == true and bo[3] == true then
        call SetItemCharges(indexItem[1], GetItemCharges(indexItem[1]) - RESOURCE1_COST[count])
        call SetItemCharges(indexItem[2], GetItemCharges(indexItem[2]) - RESOURCE2_COST[count])
        call SetItemCharges(indexItem[3], GetItemCharges(indexItem[3]) - RESOURCE3_COST[count])
        else
            call KillUnit(structure)
    endif
 
    set structure = null
    set builder = null
    set indexItem[1] = null
    set indexItem[2] = null
    set indexItem[3] = null
 
endfunction
 
function Cond takes nothing returns boolean
     call BJDebugMsg("Conditions On")
    return GetIssuedOrderId() == String2OrderIdBJ("build")
endfunction
 
function Build takes nothing returns nothing  // the name of the function must be the same as that after the initializer keyword
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerAddCondition(t, Condition( function Cond ) )
    call TriggerAddAction(t, function UnitStartsBuilding)
endfunction
endlibrary


still something in the actions is wrong that is eluding me.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
There is a problem I found with issued order "build"; it isn't working.

Try this and it won't work.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Issued order) Equal to (==) (Order(build))
    • Actions
      • Game - Display to (All players) the text: Working
Note that I did that with JNGP with UMSWE enabled.
 
Last edited:
Level 16
Joined
Mar 3, 2006
Messages
1,564
No, that is not the problem.

After an intensive work and search, I found that there is no "build" order.

Although Destroyer95 script contains some errors in the action function but there is more problem that concerned me; which is the order ID.

I attached a map to get building orders it may help him much (I hope).
 

Attachments

  • order_test.w3x
    19.9 KB · Views: 35
Status
Not open for further replies.
Top