| 10-30-2006, 01:36 AM | #1 |
I've tested a lot of time and I don't understand why this dosen't work... I want to make my trigger so you need a certain type and number of items in your inventory to build the structure. JASS:function Trig_Buildings_Requirements_Materials_Actions takes nothing returns nothing local unit Structure = GetConstructingStructure() local unit Builder = GetTriggerUnit() local integer Wood local integer Stone local integer Copper_Ore local integer Copper_Bar local integer Iron_Ore local integer Iron_Bar local integer LoopA local integer LoopAEND local integer LoopB local integer LoopBEND if GetUnitTypeId( Structure ) == 'u000' then set LoopA = 1 set LoopAEND = 6 loop exitwhen LoopA > LoopAEND if GetItemTypeId( UnitItemInSlot( Builder, LoopA - 1 )) == udg_wood then set Wood = Wood + 1 endif set LoopA = LoopA + 1 endloop if Wood >= 3 then set LoopB = 1 set LoopBEND = 3 loop exitwhen LoopB > LoopBEND call RemoveItem( GetItemOfTypeFromUnitBJ( Builder, udg_wood )) set LoopB = LoopB + 1 endloop else call SimError( GetOwningPlayer( Builder ), "You don't have the required materials." ) call IssueImmediateOrder( Builder, "stop" ) call RemoveUnit( Structure ) endif endif set Structure = null set Builder = null endfunction |
| 10-30-2006, 05:51 AM | #2 |
JASS:function Trig_Buildings_Requirements_Materials_Actions takes nothing returns nothing local unit Structure = GetConstructingStructure() local unit Builder = GetTriggerUnit() local integer Wood local integer i = 0 if GetUnitTypeId( Structure ) == 'u000' then loop exitwhen i > 5 if GetItemTypeId( UnitItemInSlot( Builder, i )) == udg_wood then set Wood = Wood + 1 endif set i = i + 1 endloop if Wood > 2 then set i = 0 loop exitwhen i > 2 call RemoveItem( GetItemOfTypeFromUnitBJ( Builder, udg_wood )) set i = i + 1 endloop else call SimError( GetOwningPlayer( Builder ), "You don't have the required materials." ) call IssueImmediateOrder( Builder, "stop" ) call RemoveUnit( Structure ) endif endif set Structure = null set Builder = null endfunction To fix your problem, we need a bit more info. Does it do anything at all? What's the event? |
| 10-30-2006, 10:11 AM | #3 |
Try setting all your integers to zero when their created as locals. I think I heard somewhere you need to do that for it to work correctly, but maybe I'm wrong. I don't think it would hurt to do it anyways. |
| 10-30-2006, 10:42 AM | #4 |
If you don't give your variables a value, what the hell are they supposed to be? Declare them -.- |
| 10-30-2006, 11:40 AM | #5 |
you don't need LoopEnd variables if they aren't going to change |
| 10-30-2006, 08:35 PM | #6 |
I declared the variables and changed the trigger a bit but it still dosen't work... I would like so when my unit start building a structure, the trigger check if the unit own specific items. If the unit don't it call an Error message. If the unit own the specific items, it removes the item of the unit. JASS:function Trig_Buildings_Requirements_Materials_Actions takes nothing returns nothing local unit Structure = GetConstructingStructure() local unit Builder = GetTriggerUnit() local integer Wood = 0 local integer Stone = 0 local integer Copper_Ore = 0 local integer Copper_Bar = 0 local integer Iron_Ore = 0 local integer Iron_Bar = 0 local integer i = 0 if GetUnitTypeId( Structure ) == 'u000' then call BJDebugMsg( "Well... It works but it dosen't at the same time...") set i = 1 loop exitwhen i > 6 if GetItemTypeId( UnitItemInSlot( Builder, i - 1 )) == udg_wood then set Wood = Wood + 1 endif set i = i + 1 set Wood = Wood + 1 endloop set i = 0 if Wood >= 3 then set i = 1 loop exitwhen i > 3 call RemoveItem( GetItemOfTypeFromUnitBJ( Builder, udg_wood )) set i = i + 1 endloop elseif Wood < 3 then call SimError( GetOwningPlayer( Builder ), "You don't have the required materials." ) call IssueImmediateOrder( Builder, "stop" ) call RemoveUnit( Structure ) endif endif set Structure = null set Builder = null endfunction |
| 10-31-2006, 03:18 AM | #7 |
No sense in setting i=0 and then immediately setting it back to i=1. Also no reason to set i=1 in your first loop and then check item slot i-1. You should just leave it as 0 and check item slot i. Also, ( if Wood >= 3 ) is always going to be true because you are setting wood = wood +1 outside of your if statement in the first loop. You need to remove that line. I'm also wondering why you are declaring variables that aren't ever used such as copper, iron, and stone. I'm not sure exactly how the rest of your trigger is supposed to work, but change what you gave to us to this code: JASS:function Trig_Buildings_Requirements_Materials_Actions takes nothing returns nothing local unit Structure = GetConstructingStructure() local unit Builder = GetTriggerUnit() local integer Wood = 0 local integer i = 0 if GetUnitTypeId( Structure ) == 'u000' then loop exitwhen i>5 if GetItemTypeId(UnitItemInSlot(Builder,i))==udg_wood then set Wood=Wood+1 exitwhen Wood>=3 endif set i=i+1 endloop if Wood>=3 then set i=0 loop exitwhen i>5 if GetItemTypeId(UnitItemInSlot(Builder,i))==udg_wood then call RemoveItem(UnitItemInSlot(Builder,i)) set Wood=Wood-1 exitwhen Wood<=0 endif set i=i+1 endloop else call SimError(GetOwningPlayer(Builder),"You don't have the required materials.") call IssueImmediateOrder(Builder,"stop") call RemoveUnit(Structure) endif endif set Structure=null set Builder=null endfunction |
| 11-02-2006, 08:48 PM | #8 |
Well, the variable not declared here will be used for other kinds of building. And Thank you for your help but it still dosen't work. Each time the trigger run, it always do "else, call SimError" etc... Not the "If GetItemTypeId" (The second loop). |
| 11-04-2006, 04:24 AM | #9 |
There's no reason it shouldn't be working as long as you have 3 udg_wood items in your inventory. Did you make sure that udg_wood is declared correctly elsewhere? Also, if it's a charged item (stacked in one slot), then the trigger needs to be done differently. The is checking for 3 or more item slots of udg_wood. |
