| 10-15-2006, 11:39 PM | #1 |
what are some ways to destroy the last created building owned by a player? Should i just make a huge unit array? Replies are greatly appreciated |
| 10-16-2006, 12:49 AM | #2 |
You'll have to be more specific because I'm assuming that you mean the last building that a player constructs. In that case, create a gamecache variable, add a function to initialize it, then create a trigger and use code similar to this. Just call your GetPlayerLastBuilding( player p ) function when you want to get the last constructed building for a player. JASS:function H2I takes handle h returns integer return h return 0 endfunction function GetPlayerLastBuilding takes player p returns unit return GetStoredUnit( udg_myGameCache, I2S(H2I(p)), "LastBuilding" ) endfunction function StorePlayerBuilding takes nothing returns nothing call StoreUnit( udg_myGameCache, I2S(H2I(GetOwningPlayer(GetConstructedStructure()))), "LastBuilding", GetConstructedStructure() ) endfunction function InitTrig_StoreBuilding takes nothing returns nothing set gg_trg_StoreBuilding = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( gg_trg_StoreBuilding, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH ) call TriggerAddAction( gg_trg_StoreBuilding, function StorePlayerBuilding ) endfunction |
| 10-16-2006, 06:34 AM | #3 |
What is that? There's no function named GetStoredUnit(). You probably meant to use RestoreUnit(), but that still leaves us with the problem that these functions don't do what you think they do. Using gamecache is a bit of an overkill anyway. You could just make a unit array named lastConstructedBuilding or something like that and then, whenever a building is constructed, store it to that array under an index equal to the player number of the controling player. |
| 10-16-2006, 12:53 PM | #4 |
Oh, I did mean RestoreUnit(), the other functions follow the "GetStored..." format, so I didn't even think when I did it. Also what do you mean it doesn't do what I think it does? I only recently discovered that it exists. A unit array is fine, but I was assuming he was somehow opposed to using an array. |
| 10-16-2006, 01:35 PM | #5 |
Restor unit recreates the unit stored before in it. JASS:constant function H2I takes handle h returns integer return h return 0 endfunction function GetPlayerLastBuilding takes player p returns unit return GetStoredInteger( udg_myGameCache,"[LastBuilding]",I2S(GetPlayerId(p))) return null endfunction function StorePlayerBuilding takes nothing returns nothing local string k=I2S(GetPlayerId(GetOwningPlayer(GetConstructedStructure()))) call StoreInteger(udg_myGameCache,"[LastBuilding]",k,H2I(GetConstructedStructure())) endfunction function InitTrig_StoreBuilding takes nothing returns nothing set gg_trg_StoreBuilding = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( gg_trg_StoreBuilding, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH ) call TriggerAddAction( gg_trg_StoreBuilding, function StorePlayerBuilding ) endfunction This should work. EDIT: fixed type, forgot 'key' EDIT: Be beware that you must init the GC correctly, or the hole thing will return incorrect values (handle indices) => possible crash reason |
| 10-16-2006, 02:07 PM | #6 |
JASS:function StorePlayerBuilding takes nothing returns nothing set udg_GetLastConstructed[GetConvertedPlayerId(GetOwningPlayer(GetConstructedStructure()))] = GetConstructedStructure() endfunction function InitTrig_StoreBuilding takes nothing returns nothing set gg_trg_StoreBuilding = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( gg_trg_StoreBuilding, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH ) call TriggerAddAction( gg_trg_StoreBuilding, function StorePlayerBuilding ) endfunction Would be so much easier if he used arrays.. |
| 10-16-2006, 03:08 PM | #7 |
Just use a array ofc... Most simple method, alot faster. Create a array of size 12 and of type Unit. Whenever a unit is constructed, set array[Player number of (Owner of ( Triggering Unit ) ) ] = Constructed unit. The variable should always be the last created unit. |
| 10-17-2006, 10:07 AM | #8 |
That's true, but you waste (8192-(number of playing players))*4 bytes of memory in exchange of a little speed. |
| 10-17-2006, 10:55 AM | #9 |
Or just use some unused BJ array (like bj_ghoul) and waste zero bytes! Yay for minimal optimisation! |
| 10-18-2006, 01:44 AM | #10 |
blu. please get into more detail on how to use this empty array. i dont know jass. just GUI stuff, |
| 10-18-2006, 06:58 AM | #11 |
I'v heard the first 17 ghoul slots are sometimes used, so im working on 18-29 Use: Trigger: And when you want the last created building, use something like Trigger: Actions
![]() Custom script: local unit Structure = bj_ghoul[17 + (Players Number)]But you could also just like: set something = bj_ghoul[number] chart:
18 = Player 1 19 = Player 2 20 = Player 3 21 = Player 4 22 = Player 5 23 = Player 6 24 = Player 7 25 = Player 8 26 = Player 9 27 = Player 10 28 = Player 11 29 = Player 12 |
