RANDOM PICK UNITS (without doubles)

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Guest
here is my dilemma:
I am making a game called Survivor, just like the television show. I have come a long way and will be complete soon, however I cannot figure out how to randomly assign the heroes to the players (without them doing anything) so that they all get a DIFFERENT hero.
there is one hero for each outcast in the Borneo series. that is 8 heroes for each team, but only 5 need to be picked for each side since it is a 5v5 map. so i need it to randomly give out kelly to one player, richard to another, etc. etc. I did this myself with (randomly select a number between 1 and 8) and (if number is 1 then give kelly, if numbver is 2 give....etc) but then there is a high probability of having two or three kelly's, for example. SO if somebody could help me figure this short little mess up, then Survivor Island by Dan will be out there in no time at all, if not, then there will be a fixed hero for each slot, dont make me let that happen!

please e mail me if you have an apifany on this situation
[email protected]
THanks!

-Dan
 
Create the units at the beginning of the game. Then, instead of randomly creating a hero, put all of the heroes in a region, select a random hero from that region, and change the ownership to a player. I hope this is clear enough. :)
 
i am kinda on that track

That is what i started to think about doing but then again,
how would you go about doing that? how do i randomly pick a hero in regen? im really tired, this should be easy right?

-Dan
 
hmm

Ok i feel like a complete idiot right now, maybe i have been working on this too long, but what would that be under?
unit group?
selection?
 
First, when the trigger editor asks you to select a unit, pick "Random unit from <unit group>". Then, for unit group, select "Units in Region". Finally, for the region, select your region.
 
Thanks

Thank you Silver Hawk, you have ended a problem of mine! I have been wondering on this all day on and off, and I had to stop and listen to loud music to drown my thoughts several times. I was just making separate regens and placing the units when you posted help and I finally got this down, thanks a lot!

-Dan
[email protected]
 
No problem. Glad to help. :D

By the way, you should consider registering. You would be a welcome addition to the community. :)
 
Thanks

now that I found this site, sure thing, just give me some papers to fill out and show me the places to initial and sign! This is the very first time i tried for outside help on issues of mine. I have tons of crappy maps and games that I have made without any help whatsoever... So i know my way around the editor pretty well... Thanks for the invite, Ill register right now!
 
This is more advanced, but using a 'loop' and 'exitwhen' statement is how you pick a random, non-repeating integer.

Although you might not know all the JASS code powering it, you may learn a little looking at it.

Code:
All Random
    Events
    Conditions
    Actions
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Picked player) slot status) Equal to Is playing
                        ((Picked player) controller) Equal to User
                    Then - Actions
                        Custom script:   loop
                        Set Random = (Random integer number between 1 and 8)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Hero_Taken[Random] Equal to False
                            Then - Actions
                                Set Hero_Taken[Random] = True
                                Unit - Create 1 Hero_Array[Random] for (Picked player) at ((Picked player) start location) facing Default building facing degrees
                            Else - Actions
                                Do nothing
                        Custom script:   exitwhen (GetPlayerState(GetEnumPlayer(),PLAYER_STATE_RESOURCE_FOOD_USED)>=5)
                        Custom script:   endloop
                    Else - Actions
                        Do nothing
Note

For this to truly work, you need to JASS it, and make 'Random' a local variable.
 
:) You have put me in my place... I don't know any Jass code, I am limited to world edit trigger commands as of now. That is way more advanced then I am right now, but thanks for the reference! I need to take some classes... im in eleventh grade next school year... :) ...
 
Actually I get it, Its just i don't know the codes that you use and wouldn't know when to use them.
I have never seen:
Custom script: exitwhen (GetPlayerState(GetEnumPlayer(),PLAYER_STATE_RESOURCE_FOOD_USED)>=5)
Custom script: endloop

I don't know custom script and don't know how to use it in the editor... Like i said, i think i need some classes...
 
Well, there's also the Non-JASS way of generating a random non-repeating sequence.

Code:
RandomSequenceInit
    Events
        Map initialization
    Conditions
    Actions
        For each (Integer A) from 1 to 8, do (Actions)
            Loop - Actions
                Set Sequence[(Integer A)] = (Integer A)
        Set SequenceCount = 8

Sequence is an integer array of size 8.
SequenceCount is an integer set to the size of the array (8 in this example).


Then, when you need it:

Code:
Actions
    Set tmpInteger = (Random integer number between 1 and SequenceCount)

    --- Do something with "Sequence[tmpInteger]" ---
    Game - Display to (All players) the text: (String(Sequence[tmpInteger]))

    --- Once done, prepare for the next run ---
    Set Sequence[tmpInteger] = Sequence[SequenceCount]
    Set SequenceCount = (SequenceCount - 1)

