● Información Adicional:
Ideal para servidores desatendidos, el código de este fs hace que los jugadores puedan votar para expulsar a un jugador mediante la funcion "/votekick [ID][Razon]". Al llegar a X cantidad de votos, el jugador es expulsado. Se podria utilizar para vote Ban y otras caracteristicas, solo es adaptarlo para ello.
● Código:
#include <a_samp>
//*COLOURS*//
#define GREEN 0x21DD00FF
#define RED 0xE60000FF
#define ADMIN_RED 0xFB0000FF
#define YELLOW 0xFFFF00FF
#define ORANGE 0xF97804FF
#define LIGHTRED 0xFF8080FF
#define LIGHTBLUE 0x00C2ECFF
#define PURPLE 0xB360FDFF
#define PLAYER_COLOR 0xFFFFFFFF
#define BLUE 0x1229FAFF
#define LIGHTGREEN 0x38FF06FF
#define DARKPINK 0xE100E1FF
#define DARKGREEN 0x008040FF
#define ANNOUNCEMENT 0x00CACAFB
#define COLOR_SYSTEM 0xEFEFF7AA
#define NICESKY 0x99FFFFAA
#define GRAY 0xCECECEFF
#define WHITE 0xFFFFFFAA
#define CYAN 0x00FFFFAA
//*OTHER DEFINES*//
#define VOTETIME 30000 // change the time to change the amount of time left.
#define STRING 255
//#define ADMINSONLINE 1 // Uncomment this if you don't want people to vote while admins are online.
//*VARIBALES*//
new VoteKick;
new Votes;
new Voted[MAX_PLAYERS];
new PlayerCount;
//*FORWARDS*//
forward VoteTimer(giveplayerid);
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Simple Vote Kick system - By Giacomand");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
Voted[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Voted[playerid] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[128];
new tmp[128];
new idx;
new giveplayerid;
new giveplayer[MAX_PLAYER_NAME];
new sendername[MAX_PLAYER_NAME];
new string[STRING];
cmd = strtok(cmdtext,idx);
if(strcmp(cmd, "/votekick", true) == 0)
{
for (new i = 0; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
#if defined ADMINSONLNE
if(IsPlayerAdmin(i))
{
format(string, sizeof(string), "ERROR: There is an admin online. (%s (%d)) PM Them for help.", Name(i), i);
SendClientMessage(playerid, RED, string);
return 1;
}
#endif
PlayerCount++;
}
}
if(PlayerCount <= 3)
{
SendClientMessage(playerid, RED, "ERROR: Must have more than 3 Players online to start a vote-kick");
return 1;
}
new reason[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, ORANGE, "USAGE: /votekick [ID/PartOfName] [reason]");
SendClientMessage(playerid, ORANGE, "FUNCTION: Will start a timer, which anyone can vote to kick the player. (30 Seconds)");
return 1;
}
if(VoteKick == 1)
{
SendClientMessage(playerid, RED, "ERROR: There is a voting in progress, please wait");
return 1;
}
if(IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, RED, "ERROR: You can't kick an admin!");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
{
reason[idx - offset] = cmdtext[idx];
idx++;
}
reason[idx - offset] = EOS;
if(!strlen(reason))
{
SendClientMessage(playerid, ORANGE, "USAGE: /votekick [ID/PartOfName] [reason]");
return 1;
}
else
{
format(string, sizeof(string), "[NEWS]: Player %s started a votekick on %s. [Reason: %s] - %d seconds Remaining.", Name(playerid), Name(giveplayerid), reason, VOTETIME / 1000);
print(string);
SendClientMessageToAll(YELLOW, string);
SendClientMessageToAll(YELLOW, "If you want this player kicked. Use /vote");
Votes = 1;
SetTimerEx("VoteTimer", VOTETIME, 0, "i", giveplayerid);
VoteKick = 1;
Voted[playerid] = 1;
}
}
else if(giveplayerid == INVALID_PLAYER_ID)
{
format(string, sizeof(string), "%d is not an active player.", giveplayerid);
SendClientMessage(playerid, RED, string);
}
return 1;
}
if(strcmp(cmd, "/vote", true) == 0)
{
if(Voted[playerid] == 1)
{
SendClientMessage(playerid, RED, "You have already voted!");
}
else
{
Voted[playerid] = 1;
Votes++;
format(string, sizeof(string), "%s has voted (%d/%d)", Name(playerid), Votes, (PlayerCount /= 2)+1);
SendClientMessageToAll(YELLOW, string);
}
return 1;
}
return 0;
}
public VoteTimer(giveplayerid)
{
new string[STRING];
new TempPlayerCount = PlayerCount;
TempPlayerCount /= 2;
if(Votes > TempPlayerCount)
{
format(string, sizeof(string), "%s has been kicked for being voted out", Name(giveplayerid));
SendClientMessageToAll(YELLOW, string);
Kick(giveplayerid);
}
else
{
format(string, sizeof(string), "%s was not kicked, because there were not enough votes", Name(giveplayerid));
SendClientMessageToAll(YELLOW, string);
}
for(new i = 0; i < GetMaxPlayers(); i++)
{
Voted[i] = 0;
}
Votes = 0;
VoteKick = 0;
return 1;
}
stock Name(playerid) //By Alex "Y_Less" Cole
{
new plname[24];
GetPlayerName(playerid, plname, sizeof(plname));
return plname;
}
stock strtok(const string[], &index,seperator=' ')
{
new length = strlen(string);
new offset = index;
new result[128];
while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
if ((index < length) && (string[index] == seperator))
{
index++;
}
return result;
}
stock IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
if (string[i] > '9' || string[i] < '0')
return 0;
return 1;
}
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21)
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos]))
{
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
userid = INVALID_PLAYER_ID;
else return userid;
}
}
new len = strlen(text[pos]);
new count = 0;
new pname[MAX_PLAYER_NAME];
for (new i = 0; i < GetMaxPlayers(); i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, pname, sizeof (pname));
if (strcmp(pname, text[pos], true, len) == 0)
{
if (len == strlen(pname)) return i;
else
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count) SendClientMessage(playerid, COLOR_SYSTEM, "ERROR: There are multiple users, enter full playername.");
else SendClientMessage(playerid, COLOR_SYSTEM, "ERROR: Playername not found.");
}
userid = INVALID_PLAYER_ID;
}
return userid;
}