Rules FAQ Members List Search Register Login

 Raised This Month: \$203 Target: \$400 50%

Author Message
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
 08-04-2021 , 04:32   Randomization player #1 Hello everyone, I apologize for the English, please tell me how can I make a random distribution of roles? I need to call the function, implement the issuance of roles for the players. There is a certain but, the role is assigned g_iRole [iClient] = Role_Name There is a counter of how many roles need to be given to players, that is, based on the number of roles, it is necessary to randomly assign them to the players. my counter roles: Code: ```void CalculateRoles() { int iTotalPlayers = 0; // roleOne, roleTwo, roleThree, roleFour // global int for(int i = 1; i <= MaxClients; ++i) { if(IsClientInGame(i) && IsPlayerAlive(i)) { iTotalPlayers++; } } roleOne = iTotalPlayers / 6; roleTwo = iTotalPlayers / 10; roleThree = (iTotalPlayers > 2) ? (iTotalPlayers / 5) : (iTotalPlayers > 1 ? 1 : 0); roleFour = iTotalPlayers - roleOne - roleTwo - roleThree; }``` I have a timer at the end of which I need to assign roles. By calling a function such as InitRoles (), I'm not so much a pro yet, I can't figure out how to better implement it. I ask for help Thank you very much for those who can help Last edited by Hennesy; 08-04-2021 at 04:38.
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
 08-04-2021 , 11:21   Re: Randomization player #2 I tried to do this, but I'm not sure if this is a normal solution. Someone does not give a role at all. Code: ```void InitRoles() { LoopClients(i) g_iRole[i] = Role_None; for (int i = 1; i <= RolesCounter[Role_One]; i++) { if(g_iRole[i] == Role_None) g_iRole[GetRandomClient()] = Role_One; } for (int i = 1; i <= RolesCounter[Role_Two]; i++) { if(g_iRole[i] == Role_None) g_iRole[GetRandomClient()] = Role_Two; } for (int i = 1; i <= RolesCounter[Role_Three]; i++) { if(g_iRole[i] == Role_None) g_iRole[GetRandomClient()] = Role_Three; } for (int i = 1; i <= RolesCounter[Role_Four]; i++) { if(g_iRole[i] == Role_None) g_iRole[GetRandomClient()] = Role_Four; } LoopClients(iClient) { switch(g_iRole[iClient]) { case Role_One: { // } case Role_Two: { // } case Role_Three: { // } case Role_Four: { // } } } } int GetRandomClient() { int[] clients = new int[MaxClients]; int clientCount; LoopClients(i) { if (IsPlayerAlive(i)) { clients[clientCount++] = i; } } return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)]; }```
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
 08-06-2021 , 02:49   Re: Randomization player #3 I wanted to show one "random" way shuffle players, using adt_array with custom sort. But I'm bit lost about "roles", how those need work... I let that part out for now. You see in this Console output how it does. Code: ```map : de_dust2 at: 0 x, 0 y, 0 z tags : bots,compspec,nostats,startmoney players : 0 humans, 11 bots (32 max) edicts : 273 used of 2048 max # userid name uniqueid connected ping loss state adr # 55 "Alfred" BOT active # 56 "Doug" BOT active # 57 "Pat" BOT active # 58 "Jon" BOT active # 59 "Grant" BOT active # 60 "Nick" BOT active # 61 "Martin" BOT active # 62 "Norm" BOT active # 63 "Dustin" BOT active # 64 "Henry" BOT active # 65 "Andy" BOT active sm_test Before Sort 1 (Alfred) Before Sort 2 (Doug) Before Sort 3 (Pat) Before Sort 4 (Jon) Before Sort 5 (Grant) Before Sort 6 (Nick) Before Sort 7 (Martin) Before Sort 8 (Norm) Before Sort 9 (Dustin) Before Sort 10 (Henry) Before Sort 11 (Andy) After Sort 9 (Dustin) After Sort 11 (Andy) After Sort 4 (Jon) After Sort 2 (Doug) After Sort 10 (Henry) After Sort 6 (Nick) After Sort 7 (Martin) After Sort 8 (Norm) After Sort 5 (Grant) After Sort 3 (Pat) After Sort 1 (Alfred)``` Code sample is here. PHP Code: ``` ....          if( !InitRoles() )     {         PrintToServer("InitRoles() failed");     } } // code sample start here enum {     Role_None,     Role_One,     Role_Two,     Role_Three,     Role_Four,     Role_Max }; enum {     Values_Player,     Values_Role,     Values_Max }; bool InitRoles() {     // Create adt_array     ArrayList RandomList = new ArrayList(Values_Max);     // array     int Values[Values_Max];     // collect players from server     for(int i = 1; i <= MaxClients; i++)     {         if(!IsClientInGame(i) || !IsPlayerAlive(i)) continue;                  Values[Values_Player] = i;         Values[Values_Role] = Role_None;         RandomList.PushArray(Values);     }     bool RandomSuccess;     // If array contain even one player, return callback as true     if(RandomList.Length > 0)         RandomSuccess = true;     // Print output of adt_array list before sort     for(int x = 0; x < RandomList.Length; x++)     {         RandomList.GetArray(x, Values, sizeof(Values));         PrintToServer("Before Sort %i (%N)", Values[Values_Player], Values[Values_Player]);     }     PrintToServer("\n");     // Sort adt_array list     RandomList.SortCustom(SortRandomList);     // Print output of adt_array list after sort     for(int x = 0; x < RandomList.Length; x++)     {         RandomList.GetArray(x, Values, sizeof(Values));         PrintToServer("After Sort %i (%N)", Values[Values_Player], Values[Values_Player]);     }     // Remember delete adt_array handle at the end     delete RandomList;     return RandomSuccess; } public int SortRandomList(int index1, int index2, Handle array, Handle hndl) {     return GetRandomInt(-1, 1); }  ``` __________________ Do not Private Message @me Last edited by Bacardi; 08-06-2021 at 02:52.
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
08-06-2021 , 08:05   Re: Randomization player
#4

Quote:
 Originally Posted by Bacardi I wanted to show one "random" way shuffle players, using adt_array with [/PHP]
It is necessary to issue the roles of the player, the roles have restrictions. Let's say role1 - 1 player, role2 - 2 player

and let's say for 30 players you need to distribute 2 roles to 3 players out of 30 players
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
 08-06-2021 , 21:02   Re: Randomization player #5 Check out how it's done in TTT Detective, Traitor, Innoncent https://forums.alliedmods.net/showthread.php?p=2357981 __________________

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans / SourceBans++             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TFDodgeball         TF2Items         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 14:03.

 DMCA - Archive - Top