tmpInteger is a simple integer variable.

This will generate a non-repeating random sequence of all the numbers from 1 to 8.

And it doesn't use a loop!
In theory, it might happen that you loop for some half hour before finding an empty spot... ;)
(Yes, of course, this "can't possibly happen")


Happy mapping.


Yours,
AceHart
 
Wow, pretty impressive. Usefull I might add too. Where'd you pick up that bit-o-code?

// Maybe your code deserves a spot in the 'Free Trigger Code' thread? Or in the FAQ? Hmm.

AceHart said:
And it doesn't use a loop!
In theory, it might happen that you loop for some half hour before finding an empty spot... ;)
(Yes, of course, this "can't possibly happen")

Heh. Welllll, Ryoko TD does it for picking the mini games, and it does it about 100 times in 'Platform Peril'.

So have no fear.

It would be an awesomer revamp to the minigame engine tho.

However, platform perill works differently.

It has to random until it finds a platform thats not DOWN. Knowing that, the platform can come up, its okay to reuse a 'sequence' number, but just has to check boolean for it.
 
I just thought of something.

Note:

Because 'Pick all Players' does the actions simultaneously, you cant combine the sequence with pick all players.

(I know because, Ryoko TD spawns all units this method, and they come out simultaniously, instead of player1, player2.....etc)

Therefore, with the squence system, use a for loop, for all players, with conditions.
Code:
For Integer A in 1 through (max number of players)
     If - Conditions
        Player slot status = is playing
        Player controler = user
     If - Then
        (create hero using the sequence)
     Else
        Do nothing

(Acehart)
AceHart said:
Thinking, my friend, thinking... :cool:
Jeez. And to think I didn't get it when I read it. I created 1-8 on paper, and picked a couple randoms, and tracked the numbers to see just how it worked. I get it now....the hard way.

Got a method for alphabetizing an array thats simple too? :)
 
:D


> Got a method for alphabetizing an array thats simple too?

An array of strings in alphabetical order?
Simple is different.

Order is much more "difficult" to achieve than making a mess.
A simple fact of life we all came across already in our earliest childhoods.
"Your room's a mess", anyone? ;)

And, well, strings can only be compared as being "equal" or "not equal".
Unfortunately, "not equal" doesn't say anything about their order... :(

So, right now, hm, no... sorry, don't have one.
 
Code:
for a = 1 to end - 1
    for b = a + 1 to end
        if value[a] > value [b] then swap value[a],value[b]

That's "Bubble sort" and terribly off topic.
Simple? Oh, yes. It doesn't get any simpler.
And for less then, around, 200 values, it might just be the fastest.
If you need it for a couple thousand values... find something else.

More as PM.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Real users can't really disable Javascript anymore these days.
  • Ghan Ghan:
    The internet is broken without it.
  • Ghan Ghan:
    Bot readable, not human usable.
  • The Helper The Helper:
    got it
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    Check out the new Featured Content feature we apparently got with the forum software upgrade! https://www.thehelper.net/featured/
  • The Helper The Helper:
    Also on the bottom right side bar we now have a Trending Content Box!
    +1
  • The Helper The Helper:
    Not on the Headline News page just on the Forums page can we get that Featured and Trending on the home page?
  • Ghan Ghan:
    Since the home page is technically a forum, it now shows on all forum views. Still in the sidebar.
    +1
  • The Helper The Helper:
    Happy Friday! Hope everyone has a fantastic day and an even better weekend!
  • The Helper The Helper:
    Happy Sunday!
  • The Helper The Helper:
    I lovc that I can post webp and X links now! :)
  • The Helper The Helper:
    Happy Thursday!
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    we were down for a minute - think a log file or something got too big
    +1
  • Ghan Ghan:
    The alerts say it was down for a while unfortunately.
  • Ghan Ghan:
    Didn't know what was going on while I was at work.
  • Ghan Ghan:
    Disk filled up with logs. Fixed now.
    +1
  • The Helper The Helper:
    not a problem at all thanks for getting us back up
  • The Helper The Helper:
    I think the bots are finding a way to get through the anubis
  • The Helper The Helper:
    Happy Wednesday Everyone! Hope everyone has a Fantastic Day!
    +1
  • The Helper The Helper:
    Yeah, stats are showing big bot influx like 12k page views.
  • Wizard Wizard:
    :wave:
    +1
  • Ghan Ghan:
    TH changed his avatar again. 6 more weeks of summer.
    +3
  • Wizard Wizard:
    lol
    +1

The Helper Discord

Members online

No members online now.

Affiliates

Hive Workshop NUON Dome World Editor Tutorials
Back
Top