- Joined
- Nov 30, 2007
- Messages
- 1,202
The variable udg_Town_resource_cur[] is not increasing???
udg_Town_resource_cap[] = 100 by default.
and udg_Town_resource_prod[900] = 25
so at the end of thee trigger I should be given The variable udg_Town_resource_cur[900] = 25 and next cycle 50... and when it crosses 100 it shouldn't increase anymore, but for some reason it doesn't work?
There is currently only 1 unit in the Town_gr and its custom value is 0.
Can I not set integers inside a picked unit group function?
Here is the setup:
udg_Town_resource_cap[] = 100 by default.
and udg_Town_resource_prod[900] = 25
so at the end of thee trigger I should be given The variable udg_Town_resource_cur[900] = 25 and next cycle 50... and when it crosses 100 it shouldn't increase anymore, but for some reason it doesn't work?
There is currently only 1 unit in the Town_gr and its custom value is 0.
Can I not set integers inside a picked unit group function?
JASS:
function GetTownGroup takes nothing returns nothing
local integer unit_d = GetUnitUserData(GetEnumUnit())
local integer player_i = GetConvertedPlayerId(GetOwningPlayer(GetEnumUnit()))
local integer x = udg_Town_array_multiplier // x = 300
local integer z = udg_Player_array_multiplier // z = 15
local integer i = 0
local integer waste
// Takes the produced resource and adds it to the current resource variable.
// Array; Town 0-299 Gold, 300-599 Lumber, 600-899 Iron, 900-1199 Food, 1200-1499 Recruits, 1500-1799 Weapons
// Above is used for production and local resource.
//
// Array; Player 0-14 Gold, 15-29 Lumber, 30-44 Iron 45-59 Food, 60-74 Recruits, 75-89.
// Above is used for global resources and counting.
loop
exitwhen i > 5
if i < 3 then
//Global Resources
set udg_Player_resources[player_i + i * z] = udg_Player_resources[player_i + i * z] + udg_Town_resource_prod[unit_d + i * x]
else
//Local Resources
if (udg_Town_resource_prod[unit_d + i * x] + udg_Town_resource_cur[unit_d + i * x]) < udg_Town_resource_cap[unit_d + i * x] then
// Cap not breached
set udg_Town_resource_cur[unit_d + i * x] = udg_Town_resource_cur[unit_d + i * x] + udg_Town_resource_prod[unit_d + i * x]
else
// Cap breached
set waste = udg_Town_resource_prod[unit_d + i * x] + udg_Town_resource_cur[unit_d + i * x] - udg_Town_resource_cap[unit_d + i * x]
set udg_Town_resource_cur[unit_d + i * x] = udg_Town_resource_prod[unit_d + i * x] - waste
endif
endif
set i = i + 1
endloop
endfunction
function Trig_Give_Actions takes nothing returns nothing
set udg_Town_resource_prod[900] = 25
call ForGroupBJ( udg_Town_gr, function GetTownGroup)
call BJDebugMsg("Current food: " + I2S(udg_Town_resource_cur[3 * 300]))
call BJDebugMsg("Produced food: " + I2S(udg_Town_resource_prod[3 * 300]))
endfunction
//===========================================================================
function InitTrig_Give_Resources takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 10.00)
call TriggerAddAction(t, function Trig_Give_Actions)
set t = null
endfunction
Here is the setup:
-
Setup
-
Events
- Map initialization
- Conditions
-
Actions
- Custom script: local integer i = 0
- Set Town[0] = Town Hall 0000 <gen>
- Set Town[1] = Town Hall 0002 <gen>
- Custom script: loop
- Custom script: exitwhen i > 1
- Custom script: set udg_Town_alive[i] = true
- Custom script: call SetUnitUserData(udg_Town[i], i)
- Custom script: call GroupAddUnitSimple(udg_Town[i], udg_Town_gr)
- Custom script: set i = i + 1
- Custom script: endloop
-
Events
Last edited: