| 09-28-2006, 08:20 PM | #1 |
Basically, I'm trying to get a trigger that works for ANY unit. This trigger is something like a swamp: If a unit enters it 3 times, they die. I'm using JASS for this, because you have to use local variables. However, how can you store a non-local variable for every unit? This is what I have so far (if the script confuses you, just read everything else): JASS:function Trig_Swamp_Death_Func001C takes nothing returns boolean if ( not ( udg_a == 3 ) ) then // It can be udg or non_udg, I don't care. return false endif return true endfunction function Trig_Swamp_Death_Actions takes nothing returns nothing if ( Trig_Swamp_Death_Func001C() ) then call KillUnit( GetTriggerUnit() ) else call DoNothing( ) endif endfunction If you don't understand, here is what I'm trying to do: -if ANY unit at all enters a swamp 3 times it dies However, how can I get a variable that stores an integer (to check if the integer for the unit = 3) if I'm using local? If I don't use local variables, I can't use this trigger for ANY unit. I'm confused...any help will be appreciated. Thanks ![]() |
| 09-28-2006, 08:22 PM | #2 |
You need to use one of these: - Dynamic arrays. - Custom unit values (may overlap with others). - Game cache + return bug. |
| 09-28-2006, 08:46 PM | #3 |
Um...okay...what are dynamic arrays? And how should I use custom unit values to help me with this? |
| 09-28-2006, 08:52 PM | #4 |
JASS:Call StoreInteger(udg_gc,<Custom-Value>,"CurrentInteger",x) JASS:set x = GetStoredInteger(udg_gc,<Custom-Value>,"CurrentInteger") |
| 09-28-2006, 08:53 PM | #5 |
My first idea would be Return bug + Game Cache, simple and i just like it. JASS:globals gamecache udg_GC = null endglobals // Dont write the above, its just to show what globals you need function GC takes nothing returns gamecache if(udg_GC==null)then call FlushGameCache(InitGameCache("GC")) set udg_GC = InitGameCache("GC") endif return udg_GC endfunction function H2I takes handle H returns integer return H return 0 endfunction function Trig_Swamp_Death_Actions takes nothing returns nothing local gamecache GC = GC() local unit TU = GetTriggerUnit() local string TUS = I2S(H2I(TU)) local integer UnitInTimes = GetStoredInteger(GC, TUS, "SwampEnterTimes") if(UnitInTimes>=3) then call KillUnit(TU) else call StoreInteger(GC, TUS, "SwampEnterTimes", UnitInTimes+1) endif set GC = null set TU = null endfunction All you need it a gamecache called GC (or udg_GC for Jass). Then it should store the units Id's in the cache along with the amount of times its entered, then get it back later. |
| 09-29-2006, 12:26 AM | #6 |
So I basically make a global variable called GC as a game cache (using the World Editor's Variable Editor to make it global?) and copy what Tidehunter did? Ok thanks everyone... EDIT: If I'm using Tidehunter's code...what do I need? Just a global variable GC (game cache) and a region called Swamp? |
| 09-29-2006, 12:46 AM | #7 |
The trigger would need to be named Swamp Death. Make a region named whatever you want, and a gamecache variable named GC just like you said. Make an event in the trigger for unit enters region "Swamp". Then convert your trigger to JASS and copy his stuff in above the event //============================== |
| 09-29-2006, 06:57 AM | #8 | |
Quote:
Just a gamecache called GC, and a trigger that would be a event like "A unit enters a region", A unit comes in range, etc, because it uses GetTriggerUnit() Aslong as the event has a GetTriggerUnit response, it should work fine, use the bottom function i showed you (which was yours in the first place) as the triggers actions. |
| 10-01-2006, 04:39 PM | #9 |
Ok, thanks everyone. +rep |
