| 08-22-2006, 03:31 AM | #3 |
To fix the unit problem, just change your JASS trigger to set all those units to an Integer array loaded at your map initilization. Then make a loop to create all those units and put them in a group. You can then remove them one at a time to place them in your random regions. This way there is no chance of having identical units. JASS:set udg_integer[1] = 'hpea' set udg_integer[2] = 'uabo' set udg_integer[3] = 'ohun' Then for your grouping: JASS:local group g=CreateGroup() local real x=GetRectMinX(bj_mapInitialPlayableArea)-30 local real y=GetRectMinY(bj_mapInitialPlayableArea)-30 local integer i=1 local integer u loop exitwhen i>22 set u = CreateUnit(Player(11),udg_Integer[i]x,y,0) call GroupAddUnit(g,u) set i=i+1 endloop loop set u=GroupPickRandomUnit(g) exitwhen u==null call SetUnitPosition(u,x,y) // or SetUnitPositionLoc if you are using location call GroupRemoveUnit(g,u) endloop call DestroyGroup(g) EDIT someone else posted while I was typing, but I think this method should be best. |
| 08-22-2006, 03:36 AM | #4 |
Well that's a neat trick but it doesn't really help me =P Made it in JASS, works better, but still it forgets to create one or two, and there are still some repeats. This is bugging me alot. JASS:function Trig_Units_Actions takes nothing returns nothing local integer ia=1 local integer ib=1 local integer temp local boolean array filled loop set filled[ia]=false exitwhen ia==22 set ia=ia+1 endloop set ia=1 loop set temp=GetRandomInt(1,22) if filled[temp] then loop if filled[temp]==false then set temp=ib endif exitwhen ib==22 set ib=ib+1 endloop endif set filled[temp]=true call CreateRandomUnit(temp) set udg_Guys[ia]=bj_lastCreatedUnit call SetUnitPositionLoc(udg_Guys[ia],GetRectCenter(udg_Spots[ia])) exitwhen ia==22 set ia=ia+1 endloop endfunction //=========================================================================== function InitTrig_Units takes nothing returns nothing set gg_trg_Units = CreateTrigger( ) call TriggerRegisterPlayerEventEndCinematic( gg_trg_Units, Player(0) ) call TriggerAddAction( gg_trg_Units, function Trig_Units_Actions ) endfunction Can someone please tell me what I could possibly doing wrong!?!?! |
| 08-22-2006, 03:39 AM | #5 |
Use mine . It shouldn't leave any out and there won't be any repeats. It looks like you know enough about JASS to be able to use mine and apply your own stuff. You really don't need to change much except for the SetUnitPostionLocEdit: I did it for you JASS:function Trig_Units_Actions takes nothing returns nothing local group g=CreateGroup() local real x=GetRectMinX(bj_mapInitialPlayableArea)-30 local real y=GetRectMinY(bj_mapInitialPlayableArea)-30 local integer i=1 local integer u local location L loop exitwhen i>22 set u = CreateUnit(Player(11),udg_Integer[i]x,y,0) call GroupAddUnit(g,u) set i=i+1 endloop set i=1 loop set u=GroupPickRandomUnit(g) exitwhen u==null set L = GetRectCenter(udg_Spots[i]) call SetUnitPositionLoc(u,L) call RemoveLocation(L) call GroupRemoveUnit(g,u) set i=i+1 endloop call DestroyGroup(g) set L=null set g=null endfunction |
| 08-22-2006, 03:49 AM | #6 |
Ooops, I didn't even see yours. I paused when writing my reply, so I thought Guesst was still the last to reply. Argh, I can't believe I made my CreateRandomUnit function so dumb >_>, I'm trying to rush this out before I succomb to my tiredness, so I blame it on that. Thanks for the reply, and I'll see if this works in the morning. |
| 08-22-2006, 03:52 AM | #7 |
Make sure to check my post one more time.. I had a minor typo in the location that I think I edited while you posted. |
| 08-22-2006, 10:31 PM | #9 |
Here's the "right" way to shuffle. I think it can be translated to GUI fairly easy- no nested loops! You can think of it as a selection sort with a random selection. JASS:function AssignUnitTypeToSpot takes integer utype, integer spot returns nothing endfunction function Jumble takes integer n returns nothing local integer array perm local integer array sidedata local integer i = 0 local integer temp local integer s loop exitwhen i>=n set perm[i] = i set sidedata[i] = 0 //Put your unit IDs into side data set i = i + 1 endloop //inplace Fisher-Yates O(N) shuffle set i = 0 loop exitwhen i >= n set s = GetRandomInt(i,n) set temp = perm[i] set perm[i] = perm[s] set perm[s] = temp set i = i + 1 endloop set i = 0 loop exitwhen i >= n call AssignUnitTypeToSpot(sidedata[perm[i]],i) set i = i + 1 endloop endfunction I should mention that the warcraft random generator is almost certainly not good enough for proper shuffles. |
| 08-22-2006, 11:07 PM | #10 |
It still forgets to create five units, and one unit ends up on the same spot as another. (called Jumble() in GUI) JASS:function AssignUnitToSpot takes integer id, integer spot returns nothing local real x=GetRectCenterX(udg_Spots[spot]) local real y=GetRectCenterY(udg_Spots[spot]) set udg_Guys[spot]=CreateUnit(Player(11),id,x,y,270) endfunction function Jumble takes nothing returns nothing local integer array perm local integer array sidedata local integer i = 0 local integer temp local integer s local integer n=22 loop exitwhen i>=n set perm[i] = i set sidedata[i] = udg_UnitId[i] set i = i + 1 endloop //inplace Fisher-Yates O(N) shuffle set i = 0 loop exitwhen i >= n set s = GetRandomInt(i,n) set temp = perm[i] set perm[i] = perm[s] set perm[s] = temp set i = i + 1 endloop set i = 0 loop exitwhen i >= n set temp=sidedata[perm[i]] call AssignUnitToSpot(temp,i) set i = i + 1 endloop endfunction I really want to get out the sledgehammer. |
| 08-22-2006, 11:14 PM | #11 |
sorry about that, I didn't look close enough in my test! Had two off by one errors, one critical. JASS://inplace Fisher-Yates O(N) shuffle set i = 0 loop exitwhen i >= n-1 //we don't need to swap the last with itself. set s = GetRandomInt(i,n-1) //GetRandomInt is inclusive set temp = perm[i] set perm[i] = perm[s] set perm[s] = temp set i = i + 1 endloop |
| 08-22-2006, 11:25 PM | #12 |
Okay, now the problem of an extra unit being created on top of another is fixed, but five spots are left empty still (five units aren't created). |
| 08-22-2006, 11:53 PM | #13 |
Try this function by PitzerMike to print out the IDs and make sure that they match up with those in the unit editor. Also try to ping each of your regions to make sure they're set up correctly. |
