- 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