SA-MP Forums Archive
Command help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Command help (/showthread.php?tid=398374)



Command help - Lz - 09.12.2012

Here is my command so far:
pawn Код:
COMMAND:finvite(playerid, params[])
{
    if (sLeader(playerid))
    {
        new
          toplayerid, // the player we want to make SA-PD
          rank; // extracting player's ID and rank from params
        if (!sscanf(params, "ii", toplayerid, rank))
        {
          if (toplayerid != INVALID_PLAYER_ID)
          {
            new
            message[40];
            format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
            SendClientMessage(toplayerid, 0x00FF00FF, message);
          }
          else SendClientMessage(playerid, 0xFF0000FF, "That player is not connected");
        }
        else SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /finvite <playerid> <rank>");
    }
    else SendClientMessage(playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!");
    return 1;
}
What im trying to do here is if the (sLeader) executes the command /finvite, it will set the (toplayerid) the rank of 1-4 whichever he entered..

My variables from the faction are

pawn Код:
// SA-PD
new sRank0,
    sRank1,
    sRank2,
    sRank3,
    sLeader;
// SA-PD
Only thing is how do i set so the rank parameters can only be used as 0-4 or would i just need to make 5 different commands?


Re: Command help - Konstantinos - 09.12.2012

By the way, set only a variable of rank and set it from 1 to 4. It is not needed to create 4 different variables for that.
pawn Код:
COMMAND:finvite( playerid, params[ ] )
{
    if( !sLeader( playerid ) ) return SendClientMessage( playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!" );
    new
        toplayerid, // the player we want to make SA-PD
        rank
    ; // extracting player's ID and rank from params
    if( sscanf( params, "ri", toplayerid, rank ) ) return SendClientMessage( playerid, 0xFFFFFFFF, "Usage: /finvite <playerid> <rank>" );
    if( toplayerid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, 0xFF0000FF, "That player is not connected" );
    if( rank < 1 || rank > 4 ) return SendClientMessage( playerid, 0xFF0000FF, "The rank value must be between 1 and 4." );
    new
        message[ 40 ]
    ;
    format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
    SendClientMessage(toplayerid, 0x00FF00FF, message);
    // Set your rank here!
    return 1;
}



Re: Command help - Lordzy - 09.12.2012

Just one single variable is enough and makes easier. Also the variable must be global variable inorder to apply it for players. Here's a small example:
pawn Код:
new pRank[MAX_PLAYERS]; //Create a global variable to apply the ranks for players.

CMD:setrank(playerid, params[])
{
 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You must login as RCON to use this command.");
 new p2;
 new rank;
 if(sscanf(params, "ui", p2, rank)) return SendClientMessage(playerid, 0xFF0000, "Usage: /setrank [playerid] [rank]");
 if(p2 == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000FF, "This player ID is invalid.");
 if(rank > 1 || rank > 4) return SendClientMessage(playerid, 0xFF0000FF, "Invalid rank. Avalaible 0-4.");
 pRank[p2] = rank; //Sets the rank!
 return 1;
}

CMD:examplecmd(playerid, params[])
{
 if(pRank[playerid] == 1) //If player is rank 1.
 {
   //
 }
 return 1;
}
Edit:late.


Re: Command help - Lz - 09.12.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
By the way, set only a variable of rank and set it from 1 to 4. It is not needed to create 4 different variables for that.
pawn Код:
COMMAND:finvite( playerid, params[ ] )
{
    if( !sLeader( playerid ) ) return SendClientMessage( playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!" );
    new
        toplayerid, // the player we want to make SA-PD
        rank
    ; // extracting player's ID and rank from params
    if( sscanf( params, "ri", toplayerid, rank ) ) return SendClientMessage( playerid, 0xFFFFFFFF, "Usage: /finvite <playerid> <rank>" );
    if( toplayerid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, 0xFF0000FF, "That player is not connected" );
    if( rank < 1 || rank > 4 ) return SendClientMessage( playerid, 0xFF0000FF, "The rank value must be between 1 and 4." );
    new
        message[ 40 ]
    ;
    format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
    SendClientMessage(toplayerid, 0x00FF00FF, message);
    // Set your rank here!
    return 1;
}
Thanks, How do i set the variable to only 1-4? new SA-PD[4];?


Re: Command help - Konstantinos - 09.12.2012

pawn Код:
// SA-PD
new sRank[ MAX_PLAYERS ],
    sLeader;
// SA-PD

// OnPlayerConnect
sRank[ playerid ] = 0;


COMMAND:finvite( playerid, params[ ] )
{
    if( !sLeader( playerid ) ) return SendClientMessage( playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!" );
    new
        toplayerid, // the player we want to make SA-PD
        rank
    ; // extracting player's ID and rank from params
    if( sscanf( params, "ri", toplayerid, rank ) ) return SendClientMessage( playerid, 0xFFFFFFFF, "Usage: /finvite <playerid> <rank>" );
    if( toplayerid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, 0xFF0000FF, "That player is not connected" );
    if( rank < 1 || rank > 4 ) return SendClientMessage( playerid, 0xFF0000FF, "The rank value must be between 1 and 4." );
    new
        message[ 40 ]
    ;
    format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
    SendClientMessage(toplayerid, 0x00FF00FF, message);
    sRank[ toplayerid ] = rank;
    return 1;
}



Re: Command help - Lz - 09.12.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
pawn Код:
// SA-PD
new sRank[ MAX_PLAYERS ],
    sLeader;
// SA-PD

// OnPlayerConnect
sRank[ playerid ] = 0;


COMMAND:finvite( playerid, params[ ] )
{
    if( !sLeader( playerid ) ) return SendClientMessage( playerid, 0xFF0000FF, "Only the SA-PD Leader can use this command!" );
    new
        toplayerid, // the player we want to make SA-PD
        rank
    ; // extracting player's ID and rank from params
    if( sscanf( params, "ri", toplayerid, rank ) ) return SendClientMessage( playerid, 0xFFFFFFFF, "Usage: /finvite <playerid> <rank>" );
    if( toplayerid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, 0xFF0000FF, "That player is not connected" );
    if( rank < 1 || rank > 4 ) return SendClientMessage( playerid, 0xFF0000FF, "The rank value must be between 1 and 4." );
    new
        message[ 40 ]
    ;
    format(message, sizeof(message), "You were set rank %i By the SA-PD Leader.!", rank);
    SendClientMessage(toplayerid, 0x00FF00FF, message);
    sRank[ toplayerid ] = rank;
    return 1;
}
Thank you man, Ill make sure to rep in a sec, Im kinda confused with the saving process though, Im using y_ini so im not sure how i would identify which faction the player is in? Should i just use variable values, 1-4 being SA-PD, 5-9 being another faction etc?


Re: Command help - Konstantinos - 09.12.2012

Well, I'd recomment you not to use only one variable, because you will be confused as everyone would be.
I am not sure what are you using for, but I'd do it with that way.
pawn Код:
// TEAM1
team1_rank[ MAX_PLAYERS ]; // 1-4

// TEAM2
team2_rank[ MAX_PLAYERS ]; // 1-4

// TEAM3
team3_rank[ MAX_PLAYERS ]; // 1-4

// TEAM4
team4_rank[ MAX_PLAYERS ]; // 1-4
Send me if you want the part of the register/login/logout via PM and I'll help you on the saving.