Randomize a few players [+REP] -
Lirbo - 23.07.2016
Hello everyone!
I made a zombie arena and I would like to randomize zombies.
The zombies count should fit the total amount of the players in the arena
I don't care if it would work on precents or defined manually I just want it to work :P
for example randomizing 33% of the players in the arena to become zombies.
OR
if TotalCount == 2 then randomize 1 zombie
if TotalCount == 3 then randomize 1 zombie
if TotalCount == 4 then randomize 2 zombies
if TotalCount == 5 then randomize 2 zombies
if TotalCount == 6 then randomize 3 zombies
if TotalCount == 7 then randomize 3 zombies
if TotalCount == 8 then randomize 4 zombies
etc...
IMPORTANT NOTE: If you would randomize 4 times 1 player it might randomize the same player a few times which I don't want to happen so pls dont show me a way to randomize 1 player each time XD
Re: Randomize a few players [+REP] -
Threshold - 24.07.2016
Okay, so what do you want from us?
https://sampwiki.blast.hk/wiki/Random
There's the function for randomising... now what? I don't really see how it's 'random' either if you want to make 1/3 of players into zombies.
Re: Randomize a few players [+REP] - WhiteGhost - 24.07.2016
U doing it by setting skins?
PHP код:
switch(random(2))/*Increase the "2" for each skin u add*/
{
case 1: SetPlayerSkin(playerid,Zombie1);
case 2: SetPlayerSkin(playerid,Zombie2);
}
}
}
Just do something like this when they enter the arena
Re: Randomize a few players [+REP] -
Crayder - 24.07.2016
Well, definitely not what WhiteGhost said...
You're going to need to keep track of the zombie and human counts, and adjust as players are added.
pawn Код:
#define A_TYPE_HUMAN 0
#define A_TYPE_ZOMBIE 1
enum E_ARENA_PLAYER_STUFF {
bool:isInArena,
arenaType
}
new arenaHumans,
arenaZombies,
arenaPlayers[MAX_PLAYERS][E_ARENA_PLAYER_STUFF];
Now with that we can keep track of how many players are in which group and which players are in at all.
Say for example you have "arenajoin" and "arenaleave" commands...
pawn Код:
CMD:arenajoin(playerid, params[]) {
if(arenaPlayers[playerid][isInArena])
return SendClientMessage(playerid, -1, "You are already in the arena");
arenaPlayers[playerid][isInArena] = true;
if((float(arenaHumans) / float(arenaZombies)) < (2.0 / 1.0)) // 2:1 ratio is 33% zombies
{ // Too many zombies, add human
arenaPlayers[playerid][arenaType] = A_TYPE_HUMAN;
arenaHumans++;
}
else
{ // Too many humans, add zombie
arenaPlayers[playerid][arenaType] = A_TYPE_ZOMBIE;
arenaZombies++;
}
// Now spawn player into arena...
}
CMD:arenaleave(playerid, params[]) {
if(!arenaPlayers[playerid][isInArena])
return SendClientMessage(playerid, -1, "You aren't in the arena");
arenaPlayers[playerid][isInArena] = false;
if(arenaPlayers[playerid][arenaType] == A_TYPE_HUMAN)
arenaHumans--;
else
arenaZombies--;
// Now spawn player into real world...
}
Now we need to spawn player responsibly in OnPlayerSpawn:
pawn Код:
public OnPlayerSpawn(playerid)
{
if(arenaPlayers[playerid][isInArena]) {
// Spawn player in arena...
}
else {
// Spawn player normally...
}
}
And don't forget to do this when forcing players to leave the arena, like in OnPlayerDisconnect:
pawn Код:
if(arenaPlayers[playerid][isInArena]) {
arenaPlayers[playerid][isInArena] = false;
if(arenaPlayers[playerid][arenaType] == A_TYPE_HUMAN)
arenaHumans--;
else
arenaZombies--;
}
Re: Randomize a few players [+REP] -
Threshold - 24.07.2016
Aaaand on that note... please use this in the future:
https://sampforum.blast.hk/showthread.php?tid=447813
Re: Randomize a few players [+REP] -
SickAttack - 24.07.2016
This will help you out:
pawn Код:
// ** INCLUDES
#include <a_samp>
// ** DEFINES
// *** TEAMS
#define TEAM_HUMAN 0
#define TEAM_ZOMBIE 1
// ** VARIABLES
// *** GLOBAL VARIABLES
// **** GENERAL
new gPlayerCount,
gPlayerIDs[MAX_PLAYERS];
// *** PER-PLAYER VARIABLES
// **** GENERAL
new pTeam[MAX_PLAYERS];
// ** MAIN
main()
{
print("Loaded \"make_players_humans_and_zombies.amx\".");
gPlayerCount = 8;
new human_count, zombie_count, count, selected;
GetHumanAndZombieCount(human_count, zombie_count);
printf("%d human(s), %d zombie(s)", human_count, zombie_count);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
{
if(!IsPlayerConnected(i))
{
continue;
}
gPlayerIDs[count ++] = i;
pTeam[playerid] = TEAM_HUMAN;
}
for(new i = 0; i < zombie_count; i ++)
{
selected = random(count);
pTeam[gPlayerIDs[selected]] = TEAM_ZOMBIE;
gPlayerIDs[selected] = gPlayerIDs[count - 1];
count --;
}
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock GetHumanAndZombieCount(&human_count, &zombie_count)
{
zombie_count = floatround((gPlayerCount / 2), floatround_floor);
human_count = (gPlayerCount - zombie_count);
return 1;
}
Don't just copy/paste.
Re: Randomize a few players [+REP] -
Crayder - 24.07.2016
SickAttack, perhaps you didn't read his request entirely...
Re: Randomize a few players [+REP] -
SickAttack - 24.07.2016
Quote:
Originally Posted by Crayder
SickAttack, perhaps you didn't read his request entirely...
|
It says:
Quote:
OR
if TotalCount == 2 then randomize 1 zombie
if TotalCount == 3 then randomize 1 zombie
if TotalCount == 4 then randomize 2 zombies
if TotalCount == 5 then randomize 2 zombies
if TotalCount == 6 then randomize 3 zombies
if TotalCount == 7 then randomize 3 zombies
if TotalCount == 8 then randomize 4 zombies
etc...
|
OR
Re: Randomize a few players [+REP] -
Crayder - 24.07.2016
Quote:
Originally Posted by SickAttack
It says:
OR
|
Quote:
IMPORTANT NOTE: If you would randomize 4 times 1 player it might randomize the same player a few times which I don't want to happen so pls dont show me a way to randomize 1 player each time XD
|
I know his English isn't that easy to understand, but when your native language is English and you've been on this forum for years you start to understand this nonsense.
He doesn't want the balancing to random. He says "random" a lot, but that's not what he means. He also doesn't want to repeat the team ordering process over and over.
Re: Randomize a few players [+REP] -
SickAttack - 24.07.2016
Quote:
Originally Posted by Crayder
I know his English isn't that easy to understand, but when your native language is English and you've been on this forum for years you start to understand this nonsense.
He doesn't want the balancing to random. He says "random" a lot, but that's not what he means. He also doesn't want to repeat the team ordering process over and over.
|
What you posted isn't a good alternative, as the order of joining isn't random but always the same. As it is an arena and assuming the players already know how it works, they would wait for players to join and become a zombie (with the balancing system on join), then they'll join so they can become a human. Because nobody wants to be a zombie with a chainsaw (implying it's like that, it commonly is).
What I posted should select random humans and random zombies, following:
if TotalCount == 2 then randomize 1 zombie
if TotalCount == 3 then randomize 1 zombie
if TotalCount == 4 then randomize 2 zombies
if TotalCount == 5 then randomize 2 zombies
if TotalCount == 6 then randomize 3 zombies
if TotalCount == 7 then randomize 3 zombies
if TotalCount == 8 then randomize 4 zombies
Without the possibility of selecting the same player again:
pawn Код:
selected = random(count);
pTeam[gPlayerIDs[selected]] = TEAM_ZOMBIE;
gPlayerIDs[selected] = gPlayerIDs[count - 1];
count --;
This part "gPlayerIDs[selected] = gPlayerIDs[count - 1];" also gives an extra random bonus to it and it's where the magic happens.
-------------------------------------------------------------------------------------
Regardless of what he actually wants, that is my interpretation of what I understood and the best way I saw fit. The code should only be ran once, and to an extent, he should use what you posted if any new players join after the teams have been sorted out.