[Tutorial] [BASIC]How to make a command not work without enough players.
#1

The Purpose of the Tutorial:
To make a command not work without enough players in the server.

What will this code do?
This code will SendClientMessage back to the player that there is not enough players in the server for the command to go further and take action.

Were can you use this?
Well you can use this in vote systems (Like I did) You could also use this in race systems and other places you think are suitable...

This is the code

pawn Код:
VPlayers = GetPlayersOnServer()/2+1;
    if(GetPlayersOnServer() <= 2)
        return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
pawn Код:
VPlayers = GetPlayersOnServer()/2+1;
This code means that like 3 players are minimum needed for the command to work...

pawn Код:
if(GetPlayersOnServer() <=2)
This is the code that tells the server to check if there are enough players for the command to work if not...

pawn Код:
return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
The player gets sent a message that there are not enough players for the command to go further...

pawn Код:
GetPlayersOnServer()
{
    new count;
    for(new x=0; x< MAX_PLAYERS; x++)
    {
        if(IsPlayerConnected(x))
        {
            count++;
        }
    }
    return count;
}
This bit you add to the bottom of your script ^^.

So this is how you would place it a extract out of my script...

pawn Код:
dcmd_votecash(playerid,params[])
{
    new id,n[24],on[24],str2[128],string[3];
    new tmp[256], tmp2[256], Index,str[128];
    VPlayers = GetPlayersOnServer()/2+1;
    if(GetPlayersOnServer() <= 2)
        return SendClientMessage(playerid,GREY,"The minimum players required for this command to work are 3.");
    tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp);
    if(IsPlayerAdmin(id)) return SendClientMessage(playerid,0xFF0000FF,"You cannot try to Votecash an admin! -_-");
    if(VoteActive == 1) return SendClientMessage(playerid,0xFF0000FF,"There is already a Vote for something in proccess, please wait until it has finished.");
    GetPlayerName(playerid,n,24),GetPlayerName(id,on,24);
    Voted[playerid] = 1;
    SlapName = on;
    PlayerName = n;
    if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /Votecash [ID] [Reason]");
    if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID.");
    Votes = 1;
    VoteActive = 1;
    format(str2,sizeof(str2),"~r~Votecash on ~w~%s. ~r~%d/%d",PlayerName,Votes,VPlayers);
    Votecash = TextDrawCreate(50.0,300.0,str2);
    TextDrawLetterSize(Votecash,0.5,2.5);
    TextDrawShowForAll(Votecash);
    thingy = SetTimer("VoteFail",21000,false);
    Timer = SetTimerEx("CountDownTimer",1000,true,"i",playerid);
    format(str,sizeof(str),"%s has started a Votecash on %s. Reason: %s. To vote - /votec",n,on,params[2]);
    SendClientMessageToAll(0xFF0000FF,str);
    format(string,sizeof(string),"%d",Count);
    TCountDown = TextDrawCreate(300.0,300.0,string);
    Count = 21;
    return 1;
It is a really simple feature but very useful.
If I have made any mistake I'm sorry, you are aloud to correct me
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)