• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Creating Random Teams

Status
Not open for further replies.
Level 6
Joined
Oct 25, 2010
Messages
203
I have been searching google and these forums for guides on how to create a trigger that would randomize teams. I came across such one here - How do I make random even teams?

But then I realized, if I get this setup, the teams wont be "together" and enemy bases could be directly side by side. Is there anyway to change a players starting position after a map has initialized? Or should I just not bother trying to create a random teams trigger?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Is there anyway to change a players starting position after a map has initialized?
No you can't change their position, but start positions do not really matter (except for AI I think). You can just create the starting units at a different location and move the camera of the player to that point, so it's quite easy to do.
 
Level 6
Joined
Oct 25, 2010
Messages
203
hmmm.... well, if somebody is playing with AI they can pick standard teams and not RT... so I guess this might be possible after all! just have to get those triggers all setup now, its going to be awesome if I can pull this all off haha XD

thanks
 
If you are not afriad from using custom script you could remove the spawing and do it by yourself, with this Functions you can keep it quite orginal:

0 would give the in the Editor preplaced Startloc of Red, 1 blue ...
  • native GetStartLocationLoc takes integer whichStartLocation returns location
Spawn Units for One Player; Beaware that MeleeStartingUnitsForPlayer does not preload nor set camarapostions.
  • function MeleeStartingUnitsForPlayer takes race whichRace, player whichPlayer, location loc, boolean doHeroes returns nothing
Cleans off Preplaced Creeps from the x/y cord, for range:
bj_MELEE_CLEAR_UNITS_RADIUS is recommented.
  • function MeleeClearNearbyUnits real x, real y, real range returns nothing

Edit:

preload codes:
  • call Preloader( "scripts\\OrcMelee.pld" )
  • call Preloader( "scripts\\HumanMelee.pld" )
  • call Preloader( "scripts\\UndeadMelee.pld" )
  • call Preloader( "scripts\\NightElfMelee.pld" )
  • call Preloader( "scripts\\SharedMelee.pld" )
 
Last edited:
Level 6
Joined
Oct 25, 2010
Messages
203
It would be nice, but I dont think I'm ready for that :)

For now, I'm just going to see if I can get it working through the GUI, still learning the WE and trying to figure out how to set things up

But it would be cool if I knew how to use custom scripts better, that stuff would probably be very useful for of the other things I want to do!
 
Level 6
Joined
Oct 25, 2010
Messages
203
well I got my team randomizer triggers setup, and it sort of works... but something really funny happens!! everytime, no matter how the teams come out, the allies are always on opposite sides... it makes no sense!! if p1red and p2blue are normally side by side, but if I press random team it will put blue on the opposite side (when we are allies) but if it teams me with p3teal or p4purp then they two are on opposite sides, no matter whos team I get we are cross spawns

lol like how the hell?? how is it possible for blue to be far away from red when by default red and blue should be together?? I did not make any triggers to move players :confused:
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
If anyone is interested in an efficient algorithm to assign a team for each player, here is one option:
It takes the player amount and splits them into a certain number of random teams.
It also works for numbers like 8 players into 5 teams (1,1,2,2,2). The first teams will have less players, but since it's random in which team you will be, every player has the same chance to get into a smaller team.

JASS:
function CreateTeams takes integer playerCount, integer teamCount returns nothing
    local integer i //for loop
    local integer currentValue //algorithm variable
    local integer k //temporary result
    local integer array teamMaxPlayers //maximum players in the team
    local integer array teamPlayerCount //current players in the team
    local integer array teamId //maps random integer to team index
    local integer index
    //force setup
    set i = 0
    set currentValue = playerCount
    loop
        exitwhen i>=teamCount
        set k = R2I(((currentValue*1.00)/(1.00*teamCount-i)))
        set teamMaxPlayers[i]=k
        set currentValue=currentValue - k
        set teamPlayerCount[i] = 0
        set teamId[i]=i
        set i = i + 1
    endloop
    //team creation
    set i = 0
    set currentValue = teamCount
    loop
        exitwhen i>=playerCount
        set k = GetRandomInt(0, currentValue-1)
        set index = teamId[k]
        set teamPlayerCount[index] = teamPlayerCount[index] + 1
        if(teamPlayerCount[index]>=teamMaxPlayers[index]) then
            set currentValue = currentValue - 1
            set teamId[k] = teamId[currentValue]
        endif
       //place your code here
       // i = player index
       // index = team index
      
        call BJDebugMsg(GetPlayerName(Player(i))+" in team: "+I2S(index))
      
       //end of your code
        set i = i + 1
    endloop
endfunction
This is only an algorithm to give every players a team index. No actual teams will be created, so you will have to create your teams afterwards depending on the results of the algorithm.

========================================================

Start positions are usually random (unless you tick fixed start posititions)
Also if you use a trigger to refer to a player's start position, you will get the start position, that was randomly assigned to that player. If you want to get the start position you see in the world editor, you either have to check fixed start position, so they don't change or use regions to get the exact points.
 
With this native you are able to change Starting Locations by simply using it before the Default Melee Trigger Runs.

  • SetPlayerStartLocation player whichPlayer, integer startLocIndex
This one allows to get the in world editor defined StartingLocations, without beeing randomed.
  • GetStartLocationLoc integer whichStartLocation returns location
    • the provieded Function in GUI returns the one which was picked, not the one beeing placed in editor.
    • What makes sense in most cases except this one :).
Index in both is the Jass Index for Players: 0=red, 1 = blue...
 
Level 6
Joined
Oct 25, 2010
Messages
203
I'm a pretty big newb, still learning most of the basic stuff. Is there a good tutorial for custom scripts??

Jampion seems pretty good at this stuff, so I sent him a copy of my map and hopefully he can fix the issue I'm having :)

Like I said, I created triggers for creating random teams, and it works (yay!!) but it always seems to set allies on opposite/far sides of the map no matter who the ally is, its really messed up because its moving player 2 who should be next to player 1 so I dont get it at all

But for the most part, my dialogue voting system is almost complete so I can start moving on to the juicier parts of my map!
 
Status
Not open for further replies.
Top