| 09-12-2009, 11:38 AM | #1 |
JASS:library HeroRestrictions initializer Init globals private integer array id private trigger Detect endglobals private function Cond takes nothing returns boolean return GetSellingUnit() == udg_HeroRestrictions endfunction private function Restrict takes nothing returns nothing local item a = GetSoldItem() local integer i = GetItemTypeId(a) local integer l = 0 loop exitwhen l == 3 if i == id[l] then set HeroesRestricted[l] = true if (HeroesRestricted[0] and HeroesRestricted[1] and HeroesRestricted[2]) == false then call RemoveItemFromStock(udg_HeroRestrictions, id[l]) call AddItemToStock(udg_HeroRestrictions, id[l+3],0,1) else set HeroesRestricted[l] = false endif elseif i == id[l+3] then set HeroesRestricted[l] = false call RemoveItemFromStock(udg_HeroRestrictions, id[l+3]) call AddItemToStock(udg_HeroRestrictions, id[l],0,1) endif set l = l + 1 endloop call RemoveItem(a) endfunction private function Init takes nothing returns nothing local integer i = 0 set id[0] = 'I000' set id[1] = 'I001' set id[2] = 'I006' set id[3] = 'I003' set id[4] = 'I004' set id[5] = 'I005' set udg_HeroRestrictions = gg_unit_h009_0032 loop exitwhen i >= 3 call AddItemToStock(udg_HeroRestrictions,id[i],1,1) set HeroesRestricted[i] = false set i = i + 1 endloop set Detect = CreateTrigger() call TriggerRegisterPlayerUnitEvent(Detect,GetOwningPlayer(udg_HeroRestrictions),EVENT_PLAYER_UNIT_SELL_ITEM,null) call TriggerAddAction(Detect, function Restrict) call TriggerAddCondition(Detect, Condition(function Cond)) endfunction endlibrary Basically, when I click my items fast (while buying them in order to trigger the action), suddenly, random items start disappearing on the list. And I don't get why, the only item that should disappear is the one that gets replaced, that is, if I click item "Strength ENABLE" it should remove it from stock, and place another one called "Strength DISABLE". But instead, if I keep clicking fast, random items start disappearing. Is this a bug or am I doing something horribly wrong? Oh, and my code is terrible, I know. |
| 09-13-2009, 10:37 PM | #2 |
I had this same problem a while ago... never did solve it. I think it's something to do with adding items up to the limit (12?) and removing them doesn't actually free up the slot on the building. No idea how to properly add/remove items. Anyone? |
| 09-15-2009, 08:52 PM | #3 |
Add the items to the building at runtime, rather than in the Object Editor. |
| 09-16-2009, 02:16 AM | #4 |
I did, the initialization trigger for system does exactly that (I don't have the map here, but item IDs are in form of private global integers). At 0.01 the function is called to add those items to building, because if I add stuff in object editor, I don't think it's possible to remove it later. The weird thing is that it only happens if you click on items REALLY fast, and it's not LAN/bnet lag, but in singleplayer. |
